vxge-main.c 128 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867
  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-main.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. * The module loadable parameters that are supported by the driver and a brief
  15. * explanation of all the variables:
  16. * vlan_tag_strip:
  17. * Strip VLAN Tag enable/disable. Instructs the device to remove
  18. * the VLAN tag from all received tagged frames that are not
  19. * replicated at the internal L2 switch.
  20. * 0 - Do not strip the VLAN tag.
  21. * 1 - Strip the VLAN tag.
  22. *
  23. * addr_learn_en:
  24. * Enable learning the mac address of the guest OS interface in
  25. * a virtualization environment.
  26. * 0 - DISABLE
  27. * 1 - ENABLE
  28. *
  29. * max_config_port:
  30. * Maximum number of port to be supported.
  31. * MIN -1 and MAX - 2
  32. *
  33. * max_config_vpath:
  34. * This configures the maximum no of VPATH configures for each
  35. * device function.
  36. * MIN - 1 and MAX - 17
  37. *
  38. * max_config_dev:
  39. * This configures maximum no of Device function to be enabled.
  40. * MIN - 1 and MAX - 17
  41. *
  42. ******************************************************************************/
  43. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  44. #include <linux/bitops.h>
  45. #include <linux/if_vlan.h>
  46. #include <linux/interrupt.h>
  47. #include <linux/pci.h>
  48. #include <linux/slab.h>
  49. #include <linux/tcp.h>
  50. #include <net/ip.h>
  51. #include <linux/netdevice.h>
  52. #include <linux/etherdevice.h>
  53. #include <linux/firmware.h>
  54. #include <linux/net_tstamp.h>
  55. #include <linux/prefetch.h>
  56. #include <linux/module.h>
  57. #include "vxge-main.h"
  58. #include "vxge-reg.h"
  59. MODULE_LICENSE("Dual BSD/GPL");
  60. MODULE_DESCRIPTION("Neterion's X3100 Series 10GbE PCIe I/O"
  61. "Virtualized Server Adapter");
  62. static DEFINE_PCI_DEVICE_TABLE(vxge_id_table) = {
  63. {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_TITAN_WIN, PCI_ANY_ID,
  64. PCI_ANY_ID},
  65. {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_TITAN_UNI, PCI_ANY_ID,
  66. PCI_ANY_ID},
  67. {0}
  68. };
  69. MODULE_DEVICE_TABLE(pci, vxge_id_table);
  70. VXGE_MODULE_PARAM_INT(vlan_tag_strip, VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE);
  71. VXGE_MODULE_PARAM_INT(addr_learn_en, VXGE_HW_MAC_ADDR_LEARN_DEFAULT);
  72. VXGE_MODULE_PARAM_INT(max_config_port, VXGE_MAX_CONFIG_PORT);
  73. VXGE_MODULE_PARAM_INT(max_config_vpath, VXGE_USE_DEFAULT);
  74. VXGE_MODULE_PARAM_INT(max_mac_vpath, VXGE_MAX_MAC_ADDR_COUNT);
  75. VXGE_MODULE_PARAM_INT(max_config_dev, VXGE_MAX_CONFIG_DEV);
  76. static u16 vpath_selector[VXGE_HW_MAX_VIRTUAL_PATHS] =
  77. {0, 1, 3, 3, 7, 7, 7, 7, 15, 15, 15, 15, 15, 15, 15, 15, 31};
  78. static unsigned int bw_percentage[VXGE_HW_MAX_VIRTUAL_PATHS] =
  79. {[0 ...(VXGE_HW_MAX_VIRTUAL_PATHS - 1)] = 0xFF};
  80. module_param_array(bw_percentage, uint, NULL, 0);
  81. static struct vxge_drv_config *driver_config;
  82. static inline int is_vxge_card_up(struct vxgedev *vdev)
  83. {
  84. return test_bit(__VXGE_STATE_CARD_UP, &vdev->state);
  85. }
  86. static inline void VXGE_COMPLETE_VPATH_TX(struct vxge_fifo *fifo)
  87. {
  88. struct sk_buff **skb_ptr = NULL;
  89. struct sk_buff **temp;
  90. #define NR_SKB_COMPLETED 128
  91. struct sk_buff *completed[NR_SKB_COMPLETED];
  92. int more;
  93. do {
  94. more = 0;
  95. skb_ptr = completed;
  96. if (__netif_tx_trylock(fifo->txq)) {
  97. vxge_hw_vpath_poll_tx(fifo->handle, &skb_ptr,
  98. NR_SKB_COMPLETED, &more);
  99. __netif_tx_unlock(fifo->txq);
  100. }
  101. /* free SKBs */
  102. for (temp = completed; temp != skb_ptr; temp++)
  103. dev_kfree_skb_irq(*temp);
  104. } while (more);
  105. }
  106. static inline void VXGE_COMPLETE_ALL_TX(struct vxgedev *vdev)
  107. {
  108. int i;
  109. /* Complete all transmits */
  110. for (i = 0; i < vdev->no_of_vpath; i++)
  111. VXGE_COMPLETE_VPATH_TX(&vdev->vpaths[i].fifo);
  112. }
  113. static inline void VXGE_COMPLETE_ALL_RX(struct vxgedev *vdev)
  114. {
  115. int i;
  116. struct vxge_ring *ring;
  117. /* Complete all receives*/
  118. for (i = 0; i < vdev->no_of_vpath; i++) {
  119. ring = &vdev->vpaths[i].ring;
  120. vxge_hw_vpath_poll_rx(ring->handle);
  121. }
  122. }
  123. /*
  124. * vxge_callback_link_up
  125. *
  126. * This function is called during interrupt context to notify link up state
  127. * change.
  128. */
  129. static void vxge_callback_link_up(struct __vxge_hw_device *hldev)
  130. {
  131. struct net_device *dev = hldev->ndev;
  132. struct vxgedev *vdev = netdev_priv(dev);
  133. vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
  134. vdev->ndev->name, __func__, __LINE__);
  135. netdev_notice(vdev->ndev, "Link Up\n");
  136. vdev->stats.link_up++;
  137. netif_carrier_on(vdev->ndev);
  138. netif_tx_wake_all_queues(vdev->ndev);
  139. vxge_debug_entryexit(VXGE_TRACE,
  140. "%s: %s:%d Exiting...", vdev->ndev->name, __func__, __LINE__);
  141. }
  142. /*
  143. * vxge_callback_link_down
  144. *
  145. * This function is called during interrupt context to notify link down state
  146. * change.
  147. */
  148. static void vxge_callback_link_down(struct __vxge_hw_device *hldev)
  149. {
  150. struct net_device *dev = hldev->ndev;
  151. struct vxgedev *vdev = netdev_priv(dev);
  152. vxge_debug_entryexit(VXGE_TRACE,
  153. "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
  154. netdev_notice(vdev->ndev, "Link Down\n");
  155. vdev->stats.link_down++;
  156. netif_carrier_off(vdev->ndev);
  157. netif_tx_stop_all_queues(vdev->ndev);
  158. vxge_debug_entryexit(VXGE_TRACE,
  159. "%s: %s:%d Exiting...", vdev->ndev->name, __func__, __LINE__);
  160. }
  161. /*
  162. * vxge_rx_alloc
  163. *
  164. * Allocate SKB.
  165. */
  166. static struct sk_buff *
  167. vxge_rx_alloc(void *dtrh, struct vxge_ring *ring, const int skb_size)
  168. {
  169. struct net_device *dev;
  170. struct sk_buff *skb;
  171. struct vxge_rx_priv *rx_priv;
  172. dev = ring->ndev;
  173. vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
  174. ring->ndev->name, __func__, __LINE__);
  175. rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
  176. /* try to allocate skb first. this one may fail */
  177. skb = netdev_alloc_skb(dev, skb_size +
  178. VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
  179. if (skb == NULL) {
  180. vxge_debug_mem(VXGE_ERR,
  181. "%s: out of memory to allocate SKB", dev->name);
  182. ring->stats.skb_alloc_fail++;
  183. return NULL;
  184. }
  185. vxge_debug_mem(VXGE_TRACE,
  186. "%s: %s:%d Skb : 0x%p", ring->ndev->name,
  187. __func__, __LINE__, skb);
  188. skb_reserve(skb, VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
  189. rx_priv->skb = skb;
  190. rx_priv->skb_data = NULL;
  191. rx_priv->data_size = skb_size;
  192. vxge_debug_entryexit(VXGE_TRACE,
  193. "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
  194. return skb;
  195. }
  196. /*
  197. * vxge_rx_map
  198. */
  199. static int vxge_rx_map(void *dtrh, struct vxge_ring *ring)
  200. {
  201. struct vxge_rx_priv *rx_priv;
  202. dma_addr_t dma_addr;
  203. vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
  204. ring->ndev->name, __func__, __LINE__);
  205. rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
  206. rx_priv->skb_data = rx_priv->skb->data;
  207. dma_addr = pci_map_single(ring->pdev, rx_priv->skb_data,
  208. rx_priv->data_size, PCI_DMA_FROMDEVICE);
  209. if (unlikely(pci_dma_mapping_error(ring->pdev, dma_addr))) {
  210. ring->stats.pci_map_fail++;
  211. return -EIO;
  212. }
  213. vxge_debug_mem(VXGE_TRACE,
  214. "%s: %s:%d 1 buffer mode dma_addr = 0x%llx",
  215. ring->ndev->name, __func__, __LINE__,
  216. (unsigned long long)dma_addr);
  217. vxge_hw_ring_rxd_1b_set(dtrh, dma_addr, rx_priv->data_size);
  218. rx_priv->data_dma = dma_addr;
  219. vxge_debug_entryexit(VXGE_TRACE,
  220. "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
  221. return 0;
  222. }
  223. /*
  224. * vxge_rx_initial_replenish
  225. * Allocation of RxD as an initial replenish procedure.
  226. */
  227. static enum vxge_hw_status
  228. vxge_rx_initial_replenish(void *dtrh, void *userdata)
  229. {
  230. struct vxge_ring *ring = (struct vxge_ring *)userdata;
  231. struct vxge_rx_priv *rx_priv;
  232. vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
  233. ring->ndev->name, __func__, __LINE__);
  234. if (vxge_rx_alloc(dtrh, ring,
  235. VXGE_LL_MAX_FRAME_SIZE(ring->ndev)) == NULL)
  236. return VXGE_HW_FAIL;
  237. if (vxge_rx_map(dtrh, ring)) {
  238. rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
  239. dev_kfree_skb(rx_priv->skb);
  240. return VXGE_HW_FAIL;
  241. }
  242. vxge_debug_entryexit(VXGE_TRACE,
  243. "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
  244. return VXGE_HW_OK;
  245. }
  246. static inline void
  247. vxge_rx_complete(struct vxge_ring *ring, struct sk_buff *skb, u16 vlan,
  248. int pkt_length, struct vxge_hw_ring_rxd_info *ext_info)
  249. {
  250. vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
  251. ring->ndev->name, __func__, __LINE__);
  252. skb_record_rx_queue(skb, ring->driver_id);
  253. skb->protocol = eth_type_trans(skb, ring->ndev);
  254. u64_stats_update_begin(&ring->stats.syncp);
  255. ring->stats.rx_frms++;
  256. ring->stats.rx_bytes += pkt_length;
  257. if (skb->pkt_type == PACKET_MULTICAST)
  258. ring->stats.rx_mcast++;
  259. u64_stats_update_end(&ring->stats.syncp);
  260. vxge_debug_rx(VXGE_TRACE,
  261. "%s: %s:%d skb protocol = %d",
  262. ring->ndev->name, __func__, __LINE__, skb->protocol);
  263. if (ext_info->vlan &&
  264. ring->vlan_tag_strip == VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE)
  265. __vlan_hwaccel_put_tag(skb, ext_info->vlan);
  266. napi_gro_receive(ring->napi_p, skb);
  267. vxge_debug_entryexit(VXGE_TRACE,
  268. "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
  269. }
  270. static inline void vxge_re_pre_post(void *dtr, struct vxge_ring *ring,
  271. struct vxge_rx_priv *rx_priv)
  272. {
  273. pci_dma_sync_single_for_device(ring->pdev,
  274. rx_priv->data_dma, rx_priv->data_size, PCI_DMA_FROMDEVICE);
  275. vxge_hw_ring_rxd_1b_set(dtr, rx_priv->data_dma, rx_priv->data_size);
  276. vxge_hw_ring_rxd_pre_post(ring->handle, dtr);
  277. }
  278. static inline void vxge_post(int *dtr_cnt, void **first_dtr,
  279. void *post_dtr, struct __vxge_hw_ring *ringh)
  280. {
  281. int dtr_count = *dtr_cnt;
  282. if ((*dtr_cnt % VXGE_HW_RXSYNC_FREQ_CNT) == 0) {
  283. if (*first_dtr)
  284. vxge_hw_ring_rxd_post_post_wmb(ringh, *first_dtr);
  285. *first_dtr = post_dtr;
  286. } else
  287. vxge_hw_ring_rxd_post_post(ringh, post_dtr);
  288. dtr_count++;
  289. *dtr_cnt = dtr_count;
  290. }
  291. /*
  292. * vxge_rx_1b_compl
  293. *
  294. * If the interrupt is because of a received frame or if the receive ring
  295. * contains fresh as yet un-processed frames, this function is called.
  296. */
  297. static enum vxge_hw_status
  298. vxge_rx_1b_compl(struct __vxge_hw_ring *ringh, void *dtr,
  299. u8 t_code, void *userdata)
  300. {
  301. struct vxge_ring *ring = (struct vxge_ring *)userdata;
  302. struct net_device *dev = ring->ndev;
  303. unsigned int dma_sizes;
  304. void *first_dtr = NULL;
  305. int dtr_cnt = 0;
  306. int data_size;
  307. dma_addr_t data_dma;
  308. int pkt_length;
  309. struct sk_buff *skb;
  310. struct vxge_rx_priv *rx_priv;
  311. struct vxge_hw_ring_rxd_info ext_info;
  312. vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
  313. ring->ndev->name, __func__, __LINE__);
  314. do {
  315. prefetch((char *)dtr + L1_CACHE_BYTES);
  316. rx_priv = vxge_hw_ring_rxd_private_get(dtr);
  317. skb = rx_priv->skb;
  318. data_size = rx_priv->data_size;
  319. data_dma = rx_priv->data_dma;
  320. prefetch(rx_priv->skb_data);
  321. vxge_debug_rx(VXGE_TRACE,
  322. "%s: %s:%d skb = 0x%p",
  323. ring->ndev->name, __func__, __LINE__, skb);
  324. vxge_hw_ring_rxd_1b_get(ringh, dtr, &dma_sizes);
  325. pkt_length = dma_sizes;
  326. pkt_length -= ETH_FCS_LEN;
  327. vxge_debug_rx(VXGE_TRACE,
  328. "%s: %s:%d Packet Length = %d",
  329. ring->ndev->name, __func__, __LINE__, pkt_length);
  330. vxge_hw_ring_rxd_1b_info_get(ringh, dtr, &ext_info);
  331. /* check skb validity */
  332. vxge_assert(skb);
  333. prefetch((char *)skb + L1_CACHE_BYTES);
  334. if (unlikely(t_code)) {
  335. if (vxge_hw_ring_handle_tcode(ringh, dtr, t_code) !=
  336. VXGE_HW_OK) {
  337. ring->stats.rx_errors++;
  338. vxge_debug_rx(VXGE_TRACE,
  339. "%s: %s :%d Rx T_code is %d",
  340. ring->ndev->name, __func__,
  341. __LINE__, t_code);
  342. /* If the t_code is not supported and if the
  343. * t_code is other than 0x5 (unparseable packet
  344. * such as unknown UPV6 header), Drop it !!!
  345. */
  346. vxge_re_pre_post(dtr, ring, rx_priv);
  347. vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
  348. ring->stats.rx_dropped++;
  349. continue;
  350. }
  351. }
  352. if (pkt_length > VXGE_LL_RX_COPY_THRESHOLD) {
  353. if (vxge_rx_alloc(dtr, ring, data_size) != NULL) {
  354. if (!vxge_rx_map(dtr, ring)) {
  355. skb_put(skb, pkt_length);
  356. pci_unmap_single(ring->pdev, data_dma,
  357. data_size, PCI_DMA_FROMDEVICE);
  358. vxge_hw_ring_rxd_pre_post(ringh, dtr);
  359. vxge_post(&dtr_cnt, &first_dtr, dtr,
  360. ringh);
  361. } else {
  362. dev_kfree_skb(rx_priv->skb);
  363. rx_priv->skb = skb;
  364. rx_priv->data_size = data_size;
  365. vxge_re_pre_post(dtr, ring, rx_priv);
  366. vxge_post(&dtr_cnt, &first_dtr, dtr,
  367. ringh);
  368. ring->stats.rx_dropped++;
  369. break;
  370. }
  371. } else {
  372. vxge_re_pre_post(dtr, ring, rx_priv);
  373. vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
  374. ring->stats.rx_dropped++;
  375. break;
  376. }
  377. } else {
  378. struct sk_buff *skb_up;
  379. skb_up = netdev_alloc_skb(dev, pkt_length +
  380. VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
  381. if (skb_up != NULL) {
  382. skb_reserve(skb_up,
  383. VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
  384. pci_dma_sync_single_for_cpu(ring->pdev,
  385. data_dma, data_size,
  386. PCI_DMA_FROMDEVICE);
  387. vxge_debug_mem(VXGE_TRACE,
  388. "%s: %s:%d skb_up = %p",
  389. ring->ndev->name, __func__,
  390. __LINE__, skb);
  391. memcpy(skb_up->data, skb->data, pkt_length);
  392. vxge_re_pre_post(dtr, ring, rx_priv);
  393. vxge_post(&dtr_cnt, &first_dtr, dtr,
  394. ringh);
  395. /* will netif_rx small SKB instead */
  396. skb = skb_up;
  397. skb_put(skb, pkt_length);
  398. } else {
  399. vxge_re_pre_post(dtr, ring, rx_priv);
  400. vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
  401. vxge_debug_rx(VXGE_ERR,
  402. "%s: vxge_rx_1b_compl: out of "
  403. "memory", dev->name);
  404. ring->stats.skb_alloc_fail++;
  405. break;
  406. }
  407. }
  408. if ((ext_info.proto & VXGE_HW_FRAME_PROTO_TCP_OR_UDP) &&
  409. !(ext_info.proto & VXGE_HW_FRAME_PROTO_IP_FRAG) &&
  410. (dev->features & NETIF_F_RXCSUM) && /* Offload Rx side CSUM */
  411. ext_info.l3_cksum == VXGE_HW_L3_CKSUM_OK &&
  412. ext_info.l4_cksum == VXGE_HW_L4_CKSUM_OK)
  413. skb->ip_summed = CHECKSUM_UNNECESSARY;
  414. else
  415. skb_checksum_none_assert(skb);
  416. if (ring->rx_hwts) {
  417. struct skb_shared_hwtstamps *skb_hwts;
  418. u32 ns = *(u32 *)(skb->head + pkt_length);
  419. skb_hwts = skb_hwtstamps(skb);
  420. skb_hwts->hwtstamp = ns_to_ktime(ns);
  421. skb_hwts->syststamp.tv64 = 0;
  422. }
  423. /* rth_hash_type and rth_it_hit are non-zero regardless of
  424. * whether rss is enabled. Only the rth_value is zero/non-zero
  425. * if rss is disabled/enabled, so key off of that.
  426. */
  427. if (ext_info.rth_value)
  428. skb->rxhash = ext_info.rth_value;
  429. vxge_rx_complete(ring, skb, ext_info.vlan,
  430. pkt_length, &ext_info);
  431. ring->budget--;
  432. ring->pkts_processed++;
  433. if (!ring->budget)
  434. break;
  435. } while (vxge_hw_ring_rxd_next_completed(ringh, &dtr,
  436. &t_code) == VXGE_HW_OK);
  437. if (first_dtr)
  438. vxge_hw_ring_rxd_post_post_wmb(ringh, first_dtr);
  439. vxge_debug_entryexit(VXGE_TRACE,
  440. "%s:%d Exiting...",
  441. __func__, __LINE__);
  442. return VXGE_HW_OK;
  443. }
  444. /*
  445. * vxge_xmit_compl
  446. *
  447. * If an interrupt was raised to indicate DMA complete of the Tx packet,
  448. * this function is called. It identifies the last TxD whose buffer was
  449. * freed and frees all skbs whose data have already DMA'ed into the NICs
  450. * internal memory.
  451. */
  452. static enum vxge_hw_status
  453. vxge_xmit_compl(struct __vxge_hw_fifo *fifo_hw, void *dtr,
  454. enum vxge_hw_fifo_tcode t_code, void *userdata,
  455. struct sk_buff ***skb_ptr, int nr_skb, int *more)
  456. {
  457. struct vxge_fifo *fifo = (struct vxge_fifo *)userdata;
  458. struct sk_buff *skb, **done_skb = *skb_ptr;
  459. int pkt_cnt = 0;
  460. vxge_debug_entryexit(VXGE_TRACE,
  461. "%s:%d Entered....", __func__, __LINE__);
  462. do {
  463. int frg_cnt;
  464. skb_frag_t *frag;
  465. int i = 0, j;
  466. struct vxge_tx_priv *txd_priv =
  467. vxge_hw_fifo_txdl_private_get(dtr);
  468. skb = txd_priv->skb;
  469. frg_cnt = skb_shinfo(skb)->nr_frags;
  470. frag = &skb_shinfo(skb)->frags[0];
  471. vxge_debug_tx(VXGE_TRACE,
  472. "%s: %s:%d fifo_hw = %p dtr = %p "
  473. "tcode = 0x%x", fifo->ndev->name, __func__,
  474. __LINE__, fifo_hw, dtr, t_code);
  475. /* check skb validity */
  476. vxge_assert(skb);
  477. vxge_debug_tx(VXGE_TRACE,
  478. "%s: %s:%d skb = %p itxd_priv = %p frg_cnt = %d",
  479. fifo->ndev->name, __func__, __LINE__,
  480. skb, txd_priv, frg_cnt);
  481. if (unlikely(t_code)) {
  482. fifo->stats.tx_errors++;
  483. vxge_debug_tx(VXGE_ERR,
  484. "%s: tx: dtr %p completed due to "
  485. "error t_code %01x", fifo->ndev->name,
  486. dtr, t_code);
  487. vxge_hw_fifo_handle_tcode(fifo_hw, dtr, t_code);
  488. }
  489. /* for unfragmented skb */
  490. pci_unmap_single(fifo->pdev, txd_priv->dma_buffers[i++],
  491. skb_headlen(skb), PCI_DMA_TODEVICE);
  492. for (j = 0; j < frg_cnt; j++) {
  493. pci_unmap_page(fifo->pdev,
  494. txd_priv->dma_buffers[i++],
  495. skb_frag_size(frag), PCI_DMA_TODEVICE);
  496. frag += 1;
  497. }
  498. vxge_hw_fifo_txdl_free(fifo_hw, dtr);
  499. /* Updating the statistics block */
  500. u64_stats_update_begin(&fifo->stats.syncp);
  501. fifo->stats.tx_frms++;
  502. fifo->stats.tx_bytes += skb->len;
  503. u64_stats_update_end(&fifo->stats.syncp);
  504. *done_skb++ = skb;
  505. if (--nr_skb <= 0) {
  506. *more = 1;
  507. break;
  508. }
  509. pkt_cnt++;
  510. if (pkt_cnt > fifo->indicate_max_pkts)
  511. break;
  512. } while (vxge_hw_fifo_txdl_next_completed(fifo_hw,
  513. &dtr, &t_code) == VXGE_HW_OK);
  514. *skb_ptr = done_skb;
  515. if (netif_tx_queue_stopped(fifo->txq))
  516. netif_tx_wake_queue(fifo->txq);
  517. vxge_debug_entryexit(VXGE_TRACE,
  518. "%s: %s:%d Exiting...",
  519. fifo->ndev->name, __func__, __LINE__);
  520. return VXGE_HW_OK;
  521. }
  522. /* select a vpath to transmit the packet */
  523. static u32 vxge_get_vpath_no(struct vxgedev *vdev, struct sk_buff *skb)
  524. {
  525. u16 queue_len, counter = 0;
  526. if (skb->protocol == htons(ETH_P_IP)) {
  527. struct iphdr *ip;
  528. struct tcphdr *th;
  529. ip = ip_hdr(skb);
  530. if (!ip_is_fragment(ip)) {
  531. th = (struct tcphdr *)(((unsigned char *)ip) +
  532. ip->ihl*4);
  533. queue_len = vdev->no_of_vpath;
  534. counter = (ntohs(th->source) +
  535. ntohs(th->dest)) &
  536. vdev->vpath_selector[queue_len - 1];
  537. if (counter >= queue_len)
  538. counter = queue_len - 1;
  539. }
  540. }
  541. return counter;
  542. }
  543. static enum vxge_hw_status vxge_search_mac_addr_in_list(
  544. struct vxge_vpath *vpath, u64 del_mac)
  545. {
  546. struct list_head *entry, *next;
  547. list_for_each_safe(entry, next, &vpath->mac_addr_list) {
  548. if (((struct vxge_mac_addrs *)entry)->macaddr == del_mac)
  549. return TRUE;
  550. }
  551. return FALSE;
  552. }
  553. static int vxge_mac_list_add(struct vxge_vpath *vpath, struct macInfo *mac)
  554. {
  555. struct vxge_mac_addrs *new_mac_entry;
  556. u8 *mac_address = NULL;
  557. if (vpath->mac_addr_cnt >= VXGE_MAX_LEARN_MAC_ADDR_CNT)
  558. return TRUE;
  559. new_mac_entry = kzalloc(sizeof(struct vxge_mac_addrs), GFP_ATOMIC);
  560. if (!new_mac_entry) {
  561. vxge_debug_mem(VXGE_ERR,
  562. "%s: memory allocation failed",
  563. VXGE_DRIVER_NAME);
  564. return FALSE;
  565. }
  566. list_add(&new_mac_entry->item, &vpath->mac_addr_list);
  567. /* Copy the new mac address to the list */
  568. mac_address = (u8 *)&new_mac_entry->macaddr;
  569. memcpy(mac_address, mac->macaddr, ETH_ALEN);
  570. new_mac_entry->state = mac->state;
  571. vpath->mac_addr_cnt++;
  572. if (is_multicast_ether_addr(mac->macaddr))
  573. vpath->mcast_addr_cnt++;
  574. return TRUE;
  575. }
  576. /* Add a mac address to DA table */
  577. static enum vxge_hw_status
  578. vxge_add_mac_addr(struct vxgedev *vdev, struct macInfo *mac)
  579. {
  580. enum vxge_hw_status status = VXGE_HW_OK;
  581. struct vxge_vpath *vpath;
  582. enum vxge_hw_vpath_mac_addr_add_mode duplicate_mode;
  583. if (is_multicast_ether_addr(mac->macaddr))
  584. duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE;
  585. else
  586. duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_REPLACE_DUPLICATE;
  587. vpath = &vdev->vpaths[mac->vpath_no];
  588. status = vxge_hw_vpath_mac_addr_add(vpath->handle, mac->macaddr,
  589. mac->macmask, duplicate_mode);
  590. if (status != VXGE_HW_OK) {
  591. vxge_debug_init(VXGE_ERR,
  592. "DA config add entry failed for vpath:%d",
  593. vpath->device_id);
  594. } else
  595. if (FALSE == vxge_mac_list_add(vpath, mac))
  596. status = -EPERM;
  597. return status;
  598. }
  599. static int vxge_learn_mac(struct vxgedev *vdev, u8 *mac_header)
  600. {
  601. struct macInfo mac_info;
  602. u8 *mac_address = NULL;
  603. u64 mac_addr = 0, vpath_vector = 0;
  604. int vpath_idx = 0;
  605. enum vxge_hw_status status = VXGE_HW_OK;
  606. struct vxge_vpath *vpath = NULL;
  607. struct __vxge_hw_device *hldev;
  608. hldev = pci_get_drvdata(vdev->pdev);
  609. mac_address = (u8 *)&mac_addr;
  610. memcpy(mac_address, mac_header, ETH_ALEN);
  611. /* Is this mac address already in the list? */
  612. for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
  613. vpath = &vdev->vpaths[vpath_idx];
  614. if (vxge_search_mac_addr_in_list(vpath, mac_addr))
  615. return vpath_idx;
  616. }
  617. memset(&mac_info, 0, sizeof(struct macInfo));
  618. memcpy(mac_info.macaddr, mac_header, ETH_ALEN);
  619. /* Any vpath has room to add mac address to its da table? */
  620. for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
  621. vpath = &vdev->vpaths[vpath_idx];
  622. if (vpath->mac_addr_cnt < vpath->max_mac_addr_cnt) {
  623. /* Add this mac address to this vpath */
  624. mac_info.vpath_no = vpath_idx;
  625. mac_info.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
  626. status = vxge_add_mac_addr(vdev, &mac_info);
  627. if (status != VXGE_HW_OK)
  628. return -EPERM;
  629. return vpath_idx;
  630. }
  631. }
  632. mac_info.state = VXGE_LL_MAC_ADDR_IN_LIST;
  633. vpath_idx = 0;
  634. mac_info.vpath_no = vpath_idx;
  635. /* Is the first vpath already selected as catch-basin ? */
  636. vpath = &vdev->vpaths[vpath_idx];
  637. if (vpath->mac_addr_cnt > vpath->max_mac_addr_cnt) {
  638. /* Add this mac address to this vpath */
  639. if (FALSE == vxge_mac_list_add(vpath, &mac_info))
  640. return -EPERM;
  641. return vpath_idx;
  642. }
  643. /* Select first vpath as catch-basin */
  644. vpath_vector = vxge_mBIT(vpath->device_id);
  645. status = vxge_hw_mgmt_reg_write(vpath->vdev->devh,
  646. vxge_hw_mgmt_reg_type_mrpcim,
  647. 0,
  648. (ulong)offsetof(
  649. struct vxge_hw_mrpcim_reg,
  650. rts_mgr_cbasin_cfg),
  651. vpath_vector);
  652. if (status != VXGE_HW_OK) {
  653. vxge_debug_tx(VXGE_ERR,
  654. "%s: Unable to set the vpath-%d in catch-basin mode",
  655. VXGE_DRIVER_NAME, vpath->device_id);
  656. return -EPERM;
  657. }
  658. if (FALSE == vxge_mac_list_add(vpath, &mac_info))
  659. return -EPERM;
  660. return vpath_idx;
  661. }
  662. /**
  663. * vxge_xmit
  664. * @skb : the socket buffer containing the Tx data.
  665. * @dev : device pointer.
  666. *
  667. * This function is the Tx entry point of the driver. Neterion NIC supports
  668. * certain protocol assist features on Tx side, namely CSO, S/G, LSO.
  669. */
  670. static netdev_tx_t
  671. vxge_xmit(struct sk_buff *skb, struct net_device *dev)
  672. {
  673. struct vxge_fifo *fifo = NULL;
  674. void *dtr_priv;
  675. void *dtr = NULL;
  676. struct vxgedev *vdev = NULL;
  677. enum vxge_hw_status status;
  678. int frg_cnt, first_frg_len;
  679. skb_frag_t *frag;
  680. int i = 0, j = 0, avail;
  681. u64 dma_pointer;
  682. struct vxge_tx_priv *txdl_priv = NULL;
  683. struct __vxge_hw_fifo *fifo_hw;
  684. int offload_type;
  685. int vpath_no = 0;
  686. vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
  687. dev->name, __func__, __LINE__);
  688. /* A buffer with no data will be dropped */
  689. if (unlikely(skb->len <= 0)) {
  690. vxge_debug_tx(VXGE_ERR,
  691. "%s: Buffer has no data..", dev->name);
  692. dev_kfree_skb(skb);
  693. return NETDEV_TX_OK;
  694. }
  695. vdev = netdev_priv(dev);
  696. if (unlikely(!is_vxge_card_up(vdev))) {
  697. vxge_debug_tx(VXGE_ERR,
  698. "%s: vdev not initialized", dev->name);
  699. dev_kfree_skb(skb);
  700. return NETDEV_TX_OK;
  701. }
  702. if (vdev->config.addr_learn_en) {
  703. vpath_no = vxge_learn_mac(vdev, skb->data + ETH_ALEN);
  704. if (vpath_no == -EPERM) {
  705. vxge_debug_tx(VXGE_ERR,
  706. "%s: Failed to store the mac address",
  707. dev->name);
  708. dev_kfree_skb(skb);
  709. return NETDEV_TX_OK;
  710. }
  711. }
  712. if (vdev->config.tx_steering_type == TX_MULTIQ_STEERING)
  713. vpath_no = skb_get_queue_mapping(skb);
  714. else if (vdev->config.tx_steering_type == TX_PORT_STEERING)
  715. vpath_no = vxge_get_vpath_no(vdev, skb);
  716. vxge_debug_tx(VXGE_TRACE, "%s: vpath_no= %d", dev->name, vpath_no);
  717. if (vpath_no >= vdev->no_of_vpath)
  718. vpath_no = 0;
  719. fifo = &vdev->vpaths[vpath_no].fifo;
  720. fifo_hw = fifo->handle;
  721. if (netif_tx_queue_stopped(fifo->txq))
  722. return NETDEV_TX_BUSY;
  723. avail = vxge_hw_fifo_free_txdl_count_get(fifo_hw);
  724. if (avail == 0) {
  725. vxge_debug_tx(VXGE_ERR,
  726. "%s: No free TXDs available", dev->name);
  727. fifo->stats.txd_not_free++;
  728. goto _exit0;
  729. }
  730. /* Last TXD? Stop tx queue to avoid dropping packets. TX
  731. * completion will resume the queue.
  732. */
  733. if (avail == 1)
  734. netif_tx_stop_queue(fifo->txq);
  735. status = vxge_hw_fifo_txdl_reserve(fifo_hw, &dtr, &dtr_priv);
  736. if (unlikely(status != VXGE_HW_OK)) {
  737. vxge_debug_tx(VXGE_ERR,
  738. "%s: Out of descriptors .", dev->name);
  739. fifo->stats.txd_out_of_desc++;
  740. goto _exit0;
  741. }
  742. vxge_debug_tx(VXGE_TRACE,
  743. "%s: %s:%d fifo_hw = %p dtr = %p dtr_priv = %p",
  744. dev->name, __func__, __LINE__,
  745. fifo_hw, dtr, dtr_priv);
  746. if (vlan_tx_tag_present(skb)) {
  747. u16 vlan_tag = vlan_tx_tag_get(skb);
  748. vxge_hw_fifo_txdl_vlan_set(dtr, vlan_tag);
  749. }
  750. first_frg_len = skb_headlen(skb);
  751. dma_pointer = pci_map_single(fifo->pdev, skb->data, first_frg_len,
  752. PCI_DMA_TODEVICE);
  753. if (unlikely(pci_dma_mapping_error(fifo->pdev, dma_pointer))) {
  754. vxge_hw_fifo_txdl_free(fifo_hw, dtr);
  755. fifo->stats.pci_map_fail++;
  756. goto _exit0;
  757. }
  758. txdl_priv = vxge_hw_fifo_txdl_private_get(dtr);
  759. txdl_priv->skb = skb;
  760. txdl_priv->dma_buffers[j] = dma_pointer;
  761. frg_cnt = skb_shinfo(skb)->nr_frags;
  762. vxge_debug_tx(VXGE_TRACE,
  763. "%s: %s:%d skb = %p txdl_priv = %p "
  764. "frag_cnt = %d dma_pointer = 0x%llx", dev->name,
  765. __func__, __LINE__, skb, txdl_priv,
  766. frg_cnt, (unsigned long long)dma_pointer);
  767. vxge_hw_fifo_txdl_buffer_set(fifo_hw, dtr, j++, dma_pointer,
  768. first_frg_len);
  769. frag = &skb_shinfo(skb)->frags[0];
  770. for (i = 0; i < frg_cnt; i++) {
  771. /* ignore 0 length fragment */
  772. if (!skb_frag_size(frag))
  773. continue;
  774. dma_pointer = (u64)skb_frag_dma_map(&fifo->pdev->dev, frag,
  775. 0, skb_frag_size(frag),
  776. DMA_TO_DEVICE);
  777. if (unlikely(dma_mapping_error(&fifo->pdev->dev, dma_pointer)))
  778. goto _exit2;
  779. vxge_debug_tx(VXGE_TRACE,
  780. "%s: %s:%d frag = %d dma_pointer = 0x%llx",
  781. dev->name, __func__, __LINE__, i,
  782. (unsigned long long)dma_pointer);
  783. txdl_priv->dma_buffers[j] = dma_pointer;
  784. vxge_hw_fifo_txdl_buffer_set(fifo_hw, dtr, j++, dma_pointer,
  785. skb_frag_size(frag));
  786. frag += 1;
  787. }
  788. offload_type = vxge_offload_type(skb);
  789. if (offload_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6)) {
  790. int mss = vxge_tcp_mss(skb);
  791. if (mss) {
  792. vxge_debug_tx(VXGE_TRACE, "%s: %s:%d mss = %d",
  793. dev->name, __func__, __LINE__, mss);
  794. vxge_hw_fifo_txdl_mss_set(dtr, mss);
  795. } else {
  796. vxge_assert(skb->len <=
  797. dev->mtu + VXGE_HW_MAC_HEADER_MAX_SIZE);
  798. vxge_assert(0);
  799. goto _exit1;
  800. }
  801. }
  802. if (skb->ip_summed == CHECKSUM_PARTIAL)
  803. vxge_hw_fifo_txdl_cksum_set_bits(dtr,
  804. VXGE_HW_FIFO_TXD_TX_CKO_IPV4_EN |
  805. VXGE_HW_FIFO_TXD_TX_CKO_TCP_EN |
  806. VXGE_HW_FIFO_TXD_TX_CKO_UDP_EN);
  807. vxge_hw_fifo_txdl_post(fifo_hw, dtr);
  808. vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...",
  809. dev->name, __func__, __LINE__);
  810. return NETDEV_TX_OK;
  811. _exit2:
  812. vxge_debug_tx(VXGE_TRACE, "%s: pci_map_page failed", dev->name);
  813. _exit1:
  814. j = 0;
  815. frag = &skb_shinfo(skb)->frags[0];
  816. pci_unmap_single(fifo->pdev, txdl_priv->dma_buffers[j++],
  817. skb_headlen(skb), PCI_DMA_TODEVICE);
  818. for (; j < i; j++) {
  819. pci_unmap_page(fifo->pdev, txdl_priv->dma_buffers[j],
  820. skb_frag_size(frag), PCI_DMA_TODEVICE);
  821. frag += 1;
  822. }
  823. vxge_hw_fifo_txdl_free(fifo_hw, dtr);
  824. _exit0:
  825. netif_tx_stop_queue(fifo->txq);
  826. dev_kfree_skb(skb);
  827. return NETDEV_TX_OK;
  828. }
  829. /*
  830. * vxge_rx_term
  831. *
  832. * Function will be called by hw function to abort all outstanding receive
  833. * descriptors.
  834. */
  835. static void
  836. vxge_rx_term(void *dtrh, enum vxge_hw_rxd_state state, void *userdata)
  837. {
  838. struct vxge_ring *ring = (struct vxge_ring *)userdata;
  839. struct vxge_rx_priv *rx_priv =
  840. vxge_hw_ring_rxd_private_get(dtrh);
  841. vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
  842. ring->ndev->name, __func__, __LINE__);
  843. if (state != VXGE_HW_RXD_STATE_POSTED)
  844. return;
  845. pci_unmap_single(ring->pdev, rx_priv->data_dma,
  846. rx_priv->data_size, PCI_DMA_FROMDEVICE);
  847. dev_kfree_skb(rx_priv->skb);
  848. rx_priv->skb_data = NULL;
  849. vxge_debug_entryexit(VXGE_TRACE,
  850. "%s: %s:%d Exiting...",
  851. ring->ndev->name, __func__, __LINE__);
  852. }
  853. /*
  854. * vxge_tx_term
  855. *
  856. * Function will be called to abort all outstanding tx descriptors
  857. */
  858. static void
  859. vxge_tx_term(void *dtrh, enum vxge_hw_txdl_state state, void *userdata)
  860. {
  861. struct vxge_fifo *fifo = (struct vxge_fifo *)userdata;
  862. skb_frag_t *frag;
  863. int i = 0, j, frg_cnt;
  864. struct vxge_tx_priv *txd_priv = vxge_hw_fifo_txdl_private_get(dtrh);
  865. struct sk_buff *skb = txd_priv->skb;
  866. vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
  867. if (state != VXGE_HW_TXDL_STATE_POSTED)
  868. return;
  869. /* check skb validity */
  870. vxge_assert(skb);
  871. frg_cnt = skb_shinfo(skb)->nr_frags;
  872. frag = &skb_shinfo(skb)->frags[0];
  873. /* for unfragmented skb */
  874. pci_unmap_single(fifo->pdev, txd_priv->dma_buffers[i++],
  875. skb_headlen(skb), PCI_DMA_TODEVICE);
  876. for (j = 0; j < frg_cnt; j++) {
  877. pci_unmap_page(fifo->pdev, txd_priv->dma_buffers[i++],
  878. skb_frag_size(frag), PCI_DMA_TODEVICE);
  879. frag += 1;
  880. }
  881. dev_kfree_skb(skb);
  882. vxge_debug_entryexit(VXGE_TRACE,
  883. "%s:%d Exiting...", __func__, __LINE__);
  884. }
  885. static int vxge_mac_list_del(struct vxge_vpath *vpath, struct macInfo *mac)
  886. {
  887. struct list_head *entry, *next;
  888. u64 del_mac = 0;
  889. u8 *mac_address = (u8 *) (&del_mac);
  890. /* Copy the mac address to delete from the list */
  891. memcpy(mac_address, mac->macaddr, ETH_ALEN);
  892. list_for_each_safe(entry, next, &vpath->mac_addr_list) {
  893. if (((struct vxge_mac_addrs *)entry)->macaddr == del_mac) {
  894. list_del(entry);
  895. kfree((struct vxge_mac_addrs *)entry);
  896. vpath->mac_addr_cnt--;
  897. if (is_multicast_ether_addr(mac->macaddr))
  898. vpath->mcast_addr_cnt--;
  899. return TRUE;
  900. }
  901. }
  902. return FALSE;
  903. }
  904. /* delete a mac address from DA table */
  905. static enum vxge_hw_status
  906. vxge_del_mac_addr(struct vxgedev *vdev, struct macInfo *mac)
  907. {
  908. enum vxge_hw_status status = VXGE_HW_OK;
  909. struct vxge_vpath *vpath;
  910. vpath = &vdev->vpaths[mac->vpath_no];
  911. status = vxge_hw_vpath_mac_addr_delete(vpath->handle, mac->macaddr,
  912. mac->macmask);
  913. if (status != VXGE_HW_OK) {
  914. vxge_debug_init(VXGE_ERR,
  915. "DA config delete entry failed for vpath:%d",
  916. vpath->device_id);
  917. } else
  918. vxge_mac_list_del(vpath, mac);
  919. return status;
  920. }
  921. /**
  922. * vxge_set_multicast
  923. * @dev: pointer to the device structure
  924. *
  925. * Entry point for multicast address enable/disable
  926. * This function is a driver entry point which gets called by the kernel
  927. * whenever multicast addresses must be enabled/disabled. This also gets
  928. * called to set/reset promiscuous mode. Depending on the deivce flag, we
  929. * determine, if multicast address must be enabled or if promiscuous mode
  930. * is to be disabled etc.
  931. */
  932. static void vxge_set_multicast(struct net_device *dev)
  933. {
  934. struct netdev_hw_addr *ha;
  935. struct vxgedev *vdev;
  936. int i, mcast_cnt = 0;
  937. struct __vxge_hw_device *hldev;
  938. struct vxge_vpath *vpath;
  939. enum vxge_hw_status status = VXGE_HW_OK;
  940. struct macInfo mac_info;
  941. int vpath_idx = 0;
  942. struct vxge_mac_addrs *mac_entry;
  943. struct list_head *list_head;
  944. struct list_head *entry, *next;
  945. u8 *mac_address = NULL;
  946. vxge_debug_entryexit(VXGE_TRACE,
  947. "%s:%d", __func__, __LINE__);
  948. vdev = netdev_priv(dev);
  949. hldev = vdev->devh;
  950. if (unlikely(!is_vxge_card_up(vdev)))
  951. return;
  952. if ((dev->flags & IFF_ALLMULTI) && (!vdev->all_multi_flg)) {
  953. for (i = 0; i < vdev->no_of_vpath; i++) {
  954. vpath = &vdev->vpaths[i];
  955. vxge_assert(vpath->is_open);
  956. status = vxge_hw_vpath_mcast_enable(vpath->handle);
  957. if (status != VXGE_HW_OK)
  958. vxge_debug_init(VXGE_ERR, "failed to enable "
  959. "multicast, status %d", status);
  960. vdev->all_multi_flg = 1;
  961. }
  962. } else if (!(dev->flags & IFF_ALLMULTI) && (vdev->all_multi_flg)) {
  963. for (i = 0; i < vdev->no_of_vpath; i++) {
  964. vpath = &vdev->vpaths[i];
  965. vxge_assert(vpath->is_open);
  966. status = vxge_hw_vpath_mcast_disable(vpath->handle);
  967. if (status != VXGE_HW_OK)
  968. vxge_debug_init(VXGE_ERR, "failed to disable "
  969. "multicast, status %d", status);
  970. vdev->all_multi_flg = 0;
  971. }
  972. }
  973. if (!vdev->config.addr_learn_en) {
  974. for (i = 0; i < vdev->no_of_vpath; i++) {
  975. vpath = &vdev->vpaths[i];
  976. vxge_assert(vpath->is_open);
  977. if (dev->flags & IFF_PROMISC)
  978. status = vxge_hw_vpath_promisc_enable(
  979. vpath->handle);
  980. else
  981. status = vxge_hw_vpath_promisc_disable(
  982. vpath->handle);
  983. if (status != VXGE_HW_OK)
  984. vxge_debug_init(VXGE_ERR, "failed to %s promisc"
  985. ", status %d", dev->flags&IFF_PROMISC ?
  986. "enable" : "disable", status);
  987. }
  988. }
  989. memset(&mac_info, 0, sizeof(struct macInfo));
  990. /* Update individual M_CAST address list */
  991. if ((!vdev->all_multi_flg) && netdev_mc_count(dev)) {
  992. mcast_cnt = vdev->vpaths[0].mcast_addr_cnt;
  993. list_head = &vdev->vpaths[0].mac_addr_list;
  994. if ((netdev_mc_count(dev) +
  995. (vdev->vpaths[0].mac_addr_cnt - mcast_cnt)) >
  996. vdev->vpaths[0].max_mac_addr_cnt)
  997. goto _set_all_mcast;
  998. /* Delete previous MC's */
  999. for (i = 0; i < mcast_cnt; i++) {
  1000. list_for_each_safe(entry, next, list_head) {
  1001. mac_entry = (struct vxge_mac_addrs *)entry;
  1002. /* Copy the mac address to delete */
  1003. mac_address = (u8 *)&mac_entry->macaddr;
  1004. memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
  1005. if (is_multicast_ether_addr(mac_info.macaddr)) {
  1006. for (vpath_idx = 0; vpath_idx <
  1007. vdev->no_of_vpath;
  1008. vpath_idx++) {
  1009. mac_info.vpath_no = vpath_idx;
  1010. status = vxge_del_mac_addr(
  1011. vdev,
  1012. &mac_info);
  1013. }
  1014. }
  1015. }
  1016. }
  1017. /* Add new ones */
  1018. netdev_for_each_mc_addr(ha, dev) {
  1019. memcpy(mac_info.macaddr, ha->addr, ETH_ALEN);
  1020. for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath;
  1021. vpath_idx++) {
  1022. mac_info.vpath_no = vpath_idx;
  1023. mac_info.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
  1024. status = vxge_add_mac_addr(vdev, &mac_info);
  1025. if (status != VXGE_HW_OK) {
  1026. vxge_debug_init(VXGE_ERR,
  1027. "%s:%d Setting individual"
  1028. "multicast address failed",
  1029. __func__, __LINE__);
  1030. goto _set_all_mcast;
  1031. }
  1032. }
  1033. }
  1034. return;
  1035. _set_all_mcast:
  1036. mcast_cnt = vdev->vpaths[0].mcast_addr_cnt;
  1037. /* Delete previous MC's */
  1038. for (i = 0; i < mcast_cnt; i++) {
  1039. list_for_each_safe(entry, next, list_head) {
  1040. mac_entry = (struct vxge_mac_addrs *)entry;
  1041. /* Copy the mac address to delete */
  1042. mac_address = (u8 *)&mac_entry->macaddr;
  1043. memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
  1044. if (is_multicast_ether_addr(mac_info.macaddr))
  1045. break;
  1046. }
  1047. for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath;
  1048. vpath_idx++) {
  1049. mac_info.vpath_no = vpath_idx;
  1050. status = vxge_del_mac_addr(vdev, &mac_info);
  1051. }
  1052. }
  1053. /* Enable all multicast */
  1054. for (i = 0; i < vdev->no_of_vpath; i++) {
  1055. vpath = &vdev->vpaths[i];
  1056. vxge_assert(vpath->is_open);
  1057. status = vxge_hw_vpath_mcast_enable(vpath->handle);
  1058. if (status != VXGE_HW_OK) {
  1059. vxge_debug_init(VXGE_ERR,
  1060. "%s:%d Enabling all multicasts failed",
  1061. __func__, __LINE__);
  1062. }
  1063. vdev->all_multi_flg = 1;
  1064. }
  1065. dev->flags |= IFF_ALLMULTI;
  1066. }
  1067. vxge_debug_entryexit(VXGE_TRACE,
  1068. "%s:%d Exiting...", __func__, __LINE__);
  1069. }
  1070. /**
  1071. * vxge_set_mac_addr
  1072. * @dev: pointer to the device structure
  1073. *
  1074. * Update entry "0" (default MAC addr)
  1075. */
  1076. static int vxge_set_mac_addr(struct net_device *dev, void *p)
  1077. {
  1078. struct sockaddr *addr = p;
  1079. struct vxgedev *vdev;
  1080. struct __vxge_hw_device *hldev;
  1081. enum vxge_hw_status status = VXGE_HW_OK;
  1082. struct macInfo mac_info_new, mac_info_old;
  1083. int vpath_idx = 0;
  1084. vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
  1085. vdev = netdev_priv(dev);
  1086. hldev = vdev->devh;
  1087. if (!is_valid_ether_addr(addr->sa_data))
  1088. return -EINVAL;
  1089. memset(&mac_info_new, 0, sizeof(struct macInfo));
  1090. memset(&mac_info_old, 0, sizeof(struct macInfo));
  1091. vxge_debug_entryexit(VXGE_TRACE, "%s:%d Exiting...",
  1092. __func__, __LINE__);
  1093. /* Get the old address */
  1094. memcpy(mac_info_old.macaddr, dev->dev_addr, dev->addr_len);
  1095. /* Copy the new address */
  1096. memcpy(mac_info_new.macaddr, addr->sa_data, dev->addr_len);
  1097. /* First delete the old mac address from all the vpaths
  1098. as we can't specify the index while adding new mac address */
  1099. for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
  1100. struct vxge_vpath *vpath = &vdev->vpaths[vpath_idx];
  1101. if (!vpath->is_open) {
  1102. /* This can happen when this interface is added/removed
  1103. to the bonding interface. Delete this station address
  1104. from the linked list */
  1105. vxge_mac_list_del(vpath, &mac_info_old);
  1106. /* Add this new address to the linked list
  1107. for later restoring */
  1108. vxge_mac_list_add(vpath, &mac_info_new);
  1109. continue;
  1110. }
  1111. /* Delete the station address */
  1112. mac_info_old.vpath_no = vpath_idx;
  1113. status = vxge_del_mac_addr(vdev, &mac_info_old);
  1114. }
  1115. if (unlikely(!is_vxge_card_up(vdev))) {
  1116. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  1117. return VXGE_HW_OK;
  1118. }
  1119. /* Set this mac address to all the vpaths */
  1120. for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
  1121. mac_info_new.vpath_no = vpath_idx;
  1122. mac_info_new.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
  1123. status = vxge_add_mac_addr(vdev, &mac_info_new);
  1124. if (status != VXGE_HW_OK)
  1125. return -EINVAL;
  1126. }
  1127. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  1128. return status;
  1129. }
  1130. /*
  1131. * vxge_vpath_intr_enable
  1132. * @vdev: pointer to vdev
  1133. * @vp_id: vpath for which to enable the interrupts
  1134. *
  1135. * Enables the interrupts for the vpath
  1136. */
  1137. static void vxge_vpath_intr_enable(struct vxgedev *vdev, int vp_id)
  1138. {
  1139. struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
  1140. int msix_id = 0;
  1141. int tim_msix_id[4] = {0, 1, 0, 0};
  1142. int alarm_msix_id = VXGE_ALARM_MSIX_ID;
  1143. vxge_hw_vpath_intr_enable(vpath->handle);
  1144. if (vdev->config.intr_type == INTA)
  1145. vxge_hw_vpath_inta_unmask_tx_rx(vpath->handle);
  1146. else {
  1147. vxge_hw_vpath_msix_set(vpath->handle, tim_msix_id,
  1148. alarm_msix_id);
  1149. msix_id = vpath->device_id * VXGE_HW_VPATH_MSIX_ACTIVE;
  1150. vxge_hw_vpath_msix_unmask(vpath->handle, msix_id);
  1151. vxge_hw_vpath_msix_unmask(vpath->handle, msix_id + 1);
  1152. /* enable the alarm vector */
  1153. msix_id = (vpath->handle->vpath->hldev->first_vp_id *
  1154. VXGE_HW_VPATH_MSIX_ACTIVE) + alarm_msix_id;
  1155. vxge_hw_vpath_msix_unmask(vpath->handle, msix_id);
  1156. }
  1157. }
  1158. /*
  1159. * vxge_vpath_intr_disable
  1160. * @vdev: pointer to vdev
  1161. * @vp_id: vpath for which to disable the interrupts
  1162. *
  1163. * Disables the interrupts for the vpath
  1164. */
  1165. static void vxge_vpath_intr_disable(struct vxgedev *vdev, int vp_id)
  1166. {
  1167. struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
  1168. struct __vxge_hw_device *hldev;
  1169. int msix_id;
  1170. hldev = pci_get_drvdata(vdev->pdev);
  1171. vxge_hw_vpath_wait_receive_idle(hldev, vpath->device_id);
  1172. vxge_hw_vpath_intr_disable(vpath->handle);
  1173. if (vdev->config.intr_type == INTA)
  1174. vxge_hw_vpath_inta_mask_tx_rx(vpath->handle);
  1175. else {
  1176. msix_id = vpath->device_id * VXGE_HW_VPATH_MSIX_ACTIVE;
  1177. vxge_hw_vpath_msix_mask(vpath->handle, msix_id);
  1178. vxge_hw_vpath_msix_mask(vpath->handle, msix_id + 1);
  1179. /* disable the alarm vector */
  1180. msix_id = (vpath->handle->vpath->hldev->first_vp_id *
  1181. VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
  1182. vxge_hw_vpath_msix_mask(vpath->handle, msix_id);
  1183. }
  1184. }
  1185. /* list all mac addresses from DA table */
  1186. static enum vxge_hw_status
  1187. vxge_search_mac_addr_in_da_table(struct vxge_vpath *vpath, struct macInfo *mac)
  1188. {
  1189. enum vxge_hw_status status = VXGE_HW_OK;
  1190. unsigned char macmask[ETH_ALEN];
  1191. unsigned char macaddr[ETH_ALEN];
  1192. status = vxge_hw_vpath_mac_addr_get(vpath->handle,
  1193. macaddr, macmask);
  1194. if (status != VXGE_HW_OK) {
  1195. vxge_debug_init(VXGE_ERR,
  1196. "DA config list entry failed for vpath:%d",
  1197. vpath->device_id);
  1198. return status;
  1199. }
  1200. while (memcmp(mac->macaddr, macaddr, ETH_ALEN)) {
  1201. status = vxge_hw_vpath_mac_addr_get_next(vpath->handle,
  1202. macaddr, macmask);
  1203. if (status != VXGE_HW_OK)
  1204. break;
  1205. }
  1206. return status;
  1207. }
  1208. /* Store all mac addresses from the list to the DA table */
  1209. static enum vxge_hw_status vxge_restore_vpath_mac_addr(struct vxge_vpath *vpath)
  1210. {
  1211. enum vxge_hw_status status = VXGE_HW_OK;
  1212. struct macInfo mac_info;
  1213. u8 *mac_address = NULL;
  1214. struct list_head *entry, *next;
  1215. memset(&mac_info, 0, sizeof(struct macInfo));
  1216. if (vpath->is_open) {
  1217. list_for_each_safe(entry, next, &vpath->mac_addr_list) {
  1218. mac_address =
  1219. (u8 *)&
  1220. ((struct vxge_mac_addrs *)entry)->macaddr;
  1221. memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
  1222. ((struct vxge_mac_addrs *)entry)->state =
  1223. VXGE_LL_MAC_ADDR_IN_DA_TABLE;
  1224. /* does this mac address already exist in da table? */
  1225. status = vxge_search_mac_addr_in_da_table(vpath,
  1226. &mac_info);
  1227. if (status != VXGE_HW_OK) {
  1228. /* Add this mac address to the DA table */
  1229. status = vxge_hw_vpath_mac_addr_add(
  1230. vpath->handle, mac_info.macaddr,
  1231. mac_info.macmask,
  1232. VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE);
  1233. if (status != VXGE_HW_OK) {
  1234. vxge_debug_init(VXGE_ERR,
  1235. "DA add entry failed for vpath:%d",
  1236. vpath->device_id);
  1237. ((struct vxge_mac_addrs *)entry)->state
  1238. = VXGE_LL_MAC_ADDR_IN_LIST;
  1239. }
  1240. }
  1241. }
  1242. }
  1243. return status;
  1244. }
  1245. /* Store all vlan ids from the list to the vid table */
  1246. static enum vxge_hw_status
  1247. vxge_restore_vpath_vid_table(struct vxge_vpath *vpath)
  1248. {
  1249. enum vxge_hw_status status = VXGE_HW_OK;
  1250. struct vxgedev *vdev = vpath->vdev;
  1251. u16 vid;
  1252. if (!vpath->is_open)
  1253. return status;
  1254. for_each_set_bit(vid, vdev->active_vlans, VLAN_N_VID)
  1255. status = vxge_hw_vpath_vid_add(vpath->handle, vid);
  1256. return status;
  1257. }
  1258. /*
  1259. * vxge_reset_vpath
  1260. * @vdev: pointer to vdev
  1261. * @vp_id: vpath to reset
  1262. *
  1263. * Resets the vpath
  1264. */
  1265. static int vxge_reset_vpath(struct vxgedev *vdev, int vp_id)
  1266. {
  1267. enum vxge_hw_status status = VXGE_HW_OK;
  1268. struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
  1269. int ret = 0;
  1270. /* check if device is down already */
  1271. if (unlikely(!is_vxge_card_up(vdev)))
  1272. return 0;
  1273. /* is device reset already scheduled */
  1274. if (test_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
  1275. return 0;
  1276. if (vpath->handle) {
  1277. if (vxge_hw_vpath_reset(vpath->handle) == VXGE_HW_OK) {
  1278. if (is_vxge_card_up(vdev) &&
  1279. vxge_hw_vpath_recover_from_reset(vpath->handle)
  1280. != VXGE_HW_OK) {
  1281. vxge_debug_init(VXGE_ERR,
  1282. "vxge_hw_vpath_recover_from_reset"
  1283. "failed for vpath:%d", vp_id);
  1284. return status;
  1285. }
  1286. } else {
  1287. vxge_debug_init(VXGE_ERR,
  1288. "vxge_hw_vpath_reset failed for"
  1289. "vpath:%d", vp_id);
  1290. return status;
  1291. }
  1292. } else
  1293. return VXGE_HW_FAIL;
  1294. vxge_restore_vpath_mac_addr(vpath);
  1295. vxge_restore_vpath_vid_table(vpath);
  1296. /* Enable all broadcast */
  1297. vxge_hw_vpath_bcast_enable(vpath->handle);
  1298. /* Enable all multicast */
  1299. if (vdev->all_multi_flg) {
  1300. status = vxge_hw_vpath_mcast_enable(vpath->handle);
  1301. if (status != VXGE_HW_OK)
  1302. vxge_debug_init(VXGE_ERR,
  1303. "%s:%d Enabling multicast failed",
  1304. __func__, __LINE__);
  1305. }
  1306. /* Enable the interrupts */
  1307. vxge_vpath_intr_enable(vdev, vp_id);
  1308. smp_wmb();
  1309. /* Enable the flow of traffic through the vpath */
  1310. vxge_hw_vpath_enable(vpath->handle);
  1311. smp_wmb();
  1312. vxge_hw_vpath_rx_doorbell_init(vpath->handle);
  1313. vpath->ring.last_status = VXGE_HW_OK;
  1314. /* Vpath reset done */
  1315. clear_bit(vp_id, &vdev->vp_reset);
  1316. /* Start the vpath queue */
  1317. if (netif_tx_queue_stopped(vpath->fifo.txq))
  1318. netif_tx_wake_queue(vpath->fifo.txq);
  1319. return ret;
  1320. }
  1321. /* Configure CI */
  1322. static void vxge_config_ci_for_tti_rti(struct vxgedev *vdev)
  1323. {
  1324. int i = 0;
  1325. /* Enable CI for RTI */
  1326. if (vdev->config.intr_type == MSI_X) {
  1327. for (i = 0; i < vdev->no_of_vpath; i++) {
  1328. struct __vxge_hw_ring *hw_ring;
  1329. hw_ring = vdev->vpaths[i].ring.handle;
  1330. vxge_hw_vpath_dynamic_rti_ci_set(hw_ring);
  1331. }
  1332. }
  1333. /* Enable CI for TTI */
  1334. for (i = 0; i < vdev->no_of_vpath; i++) {
  1335. struct __vxge_hw_fifo *hw_fifo = vdev->vpaths[i].fifo.handle;
  1336. vxge_hw_vpath_tti_ci_set(hw_fifo);
  1337. /*
  1338. * For Inta (with or without napi), Set CI ON for only one
  1339. * vpath. (Have only one free running timer).
  1340. */
  1341. if ((vdev->config.intr_type == INTA) && (i == 0))
  1342. break;
  1343. }
  1344. return;
  1345. }
  1346. static int do_vxge_reset(struct vxgedev *vdev, int event)
  1347. {
  1348. enum vxge_hw_status status;
  1349. int ret = 0, vp_id, i;
  1350. vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
  1351. if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_START_RESET)) {
  1352. /* check if device is down already */
  1353. if (unlikely(!is_vxge_card_up(vdev)))
  1354. return 0;
  1355. /* is reset already scheduled */
  1356. if (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
  1357. return 0;
  1358. }
  1359. if (event == VXGE_LL_FULL_RESET) {
  1360. netif_carrier_off(vdev->ndev);
  1361. /* wait for all the vpath reset to complete */
  1362. for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
  1363. while (test_bit(vp_id, &vdev->vp_reset))
  1364. msleep(50);
  1365. }
  1366. netif_carrier_on(vdev->ndev);
  1367. /* if execution mode is set to debug, don't reset the adapter */
  1368. if (unlikely(vdev->exec_mode)) {
  1369. vxge_debug_init(VXGE_ERR,
  1370. "%s: execution mode is debug, returning..",
  1371. vdev->ndev->name);
  1372. clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
  1373. netif_tx_stop_all_queues(vdev->ndev);
  1374. return 0;
  1375. }
  1376. }
  1377. if (event == VXGE_LL_FULL_RESET) {
  1378. vxge_hw_device_wait_receive_idle(vdev->devh);
  1379. vxge_hw_device_intr_disable(vdev->devh);
  1380. switch (vdev->cric_err_event) {
  1381. case VXGE_HW_EVENT_UNKNOWN:
  1382. netif_tx_stop_all_queues(vdev->ndev);
  1383. vxge_debug_init(VXGE_ERR,
  1384. "fatal: %s: Disabling device due to"
  1385. "unknown error",
  1386. vdev->ndev->name);
  1387. ret = -EPERM;
  1388. goto out;
  1389. case VXGE_HW_EVENT_RESET_START:
  1390. break;
  1391. case VXGE_HW_EVENT_RESET_COMPLETE:
  1392. case VXGE_HW_EVENT_LINK_DOWN:
  1393. case VXGE_HW_EVENT_LINK_UP:
  1394. case VXGE_HW_EVENT_ALARM_CLEARED:
  1395. case VXGE_HW_EVENT_ECCERR:
  1396. case VXGE_HW_EVENT_MRPCIM_ECCERR:
  1397. ret = -EPERM;
  1398. goto out;
  1399. case VXGE_HW_EVENT_FIFO_ERR:
  1400. case VXGE_HW_EVENT_VPATH_ERR:
  1401. break;
  1402. case VXGE_HW_EVENT_CRITICAL_ERR:
  1403. netif_tx_stop_all_queues(vdev->ndev);
  1404. vxge_debug_init(VXGE_ERR,
  1405. "fatal: %s: Disabling device due to"
  1406. "serious error",
  1407. vdev->ndev->name);
  1408. /* SOP or device reset required */
  1409. /* This event is not currently used */
  1410. ret = -EPERM;
  1411. goto out;
  1412. case VXGE_HW_EVENT_SERR:
  1413. netif_tx_stop_all_queues(vdev->ndev);
  1414. vxge_debug_init(VXGE_ERR,
  1415. "fatal: %s: Disabling device due to"
  1416. "serious error",
  1417. vdev->ndev->name);
  1418. ret = -EPERM;
  1419. goto out;
  1420. case VXGE_HW_EVENT_SRPCIM_SERR:
  1421. case VXGE_HW_EVENT_MRPCIM_SERR:
  1422. ret = -EPERM;
  1423. goto out;
  1424. case VXGE_HW_EVENT_SLOT_FREEZE:
  1425. netif_tx_stop_all_queues(vdev->ndev);
  1426. vxge_debug_init(VXGE_ERR,
  1427. "fatal: %s: Disabling device due to"
  1428. "slot freeze",
  1429. vdev->ndev->name);
  1430. ret = -EPERM;
  1431. goto out;
  1432. default:
  1433. break;
  1434. }
  1435. }
  1436. if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_START_RESET))
  1437. netif_tx_stop_all_queues(vdev->ndev);
  1438. if (event == VXGE_LL_FULL_RESET) {
  1439. status = vxge_reset_all_vpaths(vdev);
  1440. if (status != VXGE_HW_OK) {
  1441. vxge_debug_init(VXGE_ERR,
  1442. "fatal: %s: can not reset vpaths",
  1443. vdev->ndev->name);
  1444. ret = -EPERM;
  1445. goto out;
  1446. }
  1447. }
  1448. if (event == VXGE_LL_COMPL_RESET) {
  1449. for (i = 0; i < vdev->no_of_vpath; i++)
  1450. if (vdev->vpaths[i].handle) {
  1451. if (vxge_hw_vpath_recover_from_reset(
  1452. vdev->vpaths[i].handle)
  1453. != VXGE_HW_OK) {
  1454. vxge_debug_init(VXGE_ERR,
  1455. "vxge_hw_vpath_recover_"
  1456. "from_reset failed for vpath: "
  1457. "%d", i);
  1458. ret = -EPERM;
  1459. goto out;
  1460. }
  1461. } else {
  1462. vxge_debug_init(VXGE_ERR,
  1463. "vxge_hw_vpath_reset failed for "
  1464. "vpath:%d", i);
  1465. ret = -EPERM;
  1466. goto out;
  1467. }
  1468. }
  1469. if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_COMPL_RESET)) {
  1470. /* Reprogram the DA table with populated mac addresses */
  1471. for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
  1472. vxge_restore_vpath_mac_addr(&vdev->vpaths[vp_id]);
  1473. vxge_restore_vpath_vid_table(&vdev->vpaths[vp_id]);
  1474. }
  1475. /* enable vpath interrupts */
  1476. for (i = 0; i < vdev->no_of_vpath; i++)
  1477. vxge_vpath_intr_enable(vdev, i);
  1478. vxge_hw_device_intr_enable(vdev->devh);
  1479. smp_wmb();
  1480. /* Indicate card up */
  1481. set_bit(__VXGE_STATE_CARD_UP, &vdev->state);
  1482. /* Get the traffic to flow through the vpaths */
  1483. for (i = 0; i < vdev->no_of_vpath; i++) {
  1484. vxge_hw_vpath_enable(vdev->vpaths[i].handle);
  1485. smp_wmb();
  1486. vxge_hw_vpath_rx_doorbell_init(vdev->vpaths[i].handle);
  1487. }
  1488. netif_tx_wake_all_queues(vdev->ndev);
  1489. }
  1490. /* configure CI */
  1491. vxge_config_ci_for_tti_rti(vdev);
  1492. out:
  1493. vxge_debug_entryexit(VXGE_TRACE,
  1494. "%s:%d Exiting...", __func__, __LINE__);
  1495. /* Indicate reset done */
  1496. if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_COMPL_RESET))
  1497. clear_bit(__VXGE_STATE_RESET_CARD, &vdev->state);
  1498. return ret;
  1499. }
  1500. /*
  1501. * vxge_reset
  1502. * @vdev: pointer to ll device
  1503. *
  1504. * driver may reset the chip on events of serr, eccerr, etc
  1505. */
  1506. static void vxge_reset(struct work_struct *work)
  1507. {
  1508. struct vxgedev *vdev = container_of(work, struct vxgedev, reset_task);
  1509. if (!netif_running(vdev->ndev))
  1510. return;
  1511. do_vxge_reset(vdev, VXGE_LL_FULL_RESET);
  1512. }
  1513. /**
  1514. * vxge_poll - Receive handler when Receive Polling is used.
  1515. * @dev: pointer to the device structure.
  1516. * @budget: Number of packets budgeted to be processed in this iteration.
  1517. *
  1518. * This function comes into picture only if Receive side is being handled
  1519. * through polling (called NAPI in linux). It mostly does what the normal
  1520. * Rx interrupt handler does in terms of descriptor and packet processing
  1521. * but not in an interrupt context. Also it will process a specified number
  1522. * of packets at most in one iteration. This value is passed down by the
  1523. * kernel as the function argument 'budget'.
  1524. */
  1525. static int vxge_poll_msix(struct napi_struct *napi, int budget)
  1526. {
  1527. struct vxge_ring *ring = container_of(napi, struct vxge_ring, napi);
  1528. int pkts_processed;
  1529. int budget_org = budget;
  1530. ring->budget = budget;
  1531. ring->pkts_processed = 0;
  1532. vxge_hw_vpath_poll_rx(ring->handle);
  1533. pkts_processed = ring->pkts_processed;
  1534. if (ring->pkts_processed < budget_org) {
  1535. napi_complete(napi);
  1536. /* Re enable the Rx interrupts for the vpath */
  1537. vxge_hw_channel_msix_unmask(
  1538. (struct __vxge_hw_channel *)ring->handle,
  1539. ring->rx_vector_no);
  1540. mmiowb();
  1541. }
  1542. /* We are copying and returning the local variable, in case if after
  1543. * clearing the msix interrupt above, if the interrupt fires right
  1544. * away which can preempt this NAPI thread */
  1545. return pkts_processed;
  1546. }
  1547. static int vxge_poll_inta(struct napi_struct *napi, int budget)
  1548. {
  1549. struct vxgedev *vdev = container_of(napi, struct vxgedev, napi);
  1550. int pkts_processed = 0;
  1551. int i;
  1552. int budget_org = budget;
  1553. struct vxge_ring *ring;
  1554. struct __vxge_hw_device *hldev = pci_get_drvdata(vdev->pdev);
  1555. for (i = 0; i < vdev->no_of_vpath; i++) {
  1556. ring = &vdev->vpaths[i].ring;
  1557. ring->budget = budget;
  1558. ring->pkts_processed = 0;
  1559. vxge_hw_vpath_poll_rx(ring->handle);
  1560. pkts_processed += ring->pkts_processed;
  1561. budget -= ring->pkts_processed;
  1562. if (budget <= 0)
  1563. break;
  1564. }
  1565. VXGE_COMPLETE_ALL_TX(vdev);
  1566. if (pkts_processed < budget_org) {
  1567. napi_complete(napi);
  1568. /* Re enable the Rx interrupts for the ring */
  1569. vxge_hw_device_unmask_all(hldev);
  1570. vxge_hw_device_flush_io(hldev);
  1571. }
  1572. return pkts_processed;
  1573. }
  1574. #ifdef CONFIG_NET_POLL_CONTROLLER
  1575. /**
  1576. * vxge_netpoll - netpoll event handler entry point
  1577. * @dev : pointer to the device structure.
  1578. * Description:
  1579. * This function will be called by upper layer to check for events on the
  1580. * interface in situations where interrupts are disabled. It is used for
  1581. * specific in-kernel networking tasks, such as remote consoles and kernel
  1582. * debugging over the network (example netdump in RedHat).
  1583. */
  1584. static void vxge_netpoll(struct net_device *dev)
  1585. {
  1586. struct __vxge_hw_device *hldev;
  1587. struct vxgedev *vdev;
  1588. vdev = netdev_priv(dev);
  1589. hldev = pci_get_drvdata(vdev->pdev);
  1590. vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
  1591. if (pci_channel_offline(vdev->pdev))
  1592. return;
  1593. disable_irq(dev->irq);
  1594. vxge_hw_device_clear_tx_rx(hldev);
  1595. vxge_hw_device_clear_tx_rx(hldev);
  1596. VXGE_COMPLETE_ALL_RX(vdev);
  1597. VXGE_COMPLETE_ALL_TX(vdev);
  1598. enable_irq(dev->irq);
  1599. vxge_debug_entryexit(VXGE_TRACE,
  1600. "%s:%d Exiting...", __func__, __LINE__);
  1601. }
  1602. #endif
  1603. /* RTH configuration */
  1604. static enum vxge_hw_status vxge_rth_configure(struct vxgedev *vdev)
  1605. {
  1606. enum vxge_hw_status status = VXGE_HW_OK;
  1607. struct vxge_hw_rth_hash_types hash_types;
  1608. u8 itable[256] = {0}; /* indirection table */
  1609. u8 mtable[256] = {0}; /* CPU to vpath mapping */
  1610. int index;
  1611. /*
  1612. * Filling
  1613. * - itable with bucket numbers
  1614. * - mtable with bucket-to-vpath mapping
  1615. */
  1616. for (index = 0; index < (1 << vdev->config.rth_bkt_sz); index++) {
  1617. itable[index] = index;
  1618. mtable[index] = index % vdev->no_of_vpath;
  1619. }
  1620. /* set indirection table, bucket-to-vpath mapping */
  1621. status = vxge_hw_vpath_rts_rth_itable_set(vdev->vp_handles,
  1622. vdev->no_of_vpath,
  1623. mtable, itable,
  1624. vdev->config.rth_bkt_sz);
  1625. if (status != VXGE_HW_OK) {
  1626. vxge_debug_init(VXGE_ERR,
  1627. "RTH indirection table configuration failed "
  1628. "for vpath:%d", vdev->vpaths[0].device_id);
  1629. return status;
  1630. }
  1631. /* Fill RTH hash types */
  1632. hash_types.hash_type_tcpipv4_en = vdev->config.rth_hash_type_tcpipv4;
  1633. hash_types.hash_type_ipv4_en = vdev->config.rth_hash_type_ipv4;
  1634. hash_types.hash_type_tcpipv6_en = vdev->config.rth_hash_type_tcpipv6;
  1635. hash_types.hash_type_ipv6_en = vdev->config.rth_hash_type_ipv6;
  1636. hash_types.hash_type_tcpipv6ex_en =
  1637. vdev->config.rth_hash_type_tcpipv6ex;
  1638. hash_types.hash_type_ipv6ex_en = vdev->config.rth_hash_type_ipv6ex;
  1639. /*
  1640. * Because the itable_set() method uses the active_table field
  1641. * for the target virtual path the RTH config should be updated
  1642. * for all VPATHs. The h/w only uses the lowest numbered VPATH
  1643. * when steering frames.
  1644. */
  1645. for (index = 0; index < vdev->no_of_vpath; index++) {
  1646. status = vxge_hw_vpath_rts_rth_set(
  1647. vdev->vpaths[index].handle,
  1648. vdev->config.rth_algorithm,
  1649. &hash_types,
  1650. vdev->config.rth_bkt_sz);
  1651. if (status != VXGE_HW_OK) {
  1652. vxge_debug_init(VXGE_ERR,
  1653. "RTH configuration failed for vpath:%d",
  1654. vdev->vpaths[index].device_id);
  1655. return status;
  1656. }
  1657. }
  1658. return status;
  1659. }
  1660. /* reset vpaths */
  1661. enum vxge_hw_status vxge_reset_all_vpaths(struct vxgedev *vdev)
  1662. {
  1663. enum vxge_hw_status status = VXGE_HW_OK;
  1664. struct vxge_vpath *vpath;
  1665. int i;
  1666. for (i = 0; i < vdev->no_of_vpath; i++) {
  1667. vpath = &vdev->vpaths[i];
  1668. if (vpath->handle) {
  1669. if (vxge_hw_vpath_reset(vpath->handle) == VXGE_HW_OK) {
  1670. if (is_vxge_card_up(vdev) &&
  1671. vxge_hw_vpath_recover_from_reset(
  1672. vpath->handle) != VXGE_HW_OK) {
  1673. vxge_debug_init(VXGE_ERR,
  1674. "vxge_hw_vpath_recover_"
  1675. "from_reset failed for vpath: "
  1676. "%d", i);
  1677. return status;
  1678. }
  1679. } else {
  1680. vxge_debug_init(VXGE_ERR,
  1681. "vxge_hw_vpath_reset failed for "
  1682. "vpath:%d", i);
  1683. return status;
  1684. }
  1685. }
  1686. }
  1687. return status;
  1688. }
  1689. /* close vpaths */
  1690. static void vxge_close_vpaths(struct vxgedev *vdev, int index)
  1691. {
  1692. struct vxge_vpath *vpath;
  1693. int i;
  1694. for (i = index; i < vdev->no_of_vpath; i++) {
  1695. vpath = &vdev->vpaths[i];
  1696. if (vpath->handle && vpath->is_open) {
  1697. vxge_hw_vpath_close(vpath->handle);
  1698. vdev->stats.vpaths_open--;
  1699. }
  1700. vpath->is_open = 0;
  1701. vpath->handle = NULL;
  1702. }
  1703. }
  1704. /* open vpaths */
  1705. static int vxge_open_vpaths(struct vxgedev *vdev)
  1706. {
  1707. struct vxge_hw_vpath_attr attr;
  1708. enum vxge_hw_status status;
  1709. struct vxge_vpath *vpath;
  1710. u32 vp_id = 0;
  1711. int i;
  1712. for (i = 0; i < vdev->no_of_vpath; i++) {
  1713. vpath = &vdev->vpaths[i];
  1714. vxge_assert(vpath->is_configured);
  1715. if (!vdev->titan1) {
  1716. struct vxge_hw_vp_config *vcfg;
  1717. vcfg = &vdev->devh->config.vp_config[vpath->device_id];
  1718. vcfg->rti.urange_a = RTI_T1A_RX_URANGE_A;
  1719. vcfg->rti.urange_b = RTI_T1A_RX_URANGE_B;
  1720. vcfg->rti.urange_c = RTI_T1A_RX_URANGE_C;
  1721. vcfg->tti.uec_a = TTI_T1A_TX_UFC_A;
  1722. vcfg->tti.uec_b = TTI_T1A_TX_UFC_B;
  1723. vcfg->tti.uec_c = TTI_T1A_TX_UFC_C(vdev->mtu);
  1724. vcfg->tti.uec_d = TTI_T1A_TX_UFC_D(vdev->mtu);
  1725. vcfg->tti.ltimer_val = VXGE_T1A_TTI_LTIMER_VAL;
  1726. vcfg->tti.rtimer_val = VXGE_T1A_TTI_RTIMER_VAL;
  1727. }
  1728. attr.vp_id = vpath->device_id;
  1729. attr.fifo_attr.callback = vxge_xmit_compl;
  1730. attr.fifo_attr.txdl_term = vxge_tx_term;
  1731. attr.fifo_attr.per_txdl_space = sizeof(struct vxge_tx_priv);
  1732. attr.fifo_attr.userdata = &vpath->fifo;
  1733. attr.ring_attr.callback = vxge_rx_1b_compl;
  1734. attr.ring_attr.rxd_init = vxge_rx_initial_replenish;
  1735. attr.ring_attr.rxd_term = vxge_rx_term;
  1736. attr.ring_attr.per_rxd_space = sizeof(struct vxge_rx_priv);
  1737. attr.ring_attr.userdata = &vpath->ring;
  1738. vpath->ring.ndev = vdev->ndev;
  1739. vpath->ring.pdev = vdev->pdev;
  1740. status = vxge_hw_vpath_open(vdev->devh, &attr, &vpath->handle);
  1741. if (status == VXGE_HW_OK) {
  1742. vpath->fifo.handle =
  1743. (struct __vxge_hw_fifo *)attr.fifo_attr.userdata;
  1744. vpath->ring.handle =
  1745. (struct __vxge_hw_ring *)attr.ring_attr.userdata;
  1746. vpath->fifo.tx_steering_type =
  1747. vdev->config.tx_steering_type;
  1748. vpath->fifo.ndev = vdev->ndev;
  1749. vpath->fifo.pdev = vdev->pdev;
  1750. u64_stats_init(&vpath->fifo.stats.syncp);
  1751. u64_stats_init(&vpath->ring.stats.syncp);
  1752. if (vdev->config.tx_steering_type)
  1753. vpath->fifo.txq =
  1754. netdev_get_tx_queue(vdev->ndev, i);
  1755. else
  1756. vpath->fifo.txq =
  1757. netdev_get_tx_queue(vdev->ndev, 0);
  1758. vpath->fifo.indicate_max_pkts =
  1759. vdev->config.fifo_indicate_max_pkts;
  1760. vpath->fifo.tx_vector_no = 0;
  1761. vpath->ring.rx_vector_no = 0;
  1762. vpath->ring.rx_hwts = vdev->rx_hwts;
  1763. vpath->is_open = 1;
  1764. vdev->vp_handles[i] = vpath->handle;
  1765. vpath->ring.vlan_tag_strip = vdev->vlan_tag_strip;
  1766. vdev->stats.vpaths_open++;
  1767. } else {
  1768. vdev->stats.vpath_open_fail++;
  1769. vxge_debug_init(VXGE_ERR, "%s: vpath: %d failed to "
  1770. "open with status: %d",
  1771. vdev->ndev->name, vpath->device_id,
  1772. status);
  1773. vxge_close_vpaths(vdev, 0);
  1774. return -EPERM;
  1775. }
  1776. vp_id = vpath->handle->vpath->vp_id;
  1777. vdev->vpaths_deployed |= vxge_mBIT(vp_id);
  1778. }
  1779. return VXGE_HW_OK;
  1780. }
  1781. /**
  1782. * adaptive_coalesce_tx_interrupts - Changes the interrupt coalescing
  1783. * if the interrupts are not within a range
  1784. * @fifo: pointer to transmit fifo structure
  1785. * Description: The function changes boundary timer and restriction timer
  1786. * value depends on the traffic
  1787. * Return Value: None
  1788. */
  1789. static void adaptive_coalesce_tx_interrupts(struct vxge_fifo *fifo)
  1790. {
  1791. fifo->interrupt_count++;
  1792. if (jiffies > fifo->jiffies + HZ / 100) {
  1793. struct __vxge_hw_fifo *hw_fifo = fifo->handle;
  1794. fifo->jiffies = jiffies;
  1795. if (fifo->interrupt_count > VXGE_T1A_MAX_TX_INTERRUPT_COUNT &&
  1796. hw_fifo->rtimer != VXGE_TTI_RTIMER_ADAPT_VAL) {
  1797. hw_fifo->rtimer = VXGE_TTI_RTIMER_ADAPT_VAL;
  1798. vxge_hw_vpath_dynamic_tti_rtimer_set(hw_fifo);
  1799. } else if (hw_fifo->rtimer != 0) {
  1800. hw_fifo->rtimer = 0;
  1801. vxge_hw_vpath_dynamic_tti_rtimer_set(hw_fifo);
  1802. }
  1803. fifo->interrupt_count = 0;
  1804. }
  1805. }
  1806. /**
  1807. * adaptive_coalesce_rx_interrupts - Changes the interrupt coalescing
  1808. * if the interrupts are not within a range
  1809. * @ring: pointer to receive ring structure
  1810. * Description: The function increases of decreases the packet counts within
  1811. * the ranges of traffic utilization, if the interrupts due to this ring are
  1812. * not within a fixed range.
  1813. * Return Value: Nothing
  1814. */
  1815. static void adaptive_coalesce_rx_interrupts(struct vxge_ring *ring)
  1816. {
  1817. ring->interrupt_count++;
  1818. if (jiffies > ring->jiffies + HZ / 100) {
  1819. struct __vxge_hw_ring *hw_ring = ring->handle;
  1820. ring->jiffies = jiffies;
  1821. if (ring->interrupt_count > VXGE_T1A_MAX_INTERRUPT_COUNT &&
  1822. hw_ring->rtimer != VXGE_RTI_RTIMER_ADAPT_VAL) {
  1823. hw_ring->rtimer = VXGE_RTI_RTIMER_ADAPT_VAL;
  1824. vxge_hw_vpath_dynamic_rti_rtimer_set(hw_ring);
  1825. } else if (hw_ring->rtimer != 0) {
  1826. hw_ring->rtimer = 0;
  1827. vxge_hw_vpath_dynamic_rti_rtimer_set(hw_ring);
  1828. }
  1829. ring->interrupt_count = 0;
  1830. }
  1831. }
  1832. /*
  1833. * vxge_isr_napi
  1834. * @irq: the irq of the device.
  1835. * @dev_id: a void pointer to the hldev structure of the Titan device
  1836. * @ptregs: pointer to the registers pushed on the stack.
  1837. *
  1838. * This function is the ISR handler of the device when napi is enabled. It
  1839. * identifies the reason for the interrupt and calls the relevant service
  1840. * routines.
  1841. */
  1842. static irqreturn_t vxge_isr_napi(int irq, void *dev_id)
  1843. {
  1844. struct net_device *dev;
  1845. struct __vxge_hw_device *hldev;
  1846. u64 reason;
  1847. enum vxge_hw_status status;
  1848. struct vxgedev *vdev = (struct vxgedev *)dev_id;
  1849. vxge_debug_intr(VXGE_TRACE, "%s:%d", __func__, __LINE__);
  1850. dev = vdev->ndev;
  1851. hldev = pci_get_drvdata(vdev->pdev);
  1852. if (pci_channel_offline(vdev->pdev))
  1853. return IRQ_NONE;
  1854. if (unlikely(!is_vxge_card_up(vdev)))
  1855. return IRQ_HANDLED;
  1856. status = vxge_hw_device_begin_irq(hldev, vdev->exec_mode, &reason);
  1857. if (status == VXGE_HW_OK) {
  1858. vxge_hw_device_mask_all(hldev);
  1859. if (reason &
  1860. VXGE_HW_TITAN_GENERAL_INT_STATUS_VPATH_TRAFFIC_INT(
  1861. vdev->vpaths_deployed >>
  1862. (64 - VXGE_HW_MAX_VIRTUAL_PATHS))) {
  1863. vxge_hw_device_clear_tx_rx(hldev);
  1864. napi_schedule(&vdev->napi);
  1865. vxge_debug_intr(VXGE_TRACE,
  1866. "%s:%d Exiting...", __func__, __LINE__);
  1867. return IRQ_HANDLED;
  1868. } else
  1869. vxge_hw_device_unmask_all(hldev);
  1870. } else if (unlikely((status == VXGE_HW_ERR_VPATH) ||
  1871. (status == VXGE_HW_ERR_CRITICAL) ||
  1872. (status == VXGE_HW_ERR_FIFO))) {
  1873. vxge_hw_device_mask_all(hldev);
  1874. vxge_hw_device_flush_io(hldev);
  1875. return IRQ_HANDLED;
  1876. } else if (unlikely(status == VXGE_HW_ERR_SLOT_FREEZE))
  1877. return IRQ_HANDLED;
  1878. vxge_debug_intr(VXGE_TRACE, "%s:%d Exiting...", __func__, __LINE__);
  1879. return IRQ_NONE;
  1880. }
  1881. #ifdef CONFIG_PCI_MSI
  1882. static irqreturn_t vxge_tx_msix_handle(int irq, void *dev_id)
  1883. {
  1884. struct vxge_fifo *fifo = (struct vxge_fifo *)dev_id;
  1885. adaptive_coalesce_tx_interrupts(fifo);
  1886. vxge_hw_channel_msix_mask((struct __vxge_hw_channel *)fifo->handle,
  1887. fifo->tx_vector_no);
  1888. vxge_hw_channel_msix_clear((struct __vxge_hw_channel *)fifo->handle,
  1889. fifo->tx_vector_no);
  1890. VXGE_COMPLETE_VPATH_TX(fifo);
  1891. vxge_hw_channel_msix_unmask((struct __vxge_hw_channel *)fifo->handle,
  1892. fifo->tx_vector_no);
  1893. mmiowb();
  1894. return IRQ_HANDLED;
  1895. }
  1896. static irqreturn_t vxge_rx_msix_napi_handle(int irq, void *dev_id)
  1897. {
  1898. struct vxge_ring *ring = (struct vxge_ring *)dev_id;
  1899. adaptive_coalesce_rx_interrupts(ring);
  1900. vxge_hw_channel_msix_mask((struct __vxge_hw_channel *)ring->handle,
  1901. ring->rx_vector_no);
  1902. vxge_hw_channel_msix_clear((struct __vxge_hw_channel *)ring->handle,
  1903. ring->rx_vector_no);
  1904. napi_schedule(&ring->napi);
  1905. return IRQ_HANDLED;
  1906. }
  1907. static irqreturn_t
  1908. vxge_alarm_msix_handle(int irq, void *dev_id)
  1909. {
  1910. int i;
  1911. enum vxge_hw_status status;
  1912. struct vxge_vpath *vpath = (struct vxge_vpath *)dev_id;
  1913. struct vxgedev *vdev = vpath->vdev;
  1914. int msix_id = (vpath->handle->vpath->vp_id *
  1915. VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
  1916. for (i = 0; i < vdev->no_of_vpath; i++) {
  1917. /* Reduce the chance of losing alarm interrupts by masking
  1918. * the vector. A pending bit will be set if an alarm is
  1919. * generated and on unmask the interrupt will be fired.
  1920. */
  1921. vxge_hw_vpath_msix_mask(vdev->vpaths[i].handle, msix_id);
  1922. vxge_hw_vpath_msix_clear(vdev->vpaths[i].handle, msix_id);
  1923. mmiowb();
  1924. status = vxge_hw_vpath_alarm_process(vdev->vpaths[i].handle,
  1925. vdev->exec_mode);
  1926. if (status == VXGE_HW_OK) {
  1927. vxge_hw_vpath_msix_unmask(vdev->vpaths[i].handle,
  1928. msix_id);
  1929. mmiowb();
  1930. continue;
  1931. }
  1932. vxge_debug_intr(VXGE_ERR,
  1933. "%s: vxge_hw_vpath_alarm_process failed %x ",
  1934. VXGE_DRIVER_NAME, status);
  1935. }
  1936. return IRQ_HANDLED;
  1937. }
  1938. static int vxge_alloc_msix(struct vxgedev *vdev)
  1939. {
  1940. int j, i, ret = 0;
  1941. int msix_intr_vect = 0, temp;
  1942. vdev->intr_cnt = 0;
  1943. start:
  1944. /* Tx/Rx MSIX Vectors count */
  1945. vdev->intr_cnt = vdev->no_of_vpath * 2;
  1946. /* Alarm MSIX Vectors count */
  1947. vdev->intr_cnt++;
  1948. vdev->entries = kcalloc(vdev->intr_cnt, sizeof(struct msix_entry),
  1949. GFP_KERNEL);
  1950. if (!vdev->entries) {
  1951. vxge_debug_init(VXGE_ERR,
  1952. "%s: memory allocation failed",
  1953. VXGE_DRIVER_NAME);
  1954. ret = -ENOMEM;
  1955. goto alloc_entries_failed;
  1956. }
  1957. vdev->vxge_entries = kcalloc(vdev->intr_cnt,
  1958. sizeof(struct vxge_msix_entry),
  1959. GFP_KERNEL);
  1960. if (!vdev->vxge_entries) {
  1961. vxge_debug_init(VXGE_ERR, "%s: memory allocation failed",
  1962. VXGE_DRIVER_NAME);
  1963. ret = -ENOMEM;
  1964. goto alloc_vxge_entries_failed;
  1965. }
  1966. for (i = 0, j = 0; i < vdev->no_of_vpath; i++) {
  1967. msix_intr_vect = i * VXGE_HW_VPATH_MSIX_ACTIVE;
  1968. /* Initialize the fifo vector */
  1969. vdev->entries[j].entry = msix_intr_vect;
  1970. vdev->vxge_entries[j].entry = msix_intr_vect;
  1971. vdev->vxge_entries[j].in_use = 0;
  1972. j++;
  1973. /* Initialize the ring vector */
  1974. vdev->entries[j].entry = msix_intr_vect + 1;
  1975. vdev->vxge_entries[j].entry = msix_intr_vect + 1;
  1976. vdev->vxge_entries[j].in_use = 0;
  1977. j++;
  1978. }
  1979. /* Initialize the alarm vector */
  1980. vdev->entries[j].entry = VXGE_ALARM_MSIX_ID;
  1981. vdev->vxge_entries[j].entry = VXGE_ALARM_MSIX_ID;
  1982. vdev->vxge_entries[j].in_use = 0;
  1983. ret = pci_enable_msix(vdev->pdev, vdev->entries, vdev->intr_cnt);
  1984. if (ret > 0) {
  1985. vxge_debug_init(VXGE_ERR,
  1986. "%s: MSI-X enable failed for %d vectors, ret: %d",
  1987. VXGE_DRIVER_NAME, vdev->intr_cnt, ret);
  1988. if ((max_config_vpath != VXGE_USE_DEFAULT) || (ret < 3)) {
  1989. ret = -ENODEV;
  1990. goto enable_msix_failed;
  1991. }
  1992. kfree(vdev->entries);
  1993. kfree(vdev->vxge_entries);
  1994. vdev->entries = NULL;
  1995. vdev->vxge_entries = NULL;
  1996. /* Try with less no of vector by reducing no of vpaths count */
  1997. temp = (ret - 1)/2;
  1998. vxge_close_vpaths(vdev, temp);
  1999. vdev->no_of_vpath = temp;
  2000. goto start;
  2001. } else if (ret < 0) {
  2002. ret = -ENODEV;
  2003. goto enable_msix_failed;
  2004. }
  2005. return 0;
  2006. enable_msix_failed:
  2007. kfree(vdev->vxge_entries);
  2008. alloc_vxge_entries_failed:
  2009. kfree(vdev->entries);
  2010. alloc_entries_failed:
  2011. return ret;
  2012. }
  2013. static int vxge_enable_msix(struct vxgedev *vdev)
  2014. {
  2015. int i, ret = 0;
  2016. /* 0 - Tx, 1 - Rx */
  2017. int tim_msix_id[4] = {0, 1, 0, 0};
  2018. vdev->intr_cnt = 0;
  2019. /* allocate msix vectors */
  2020. ret = vxge_alloc_msix(vdev);
  2021. if (!ret) {
  2022. for (i = 0; i < vdev->no_of_vpath; i++) {
  2023. struct vxge_vpath *vpath = &vdev->vpaths[i];
  2024. /* If fifo or ring are not enabled, the MSIX vector for
  2025. * it should be set to 0.
  2026. */
  2027. vpath->ring.rx_vector_no = (vpath->device_id *
  2028. VXGE_HW_VPATH_MSIX_ACTIVE) + 1;
  2029. vpath->fifo.tx_vector_no = (vpath->device_id *
  2030. VXGE_HW_VPATH_MSIX_ACTIVE);
  2031. vxge_hw_vpath_msix_set(vpath->handle, tim_msix_id,
  2032. VXGE_ALARM_MSIX_ID);
  2033. }
  2034. }
  2035. return ret;
  2036. }
  2037. static void vxge_rem_msix_isr(struct vxgedev *vdev)
  2038. {
  2039. int intr_cnt;
  2040. for (intr_cnt = 0; intr_cnt < (vdev->no_of_vpath * 2 + 1);
  2041. intr_cnt++) {
  2042. if (vdev->vxge_entries[intr_cnt].in_use) {
  2043. synchronize_irq(vdev->entries[intr_cnt].vector);
  2044. free_irq(vdev->entries[intr_cnt].vector,
  2045. vdev->vxge_entries[intr_cnt].arg);
  2046. vdev->vxge_entries[intr_cnt].in_use = 0;
  2047. }
  2048. }
  2049. kfree(vdev->entries);
  2050. kfree(vdev->vxge_entries);
  2051. vdev->entries = NULL;
  2052. vdev->vxge_entries = NULL;
  2053. if (vdev->config.intr_type == MSI_X)
  2054. pci_disable_msix(vdev->pdev);
  2055. }
  2056. #endif
  2057. static void vxge_rem_isr(struct vxgedev *vdev)
  2058. {
  2059. struct __vxge_hw_device *hldev;
  2060. hldev = pci_get_drvdata(vdev->pdev);
  2061. #ifdef CONFIG_PCI_MSI
  2062. if (vdev->config.intr_type == MSI_X) {
  2063. vxge_rem_msix_isr(vdev);
  2064. } else
  2065. #endif
  2066. if (vdev->config.intr_type == INTA) {
  2067. synchronize_irq(vdev->pdev->irq);
  2068. free_irq(vdev->pdev->irq, vdev);
  2069. }
  2070. }
  2071. static int vxge_add_isr(struct vxgedev *vdev)
  2072. {
  2073. int ret = 0;
  2074. #ifdef CONFIG_PCI_MSI
  2075. int vp_idx = 0, intr_idx = 0, intr_cnt = 0, msix_idx = 0, irq_req = 0;
  2076. int pci_fun = PCI_FUNC(vdev->pdev->devfn);
  2077. if (vdev->config.intr_type == MSI_X)
  2078. ret = vxge_enable_msix(vdev);
  2079. if (ret) {
  2080. vxge_debug_init(VXGE_ERR,
  2081. "%s: Enabling MSI-X Failed", VXGE_DRIVER_NAME);
  2082. vxge_debug_init(VXGE_ERR,
  2083. "%s: Defaulting to INTA", VXGE_DRIVER_NAME);
  2084. vdev->config.intr_type = INTA;
  2085. }
  2086. if (vdev->config.intr_type == MSI_X) {
  2087. for (intr_idx = 0;
  2088. intr_idx < (vdev->no_of_vpath *
  2089. VXGE_HW_VPATH_MSIX_ACTIVE); intr_idx++) {
  2090. msix_idx = intr_idx % VXGE_HW_VPATH_MSIX_ACTIVE;
  2091. irq_req = 0;
  2092. switch (msix_idx) {
  2093. case 0:
  2094. snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
  2095. "%s:vxge:MSI-X %d - Tx - fn:%d vpath:%d",
  2096. vdev->ndev->name,
  2097. vdev->entries[intr_cnt].entry,
  2098. pci_fun, vp_idx);
  2099. ret = request_irq(
  2100. vdev->entries[intr_cnt].vector,
  2101. vxge_tx_msix_handle, 0,
  2102. vdev->desc[intr_cnt],
  2103. &vdev->vpaths[vp_idx].fifo);
  2104. vdev->vxge_entries[intr_cnt].arg =
  2105. &vdev->vpaths[vp_idx].fifo;
  2106. irq_req = 1;
  2107. break;
  2108. case 1:
  2109. snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
  2110. "%s:vxge:MSI-X %d - Rx - fn:%d vpath:%d",
  2111. vdev->ndev->name,
  2112. vdev->entries[intr_cnt].entry,
  2113. pci_fun, vp_idx);
  2114. ret = request_irq(
  2115. vdev->entries[intr_cnt].vector,
  2116. vxge_rx_msix_napi_handle,
  2117. 0,
  2118. vdev->desc[intr_cnt],
  2119. &vdev->vpaths[vp_idx].ring);
  2120. vdev->vxge_entries[intr_cnt].arg =
  2121. &vdev->vpaths[vp_idx].ring;
  2122. irq_req = 1;
  2123. break;
  2124. }
  2125. if (ret) {
  2126. vxge_debug_init(VXGE_ERR,
  2127. "%s: MSIX - %d Registration failed",
  2128. vdev->ndev->name, intr_cnt);
  2129. vxge_rem_msix_isr(vdev);
  2130. vdev->config.intr_type = INTA;
  2131. vxge_debug_init(VXGE_ERR,
  2132. "%s: Defaulting to INTA"
  2133. , vdev->ndev->name);
  2134. goto INTA_MODE;
  2135. }
  2136. if (irq_req) {
  2137. /* We requested for this msix interrupt */
  2138. vdev->vxge_entries[intr_cnt].in_use = 1;
  2139. msix_idx += vdev->vpaths[vp_idx].device_id *
  2140. VXGE_HW_VPATH_MSIX_ACTIVE;
  2141. vxge_hw_vpath_msix_unmask(
  2142. vdev->vpaths[vp_idx].handle,
  2143. msix_idx);
  2144. intr_cnt++;
  2145. }
  2146. /* Point to next vpath handler */
  2147. if (((intr_idx + 1) % VXGE_HW_VPATH_MSIX_ACTIVE == 0) &&
  2148. (vp_idx < (vdev->no_of_vpath - 1)))
  2149. vp_idx++;
  2150. }
  2151. intr_cnt = vdev->no_of_vpath * 2;
  2152. snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
  2153. "%s:vxge:MSI-X %d - Alarm - fn:%d",
  2154. vdev->ndev->name,
  2155. vdev->entries[intr_cnt].entry,
  2156. pci_fun);
  2157. /* For Alarm interrupts */
  2158. ret = request_irq(vdev->entries[intr_cnt].vector,
  2159. vxge_alarm_msix_handle, 0,
  2160. vdev->desc[intr_cnt],
  2161. &vdev->vpaths[0]);
  2162. if (ret) {
  2163. vxge_debug_init(VXGE_ERR,
  2164. "%s: MSIX - %d Registration failed",
  2165. vdev->ndev->name, intr_cnt);
  2166. vxge_rem_msix_isr(vdev);
  2167. vdev->config.intr_type = INTA;
  2168. vxge_debug_init(VXGE_ERR,
  2169. "%s: Defaulting to INTA",
  2170. vdev->ndev->name);
  2171. goto INTA_MODE;
  2172. }
  2173. msix_idx = (vdev->vpaths[0].handle->vpath->vp_id *
  2174. VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
  2175. vxge_hw_vpath_msix_unmask(vdev->vpaths[vp_idx].handle,
  2176. msix_idx);
  2177. vdev->vxge_entries[intr_cnt].in_use = 1;
  2178. vdev->vxge_entries[intr_cnt].arg = &vdev->vpaths[0];
  2179. }
  2180. INTA_MODE:
  2181. #endif
  2182. if (vdev->config.intr_type == INTA) {
  2183. snprintf(vdev->desc[0], VXGE_INTR_STRLEN,
  2184. "%s:vxge:INTA", vdev->ndev->name);
  2185. vxge_hw_device_set_intr_type(vdev->devh,
  2186. VXGE_HW_INTR_MODE_IRQLINE);
  2187. vxge_hw_vpath_tti_ci_set(vdev->vpaths[0].fifo.handle);
  2188. ret = request_irq((int) vdev->pdev->irq,
  2189. vxge_isr_napi,
  2190. IRQF_SHARED, vdev->desc[0], vdev);
  2191. if (ret) {
  2192. vxge_debug_init(VXGE_ERR,
  2193. "%s %s-%d: ISR registration failed",
  2194. VXGE_DRIVER_NAME, "IRQ", vdev->pdev->irq);
  2195. return -ENODEV;
  2196. }
  2197. vxge_debug_init(VXGE_TRACE,
  2198. "new %s-%d line allocated",
  2199. "IRQ", vdev->pdev->irq);
  2200. }
  2201. return VXGE_HW_OK;
  2202. }
  2203. static void vxge_poll_vp_reset(unsigned long data)
  2204. {
  2205. struct vxgedev *vdev = (struct vxgedev *)data;
  2206. int i, j = 0;
  2207. for (i = 0; i < vdev->no_of_vpath; i++) {
  2208. if (test_bit(i, &vdev->vp_reset)) {
  2209. vxge_reset_vpath(vdev, i);
  2210. j++;
  2211. }
  2212. }
  2213. if (j && (vdev->config.intr_type != MSI_X)) {
  2214. vxge_hw_device_unmask_all(vdev->devh);
  2215. vxge_hw_device_flush_io(vdev->devh);
  2216. }
  2217. mod_timer(&vdev->vp_reset_timer, jiffies + HZ / 2);
  2218. }
  2219. static void vxge_poll_vp_lockup(unsigned long data)
  2220. {
  2221. struct vxgedev *vdev = (struct vxgedev *)data;
  2222. enum vxge_hw_status status = VXGE_HW_OK;
  2223. struct vxge_vpath *vpath;
  2224. struct vxge_ring *ring;
  2225. int i;
  2226. unsigned long rx_frms;
  2227. for (i = 0; i < vdev->no_of_vpath; i++) {
  2228. ring = &vdev->vpaths[i].ring;
  2229. /* Truncated to machine word size number of frames */
  2230. rx_frms = ACCESS_ONCE(ring->stats.rx_frms);
  2231. /* Did this vpath received any packets */
  2232. if (ring->stats.prev_rx_frms == rx_frms) {
  2233. status = vxge_hw_vpath_check_leak(ring->handle);
  2234. /* Did it received any packets last time */
  2235. if ((VXGE_HW_FAIL == status) &&
  2236. (VXGE_HW_FAIL == ring->last_status)) {
  2237. /* schedule vpath reset */
  2238. if (!test_and_set_bit(i, &vdev->vp_reset)) {
  2239. vpath = &vdev->vpaths[i];
  2240. /* disable interrupts for this vpath */
  2241. vxge_vpath_intr_disable(vdev, i);
  2242. /* stop the queue for this vpath */
  2243. netif_tx_stop_queue(vpath->fifo.txq);
  2244. continue;
  2245. }
  2246. }
  2247. }
  2248. ring->stats.prev_rx_frms = rx_frms;
  2249. ring->last_status = status;
  2250. }
  2251. /* Check every 1 milli second */
  2252. mod_timer(&vdev->vp_lockup_timer, jiffies + HZ / 1000);
  2253. }
  2254. static netdev_features_t vxge_fix_features(struct net_device *dev,
  2255. netdev_features_t features)
  2256. {
  2257. netdev_features_t changed = dev->features ^ features;
  2258. /* Enabling RTH requires some of the logic in vxge_device_register and a
  2259. * vpath reset. Due to these restrictions, only allow modification
  2260. * while the interface is down.
  2261. */
  2262. if ((changed & NETIF_F_RXHASH) && netif_running(dev))
  2263. features ^= NETIF_F_RXHASH;
  2264. return features;
  2265. }
  2266. static int vxge_set_features(struct net_device *dev, netdev_features_t features)
  2267. {
  2268. struct vxgedev *vdev = netdev_priv(dev);
  2269. netdev_features_t changed = dev->features ^ features;
  2270. if (!(changed & NETIF_F_RXHASH))
  2271. return 0;
  2272. /* !netif_running() ensured by vxge_fix_features() */
  2273. vdev->devh->config.rth_en = !!(features & NETIF_F_RXHASH);
  2274. if (vxge_reset_all_vpaths(vdev) != VXGE_HW_OK) {
  2275. dev->features = features ^ NETIF_F_RXHASH;
  2276. vdev->devh->config.rth_en = !!(dev->features & NETIF_F_RXHASH);
  2277. return -EIO;
  2278. }
  2279. return 0;
  2280. }
  2281. /**
  2282. * vxge_open
  2283. * @dev: pointer to the device structure.
  2284. *
  2285. * This function is the open entry point of the driver. It mainly calls a
  2286. * function to allocate Rx buffers and inserts them into the buffer
  2287. * descriptors and then enables the Rx part of the NIC.
  2288. * Return value: '0' on success and an appropriate (-)ve integer as
  2289. * defined in errno.h file on failure.
  2290. */
  2291. static int vxge_open(struct net_device *dev)
  2292. {
  2293. enum vxge_hw_status status;
  2294. struct vxgedev *vdev;
  2295. struct __vxge_hw_device *hldev;
  2296. struct vxge_vpath *vpath;
  2297. int ret = 0;
  2298. int i;
  2299. u64 val64, function_mode;
  2300. vxge_debug_entryexit(VXGE_TRACE,
  2301. "%s: %s:%d", dev->name, __func__, __LINE__);
  2302. vdev = netdev_priv(dev);
  2303. hldev = pci_get_drvdata(vdev->pdev);
  2304. function_mode = vdev->config.device_hw_info.function_mode;
  2305. /* make sure you have link off by default every time Nic is
  2306. * initialized */
  2307. netif_carrier_off(dev);
  2308. /* Open VPATHs */
  2309. status = vxge_open_vpaths(vdev);
  2310. if (status != VXGE_HW_OK) {
  2311. vxge_debug_init(VXGE_ERR,
  2312. "%s: fatal: Vpath open failed", vdev->ndev->name);
  2313. ret = -EPERM;
  2314. goto out0;
  2315. }
  2316. vdev->mtu = dev->mtu;
  2317. status = vxge_add_isr(vdev);
  2318. if (status != VXGE_HW_OK) {
  2319. vxge_debug_init(VXGE_ERR,
  2320. "%s: fatal: ISR add failed", dev->name);
  2321. ret = -EPERM;
  2322. goto out1;
  2323. }
  2324. if (vdev->config.intr_type != MSI_X) {
  2325. netif_napi_add(dev, &vdev->napi, vxge_poll_inta,
  2326. vdev->config.napi_weight);
  2327. napi_enable(&vdev->napi);
  2328. for (i = 0; i < vdev->no_of_vpath; i++) {
  2329. vpath = &vdev->vpaths[i];
  2330. vpath->ring.napi_p = &vdev->napi;
  2331. }
  2332. } else {
  2333. for (i = 0; i < vdev->no_of_vpath; i++) {
  2334. vpath = &vdev->vpaths[i];
  2335. netif_napi_add(dev, &vpath->ring.napi,
  2336. vxge_poll_msix, vdev->config.napi_weight);
  2337. napi_enable(&vpath->ring.napi);
  2338. vpath->ring.napi_p = &vpath->ring.napi;
  2339. }
  2340. }
  2341. /* configure RTH */
  2342. if (vdev->config.rth_steering) {
  2343. status = vxge_rth_configure(vdev);
  2344. if (status != VXGE_HW_OK) {
  2345. vxge_debug_init(VXGE_ERR,
  2346. "%s: fatal: RTH configuration failed",
  2347. dev->name);
  2348. ret = -EPERM;
  2349. goto out2;
  2350. }
  2351. }
  2352. printk(KERN_INFO "%s: Receive Hashing Offload %s\n", dev->name,
  2353. hldev->config.rth_en ? "enabled" : "disabled");
  2354. for (i = 0; i < vdev->no_of_vpath; i++) {
  2355. vpath = &vdev->vpaths[i];
  2356. /* set initial mtu before enabling the device */
  2357. status = vxge_hw_vpath_mtu_set(vpath->handle, vdev->mtu);
  2358. if (status != VXGE_HW_OK) {
  2359. vxge_debug_init(VXGE_ERR,
  2360. "%s: fatal: can not set new MTU", dev->name);
  2361. ret = -EPERM;
  2362. goto out2;
  2363. }
  2364. }
  2365. VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_TRACE, VXGE_COMPONENT_LL, vdev);
  2366. vxge_debug_init(vdev->level_trace,
  2367. "%s: MTU is %d", vdev->ndev->name, vdev->mtu);
  2368. VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_ERR, VXGE_COMPONENT_LL, vdev);
  2369. /* Restore the DA, VID table and also multicast and promiscuous mode
  2370. * states
  2371. */
  2372. if (vdev->all_multi_flg) {
  2373. for (i = 0; i < vdev->no_of_vpath; i++) {
  2374. vpath = &vdev->vpaths[i];
  2375. vxge_restore_vpath_mac_addr(vpath);
  2376. vxge_restore_vpath_vid_table(vpath);
  2377. status = vxge_hw_vpath_mcast_enable(vpath->handle);
  2378. if (status != VXGE_HW_OK)
  2379. vxge_debug_init(VXGE_ERR,
  2380. "%s:%d Enabling multicast failed",
  2381. __func__, __LINE__);
  2382. }
  2383. }
  2384. /* Enable vpath to sniff all unicast/multicast traffic that not
  2385. * addressed to them. We allow promiscuous mode for PF only
  2386. */
  2387. val64 = 0;
  2388. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
  2389. val64 |= VXGE_HW_RXMAC_AUTHORIZE_ALL_ADDR_VP(i);
  2390. vxge_hw_mgmt_reg_write(vdev->devh,
  2391. vxge_hw_mgmt_reg_type_mrpcim,
  2392. 0,
  2393. (ulong)offsetof(struct vxge_hw_mrpcim_reg,
  2394. rxmac_authorize_all_addr),
  2395. val64);
  2396. vxge_hw_mgmt_reg_write(vdev->devh,
  2397. vxge_hw_mgmt_reg_type_mrpcim,
  2398. 0,
  2399. (ulong)offsetof(struct vxge_hw_mrpcim_reg,
  2400. rxmac_authorize_all_vid),
  2401. val64);
  2402. vxge_set_multicast(dev);
  2403. /* Enabling Bcast and mcast for all vpath */
  2404. for (i = 0; i < vdev->no_of_vpath; i++) {
  2405. vpath = &vdev->vpaths[i];
  2406. status = vxge_hw_vpath_bcast_enable(vpath->handle);
  2407. if (status != VXGE_HW_OK)
  2408. vxge_debug_init(VXGE_ERR,
  2409. "%s : Can not enable bcast for vpath "
  2410. "id %d", dev->name, i);
  2411. if (vdev->config.addr_learn_en) {
  2412. status = vxge_hw_vpath_mcast_enable(vpath->handle);
  2413. if (status != VXGE_HW_OK)
  2414. vxge_debug_init(VXGE_ERR,
  2415. "%s : Can not enable mcast for vpath "
  2416. "id %d", dev->name, i);
  2417. }
  2418. }
  2419. vxge_hw_device_setpause_data(vdev->devh, 0,
  2420. vdev->config.tx_pause_enable,
  2421. vdev->config.rx_pause_enable);
  2422. if (vdev->vp_reset_timer.function == NULL)
  2423. vxge_os_timer(vdev->vp_reset_timer,
  2424. vxge_poll_vp_reset, vdev, (HZ/2));
  2425. /* There is no need to check for RxD leak and RxD lookup on Titan1A */
  2426. if (vdev->titan1 && vdev->vp_lockup_timer.function == NULL)
  2427. vxge_os_timer(vdev->vp_lockup_timer, vxge_poll_vp_lockup, vdev,
  2428. HZ / 2);
  2429. set_bit(__VXGE_STATE_CARD_UP, &vdev->state);
  2430. smp_wmb();
  2431. if (vxge_hw_device_link_state_get(vdev->devh) == VXGE_HW_LINK_UP) {
  2432. netif_carrier_on(vdev->ndev);
  2433. netdev_notice(vdev->ndev, "Link Up\n");
  2434. vdev->stats.link_up++;
  2435. }
  2436. vxge_hw_device_intr_enable(vdev->devh);
  2437. smp_wmb();
  2438. for (i = 0; i < vdev->no_of_vpath; i++) {
  2439. vpath = &vdev->vpaths[i];
  2440. vxge_hw_vpath_enable(vpath->handle);
  2441. smp_wmb();
  2442. vxge_hw_vpath_rx_doorbell_init(vpath->handle);
  2443. }
  2444. netif_tx_start_all_queues(vdev->ndev);
  2445. /* configure CI */
  2446. vxge_config_ci_for_tti_rti(vdev);
  2447. goto out0;
  2448. out2:
  2449. vxge_rem_isr(vdev);
  2450. /* Disable napi */
  2451. if (vdev->config.intr_type != MSI_X)
  2452. napi_disable(&vdev->napi);
  2453. else {
  2454. for (i = 0; i < vdev->no_of_vpath; i++)
  2455. napi_disable(&vdev->vpaths[i].ring.napi);
  2456. }
  2457. out1:
  2458. vxge_close_vpaths(vdev, 0);
  2459. out0:
  2460. vxge_debug_entryexit(VXGE_TRACE,
  2461. "%s: %s:%d Exiting...",
  2462. dev->name, __func__, __LINE__);
  2463. return ret;
  2464. }
  2465. /* Loop through the mac address list and delete all the entries */
  2466. static void vxge_free_mac_add_list(struct vxge_vpath *vpath)
  2467. {
  2468. struct list_head *entry, *next;
  2469. if (list_empty(&vpath->mac_addr_list))
  2470. return;
  2471. list_for_each_safe(entry, next, &vpath->mac_addr_list) {
  2472. list_del(entry);
  2473. kfree((struct vxge_mac_addrs *)entry);
  2474. }
  2475. }
  2476. static void vxge_napi_del_all(struct vxgedev *vdev)
  2477. {
  2478. int i;
  2479. if (vdev->config.intr_type != MSI_X)
  2480. netif_napi_del(&vdev->napi);
  2481. else {
  2482. for (i = 0; i < vdev->no_of_vpath; i++)
  2483. netif_napi_del(&vdev->vpaths[i].ring.napi);
  2484. }
  2485. }
  2486. static int do_vxge_close(struct net_device *dev, int do_io)
  2487. {
  2488. enum vxge_hw_status status;
  2489. struct vxgedev *vdev;
  2490. struct __vxge_hw_device *hldev;
  2491. int i;
  2492. u64 val64, vpath_vector;
  2493. vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
  2494. dev->name, __func__, __LINE__);
  2495. vdev = netdev_priv(dev);
  2496. hldev = pci_get_drvdata(vdev->pdev);
  2497. if (unlikely(!is_vxge_card_up(vdev)))
  2498. return 0;
  2499. /* If vxge_handle_crit_err task is executing,
  2500. * wait till it completes. */
  2501. while (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
  2502. msleep(50);
  2503. if (do_io) {
  2504. /* Put the vpath back in normal mode */
  2505. vpath_vector = vxge_mBIT(vdev->vpaths[0].device_id);
  2506. status = vxge_hw_mgmt_reg_read(vdev->devh,
  2507. vxge_hw_mgmt_reg_type_mrpcim,
  2508. 0,
  2509. (ulong)offsetof(
  2510. struct vxge_hw_mrpcim_reg,
  2511. rts_mgr_cbasin_cfg),
  2512. &val64);
  2513. if (status == VXGE_HW_OK) {
  2514. val64 &= ~vpath_vector;
  2515. status = vxge_hw_mgmt_reg_write(vdev->devh,
  2516. vxge_hw_mgmt_reg_type_mrpcim,
  2517. 0,
  2518. (ulong)offsetof(
  2519. struct vxge_hw_mrpcim_reg,
  2520. rts_mgr_cbasin_cfg),
  2521. val64);
  2522. }
  2523. /* Remove the function 0 from promiscuous mode */
  2524. vxge_hw_mgmt_reg_write(vdev->devh,
  2525. vxge_hw_mgmt_reg_type_mrpcim,
  2526. 0,
  2527. (ulong)offsetof(struct vxge_hw_mrpcim_reg,
  2528. rxmac_authorize_all_addr),
  2529. 0);
  2530. vxge_hw_mgmt_reg_write(vdev->devh,
  2531. vxge_hw_mgmt_reg_type_mrpcim,
  2532. 0,
  2533. (ulong)offsetof(struct vxge_hw_mrpcim_reg,
  2534. rxmac_authorize_all_vid),
  2535. 0);
  2536. smp_wmb();
  2537. }
  2538. if (vdev->titan1)
  2539. del_timer_sync(&vdev->vp_lockup_timer);
  2540. del_timer_sync(&vdev->vp_reset_timer);
  2541. if (do_io)
  2542. vxge_hw_device_wait_receive_idle(hldev);
  2543. clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
  2544. /* Disable napi */
  2545. if (vdev->config.intr_type != MSI_X)
  2546. napi_disable(&vdev->napi);
  2547. else {
  2548. for (i = 0; i < vdev->no_of_vpath; i++)
  2549. napi_disable(&vdev->vpaths[i].ring.napi);
  2550. }
  2551. netif_carrier_off(vdev->ndev);
  2552. netdev_notice(vdev->ndev, "Link Down\n");
  2553. netif_tx_stop_all_queues(vdev->ndev);
  2554. /* Note that at this point xmit() is stopped by upper layer */
  2555. if (do_io)
  2556. vxge_hw_device_intr_disable(vdev->devh);
  2557. vxge_rem_isr(vdev);
  2558. vxge_napi_del_all(vdev);
  2559. if (do_io)
  2560. vxge_reset_all_vpaths(vdev);
  2561. vxge_close_vpaths(vdev, 0);
  2562. vxge_debug_entryexit(VXGE_TRACE,
  2563. "%s: %s:%d Exiting...", dev->name, __func__, __LINE__);
  2564. clear_bit(__VXGE_STATE_RESET_CARD, &vdev->state);
  2565. return 0;
  2566. }
  2567. /**
  2568. * vxge_close
  2569. * @dev: device pointer.
  2570. *
  2571. * This is the stop entry point of the driver. It needs to undo exactly
  2572. * whatever was done by the open entry point, thus it's usually referred to
  2573. * as the close function.Among other things this function mainly stops the
  2574. * Rx side of the NIC and frees all the Rx buffers in the Rx rings.
  2575. * Return value: '0' on success and an appropriate (-)ve integer as
  2576. * defined in errno.h file on failure.
  2577. */
  2578. static int vxge_close(struct net_device *dev)
  2579. {
  2580. do_vxge_close(dev, 1);
  2581. return 0;
  2582. }
  2583. /**
  2584. * vxge_change_mtu
  2585. * @dev: net device pointer.
  2586. * @new_mtu :the new MTU size for the device.
  2587. *
  2588. * A driver entry point to change MTU size for the device. Before changing
  2589. * the MTU the device must be stopped.
  2590. */
  2591. static int vxge_change_mtu(struct net_device *dev, int new_mtu)
  2592. {
  2593. struct vxgedev *vdev = netdev_priv(dev);
  2594. vxge_debug_entryexit(vdev->level_trace,
  2595. "%s:%d", __func__, __LINE__);
  2596. if ((new_mtu < VXGE_HW_MIN_MTU) || (new_mtu > VXGE_HW_MAX_MTU)) {
  2597. vxge_debug_init(vdev->level_err,
  2598. "%s: mtu size is invalid", dev->name);
  2599. return -EPERM;
  2600. }
  2601. /* check if device is down already */
  2602. if (unlikely(!is_vxge_card_up(vdev))) {
  2603. /* just store new value, will use later on open() */
  2604. dev->mtu = new_mtu;
  2605. vxge_debug_init(vdev->level_err,
  2606. "%s", "device is down on MTU change");
  2607. return 0;
  2608. }
  2609. vxge_debug_init(vdev->level_trace,
  2610. "trying to apply new MTU %d", new_mtu);
  2611. if (vxge_close(dev))
  2612. return -EIO;
  2613. dev->mtu = new_mtu;
  2614. vdev->mtu = new_mtu;
  2615. if (vxge_open(dev))
  2616. return -EIO;
  2617. vxge_debug_init(vdev->level_trace,
  2618. "%s: MTU changed to %d", vdev->ndev->name, new_mtu);
  2619. vxge_debug_entryexit(vdev->level_trace,
  2620. "%s:%d Exiting...", __func__, __LINE__);
  2621. return 0;
  2622. }
  2623. /**
  2624. * vxge_get_stats64
  2625. * @dev: pointer to the device structure
  2626. * @stats: pointer to struct rtnl_link_stats64
  2627. *
  2628. */
  2629. static struct rtnl_link_stats64 *
  2630. vxge_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *net_stats)
  2631. {
  2632. struct vxgedev *vdev = netdev_priv(dev);
  2633. int k;
  2634. /* net_stats already zeroed by caller */
  2635. for (k = 0; k < vdev->no_of_vpath; k++) {
  2636. struct vxge_ring_stats *rxstats = &vdev->vpaths[k].ring.stats;
  2637. struct vxge_fifo_stats *txstats = &vdev->vpaths[k].fifo.stats;
  2638. unsigned int start;
  2639. u64 packets, bytes, multicast;
  2640. do {
  2641. start = u64_stats_fetch_begin(&rxstats->syncp);
  2642. packets = rxstats->rx_frms;
  2643. multicast = rxstats->rx_mcast;
  2644. bytes = rxstats->rx_bytes;
  2645. } while (u64_stats_fetch_retry(&rxstats->syncp, start));
  2646. net_stats->rx_packets += packets;
  2647. net_stats->rx_bytes += bytes;
  2648. net_stats->multicast += multicast;
  2649. net_stats->rx_errors += rxstats->rx_errors;
  2650. net_stats->rx_dropped += rxstats->rx_dropped;
  2651. do {
  2652. start = u64_stats_fetch_begin(&txstats->syncp);
  2653. packets = txstats->tx_frms;
  2654. bytes = txstats->tx_bytes;
  2655. } while (u64_stats_fetch_retry(&txstats->syncp, start));
  2656. net_stats->tx_packets += packets;
  2657. net_stats->tx_bytes += bytes;
  2658. net_stats->tx_errors += txstats->tx_errors;
  2659. }
  2660. return net_stats;
  2661. }
  2662. static enum vxge_hw_status vxge_timestamp_config(struct __vxge_hw_device *devh)
  2663. {
  2664. enum vxge_hw_status status;
  2665. u64 val64;
  2666. /* Timestamp is passed to the driver via the FCS, therefore we
  2667. * must disable the FCS stripping by the adapter. Since this is
  2668. * required for the driver to load (due to a hardware bug),
  2669. * there is no need to do anything special here.
  2670. */
  2671. val64 = VXGE_HW_XMAC_TIMESTAMP_EN |
  2672. VXGE_HW_XMAC_TIMESTAMP_USE_LINK_ID(0) |
  2673. VXGE_HW_XMAC_TIMESTAMP_INTERVAL(0);
  2674. status = vxge_hw_mgmt_reg_write(devh,
  2675. vxge_hw_mgmt_reg_type_mrpcim,
  2676. 0,
  2677. offsetof(struct vxge_hw_mrpcim_reg,
  2678. xmac_timestamp),
  2679. val64);
  2680. vxge_hw_device_flush_io(devh);
  2681. devh->config.hwts_en = VXGE_HW_HWTS_ENABLE;
  2682. return status;
  2683. }
  2684. static int vxge_hwtstamp_ioctl(struct vxgedev *vdev, void __user *data)
  2685. {
  2686. struct hwtstamp_config config;
  2687. int i;
  2688. if (copy_from_user(&config, data, sizeof(config)))
  2689. return -EFAULT;
  2690. /* reserved for future extensions */
  2691. if (config.flags)
  2692. return -EINVAL;
  2693. /* Transmit HW Timestamp not supported */
  2694. switch (config.tx_type) {
  2695. case HWTSTAMP_TX_OFF:
  2696. break;
  2697. case HWTSTAMP_TX_ON:
  2698. default:
  2699. return -ERANGE;
  2700. }
  2701. switch (config.rx_filter) {
  2702. case HWTSTAMP_FILTER_NONE:
  2703. vdev->rx_hwts = 0;
  2704. config.rx_filter = HWTSTAMP_FILTER_NONE;
  2705. break;
  2706. case HWTSTAMP_FILTER_ALL:
  2707. case HWTSTAMP_FILTER_SOME:
  2708. case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
  2709. case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
  2710. case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
  2711. case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
  2712. case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
  2713. case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
  2714. case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
  2715. case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
  2716. case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
  2717. case HWTSTAMP_FILTER_PTP_V2_EVENT:
  2718. case HWTSTAMP_FILTER_PTP_V2_SYNC:
  2719. case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
  2720. if (vdev->devh->config.hwts_en != VXGE_HW_HWTS_ENABLE)
  2721. return -EFAULT;
  2722. vdev->rx_hwts = 1;
  2723. config.rx_filter = HWTSTAMP_FILTER_ALL;
  2724. break;
  2725. default:
  2726. return -ERANGE;
  2727. }
  2728. for (i = 0; i < vdev->no_of_vpath; i++)
  2729. vdev->vpaths[i].ring.rx_hwts = vdev->rx_hwts;
  2730. if (copy_to_user(data, &config, sizeof(config)))
  2731. return -EFAULT;
  2732. return 0;
  2733. }
  2734. /**
  2735. * vxge_ioctl
  2736. * @dev: Device pointer.
  2737. * @ifr: An IOCTL specific structure, that can contain a pointer to
  2738. * a proprietary structure used to pass information to the driver.
  2739. * @cmd: This is used to distinguish between the different commands that
  2740. * can be passed to the IOCTL functions.
  2741. *
  2742. * Entry point for the Ioctl.
  2743. */
  2744. static int vxge_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  2745. {
  2746. struct vxgedev *vdev = netdev_priv(dev);
  2747. int ret;
  2748. switch (cmd) {
  2749. case SIOCSHWTSTAMP:
  2750. ret = vxge_hwtstamp_ioctl(vdev, rq->ifr_data);
  2751. if (ret)
  2752. return ret;
  2753. break;
  2754. default:
  2755. return -EOPNOTSUPP;
  2756. }
  2757. return 0;
  2758. }
  2759. /**
  2760. * vxge_tx_watchdog
  2761. * @dev: pointer to net device structure
  2762. *
  2763. * Watchdog for transmit side.
  2764. * This function is triggered if the Tx Queue is stopped
  2765. * for a pre-defined amount of time when the Interface is still up.
  2766. */
  2767. static void vxge_tx_watchdog(struct net_device *dev)
  2768. {
  2769. struct vxgedev *vdev;
  2770. vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
  2771. vdev = netdev_priv(dev);
  2772. vdev->cric_err_event = VXGE_HW_EVENT_RESET_START;
  2773. schedule_work(&vdev->reset_task);
  2774. vxge_debug_entryexit(VXGE_TRACE,
  2775. "%s:%d Exiting...", __func__, __LINE__);
  2776. }
  2777. /**
  2778. * vxge_vlan_rx_add_vid
  2779. * @dev: net device pointer.
  2780. * @vid: vid
  2781. *
  2782. * Add the vlan id to the devices vlan id table
  2783. */
  2784. static int
  2785. vxge_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
  2786. {
  2787. struct vxgedev *vdev = netdev_priv(dev);
  2788. struct vxge_vpath *vpath;
  2789. int vp_id;
  2790. /* Add these vlan to the vid table */
  2791. for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
  2792. vpath = &vdev->vpaths[vp_id];
  2793. if (!vpath->is_open)
  2794. continue;
  2795. vxge_hw_vpath_vid_add(vpath->handle, vid);
  2796. }
  2797. set_bit(vid, vdev->active_vlans);
  2798. return 0;
  2799. }
  2800. /**
  2801. * vxge_vlan_rx_add_vid
  2802. * @dev: net device pointer.
  2803. * @vid: vid
  2804. *
  2805. * Remove the vlan id from the device's vlan id table
  2806. */
  2807. static int
  2808. vxge_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
  2809. {
  2810. struct vxgedev *vdev = netdev_priv(dev);
  2811. struct vxge_vpath *vpath;
  2812. int vp_id;
  2813. vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
  2814. /* Delete this vlan from the vid table */
  2815. for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
  2816. vpath = &vdev->vpaths[vp_id];
  2817. if (!vpath->is_open)
  2818. continue;
  2819. vxge_hw_vpath_vid_delete(vpath->handle, vid);
  2820. }
  2821. vxge_debug_entryexit(VXGE_TRACE,
  2822. "%s:%d Exiting...", __func__, __LINE__);
  2823. clear_bit(vid, vdev->active_vlans);
  2824. return 0;
  2825. }
  2826. static const struct net_device_ops vxge_netdev_ops = {
  2827. .ndo_open = vxge_open,
  2828. .ndo_stop = vxge_close,
  2829. .ndo_get_stats64 = vxge_get_stats64,
  2830. .ndo_start_xmit = vxge_xmit,
  2831. .ndo_validate_addr = eth_validate_addr,
  2832. .ndo_set_rx_mode = vxge_set_multicast,
  2833. .ndo_do_ioctl = vxge_ioctl,
  2834. .ndo_set_mac_address = vxge_set_mac_addr,
  2835. .ndo_change_mtu = vxge_change_mtu,
  2836. .ndo_fix_features = vxge_fix_features,
  2837. .ndo_set_features = vxge_set_features,
  2838. .ndo_vlan_rx_kill_vid = vxge_vlan_rx_kill_vid,
  2839. .ndo_vlan_rx_add_vid = vxge_vlan_rx_add_vid,
  2840. .ndo_tx_timeout = vxge_tx_watchdog,
  2841. #ifdef CONFIG_NET_POLL_CONTROLLER
  2842. .ndo_poll_controller = vxge_netpoll,
  2843. #endif
  2844. };
  2845. static int __devinit vxge_device_register(struct __vxge_hw_device *hldev,
  2846. struct vxge_config *config,
  2847. int high_dma, int no_of_vpath,
  2848. struct vxgedev **vdev_out)
  2849. {
  2850. struct net_device *ndev;
  2851. enum vxge_hw_status status = VXGE_HW_OK;
  2852. struct vxgedev *vdev;
  2853. int ret = 0, no_of_queue = 1;
  2854. u64 stat;
  2855. *vdev_out = NULL;
  2856. if (config->tx_steering_type)
  2857. no_of_queue = no_of_vpath;
  2858. ndev = alloc_etherdev_mq(sizeof(struct vxgedev),
  2859. no_of_queue);
  2860. if (ndev == NULL) {
  2861. vxge_debug_init(
  2862. vxge_hw_device_trace_level_get(hldev),
  2863. "%s : device allocation failed", __func__);
  2864. ret = -ENODEV;
  2865. goto _out0;
  2866. }
  2867. vxge_debug_entryexit(
  2868. vxge_hw_device_trace_level_get(hldev),
  2869. "%s: %s:%d Entering...",
  2870. ndev->name, __func__, __LINE__);
  2871. vdev = netdev_priv(ndev);
  2872. memset(vdev, 0, sizeof(struct vxgedev));
  2873. vdev->ndev = ndev;
  2874. vdev->devh = hldev;
  2875. vdev->pdev = hldev->pdev;
  2876. memcpy(&vdev->config, config, sizeof(struct vxge_config));
  2877. vdev->rx_hwts = 0;
  2878. vdev->titan1 = (vdev->pdev->revision == VXGE_HW_TITAN1_PCI_REVISION);
  2879. SET_NETDEV_DEV(ndev, &vdev->pdev->dev);
  2880. ndev->hw_features = NETIF_F_RXCSUM | NETIF_F_SG |
  2881. NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  2882. NETIF_F_TSO | NETIF_F_TSO6 |
  2883. NETIF_F_HW_VLAN_TX;
  2884. if (vdev->config.rth_steering != NO_STEERING)
  2885. ndev->hw_features |= NETIF_F_RXHASH;
  2886. ndev->features |= ndev->hw_features |
  2887. NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER;
  2888. /* Driver entry points */
  2889. ndev->irq = vdev->pdev->irq;
  2890. ndev->base_addr = (unsigned long) hldev->bar0;
  2891. ndev->netdev_ops = &vxge_netdev_ops;
  2892. ndev->watchdog_timeo = VXGE_LL_WATCH_DOG_TIMEOUT;
  2893. INIT_WORK(&vdev->reset_task, vxge_reset);
  2894. vxge_initialize_ethtool_ops(ndev);
  2895. /* Allocate memory for vpath */
  2896. vdev->vpaths = kzalloc((sizeof(struct vxge_vpath)) *
  2897. no_of_vpath, GFP_KERNEL);
  2898. if (!vdev->vpaths) {
  2899. vxge_debug_init(VXGE_ERR,
  2900. "%s: vpath memory allocation failed",
  2901. vdev->ndev->name);
  2902. ret = -ENOMEM;
  2903. goto _out1;
  2904. }
  2905. vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
  2906. "%s : checksuming enabled", __func__);
  2907. if (high_dma) {
  2908. ndev->features |= NETIF_F_HIGHDMA;
  2909. vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
  2910. "%s : using High DMA", __func__);
  2911. }
  2912. ret = register_netdev(ndev);
  2913. if (ret) {
  2914. vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
  2915. "%s: %s : device registration failed!",
  2916. ndev->name, __func__);
  2917. goto _out2;
  2918. }
  2919. /* Set the factory defined MAC address initially */
  2920. ndev->addr_len = ETH_ALEN;
  2921. /* Make Link state as off at this point, when the Link change
  2922. * interrupt comes the state will be automatically changed to
  2923. * the right state.
  2924. */
  2925. netif_carrier_off(ndev);
  2926. vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
  2927. "%s: Ethernet device registered",
  2928. ndev->name);
  2929. hldev->ndev = ndev;
  2930. *vdev_out = vdev;
  2931. /* Resetting the Device stats */
  2932. status = vxge_hw_mrpcim_stats_access(
  2933. hldev,
  2934. VXGE_HW_STATS_OP_CLEAR_ALL_STATS,
  2935. 0,
  2936. 0,
  2937. &stat);
  2938. if (status == VXGE_HW_ERR_PRIVILAGED_OPEARATION)
  2939. vxge_debug_init(
  2940. vxge_hw_device_trace_level_get(hldev),
  2941. "%s: device stats clear returns"
  2942. "VXGE_HW_ERR_PRIVILAGED_OPEARATION", ndev->name);
  2943. vxge_debug_entryexit(vxge_hw_device_trace_level_get(hldev),
  2944. "%s: %s:%d Exiting...",
  2945. ndev->name, __func__, __LINE__);
  2946. return ret;
  2947. _out2:
  2948. kfree(vdev->vpaths);
  2949. _out1:
  2950. free_netdev(ndev);
  2951. _out0:
  2952. return ret;
  2953. }
  2954. /*
  2955. * vxge_device_unregister
  2956. *
  2957. * This function will unregister and free network device
  2958. */
  2959. static void vxge_device_unregister(struct __vxge_hw_device *hldev)
  2960. {
  2961. struct vxgedev *vdev;
  2962. struct net_device *dev;
  2963. char buf[IFNAMSIZ];
  2964. dev = hldev->ndev;
  2965. vdev = netdev_priv(dev);
  2966. vxge_debug_entryexit(vdev->level_trace, "%s: %s:%d", vdev->ndev->name,
  2967. __func__, __LINE__);
  2968. strncpy(buf, dev->name, IFNAMSIZ);
  2969. flush_work_sync(&vdev->reset_task);
  2970. /* in 2.6 will call stop() if device is up */
  2971. unregister_netdev(dev);
  2972. kfree(vdev->vpaths);
  2973. /* we are safe to free it now */
  2974. free_netdev(dev);
  2975. vxge_debug_init(vdev->level_trace, "%s: ethernet device unregistered",
  2976. buf);
  2977. vxge_debug_entryexit(vdev->level_trace, "%s: %s:%d Exiting...", buf,
  2978. __func__, __LINE__);
  2979. }
  2980. /*
  2981. * vxge_callback_crit_err
  2982. *
  2983. * This function is called by the alarm handler in interrupt context.
  2984. * Driver must analyze it based on the event type.
  2985. */
  2986. static void
  2987. vxge_callback_crit_err(struct __vxge_hw_device *hldev,
  2988. enum vxge_hw_event type, u64 vp_id)
  2989. {
  2990. struct net_device *dev = hldev->ndev;
  2991. struct vxgedev *vdev = netdev_priv(dev);
  2992. struct vxge_vpath *vpath = NULL;
  2993. int vpath_idx;
  2994. vxge_debug_entryexit(vdev->level_trace,
  2995. "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
  2996. /* Note: This event type should be used for device wide
  2997. * indications only - Serious errors, Slot freeze and critical errors
  2998. */
  2999. vdev->cric_err_event = type;
  3000. for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
  3001. vpath = &vdev->vpaths[vpath_idx];
  3002. if (vpath->device_id == vp_id)
  3003. break;
  3004. }
  3005. if (!test_bit(__VXGE_STATE_RESET_CARD, &vdev->state)) {
  3006. if (type == VXGE_HW_EVENT_SLOT_FREEZE) {
  3007. vxge_debug_init(VXGE_ERR,
  3008. "%s: Slot is frozen", vdev->ndev->name);
  3009. } else if (type == VXGE_HW_EVENT_SERR) {
  3010. vxge_debug_init(VXGE_ERR,
  3011. "%s: Encountered Serious Error",
  3012. vdev->ndev->name);
  3013. } else if (type == VXGE_HW_EVENT_CRITICAL_ERR)
  3014. vxge_debug_init(VXGE_ERR,
  3015. "%s: Encountered Critical Error",
  3016. vdev->ndev->name);
  3017. }
  3018. if ((type == VXGE_HW_EVENT_SERR) ||
  3019. (type == VXGE_HW_EVENT_SLOT_FREEZE)) {
  3020. if (unlikely(vdev->exec_mode))
  3021. clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
  3022. } else if (type == VXGE_HW_EVENT_CRITICAL_ERR) {
  3023. vxge_hw_device_mask_all(hldev);
  3024. if (unlikely(vdev->exec_mode))
  3025. clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
  3026. } else if ((type == VXGE_HW_EVENT_FIFO_ERR) ||
  3027. (type == VXGE_HW_EVENT_VPATH_ERR)) {
  3028. if (unlikely(vdev->exec_mode))
  3029. clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
  3030. else {
  3031. /* check if this vpath is already set for reset */
  3032. if (!test_and_set_bit(vpath_idx, &vdev->vp_reset)) {
  3033. /* disable interrupts for this vpath */
  3034. vxge_vpath_intr_disable(vdev, vpath_idx);
  3035. /* stop the queue for this vpath */
  3036. netif_tx_stop_queue(vpath->fifo.txq);
  3037. }
  3038. }
  3039. }
  3040. vxge_debug_entryexit(vdev->level_trace,
  3041. "%s: %s:%d Exiting...",
  3042. vdev->ndev->name, __func__, __LINE__);
  3043. }
  3044. static void verify_bandwidth(void)
  3045. {
  3046. int i, band_width, total = 0, equal_priority = 0;
  3047. /* 1. If user enters 0 for some fifo, give equal priority to all */
  3048. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
  3049. if (bw_percentage[i] == 0) {
  3050. equal_priority = 1;
  3051. break;
  3052. }
  3053. }
  3054. if (!equal_priority) {
  3055. /* 2. If sum exceeds 100, give equal priority to all */
  3056. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
  3057. if (bw_percentage[i] == 0xFF)
  3058. break;
  3059. total += bw_percentage[i];
  3060. if (total > VXGE_HW_VPATH_BANDWIDTH_MAX) {
  3061. equal_priority = 1;
  3062. break;
  3063. }
  3064. }
  3065. }
  3066. if (!equal_priority) {
  3067. /* Is all the bandwidth consumed? */
  3068. if (total < VXGE_HW_VPATH_BANDWIDTH_MAX) {
  3069. if (i < VXGE_HW_MAX_VIRTUAL_PATHS) {
  3070. /* Split rest of bw equally among next VPs*/
  3071. band_width =
  3072. (VXGE_HW_VPATH_BANDWIDTH_MAX - total) /
  3073. (VXGE_HW_MAX_VIRTUAL_PATHS - i);
  3074. if (band_width < 2) /* min of 2% */
  3075. equal_priority = 1;
  3076. else {
  3077. for (; i < VXGE_HW_MAX_VIRTUAL_PATHS;
  3078. i++)
  3079. bw_percentage[i] =
  3080. band_width;
  3081. }
  3082. }
  3083. } else if (i < VXGE_HW_MAX_VIRTUAL_PATHS)
  3084. equal_priority = 1;
  3085. }
  3086. if (equal_priority) {
  3087. vxge_debug_init(VXGE_ERR,
  3088. "%s: Assigning equal bandwidth to all the vpaths",
  3089. VXGE_DRIVER_NAME);
  3090. bw_percentage[0] = VXGE_HW_VPATH_BANDWIDTH_MAX /
  3091. VXGE_HW_MAX_VIRTUAL_PATHS;
  3092. for (i = 1; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
  3093. bw_percentage[i] = bw_percentage[0];
  3094. }
  3095. }
  3096. /*
  3097. * Vpath configuration
  3098. */
  3099. static int __devinit vxge_config_vpaths(
  3100. struct vxge_hw_device_config *device_config,
  3101. u64 vpath_mask, struct vxge_config *config_param)
  3102. {
  3103. int i, no_of_vpaths = 0, default_no_vpath = 0, temp;
  3104. u32 txdl_size, txdl_per_memblock;
  3105. temp = driver_config->vpath_per_dev;
  3106. if ((driver_config->vpath_per_dev == VXGE_USE_DEFAULT) &&
  3107. (max_config_dev == VXGE_MAX_CONFIG_DEV)) {
  3108. /* No more CPU. Return vpath number as zero.*/
  3109. if (driver_config->g_no_cpus == -1)
  3110. return 0;
  3111. if (!driver_config->g_no_cpus)
  3112. driver_config->g_no_cpus = num_online_cpus();
  3113. driver_config->vpath_per_dev = driver_config->g_no_cpus >> 1;
  3114. if (!driver_config->vpath_per_dev)
  3115. driver_config->vpath_per_dev = 1;
  3116. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
  3117. if (!vxge_bVALn(vpath_mask, i, 1))
  3118. continue;
  3119. else
  3120. default_no_vpath++;
  3121. if (default_no_vpath < driver_config->vpath_per_dev)
  3122. driver_config->vpath_per_dev = default_no_vpath;
  3123. driver_config->g_no_cpus = driver_config->g_no_cpus -
  3124. (driver_config->vpath_per_dev * 2);
  3125. if (driver_config->g_no_cpus <= 0)
  3126. driver_config->g_no_cpus = -1;
  3127. }
  3128. if (driver_config->vpath_per_dev == 1) {
  3129. vxge_debug_ll_config(VXGE_TRACE,
  3130. "%s: Disable tx and rx steering, "
  3131. "as single vpath is configured", VXGE_DRIVER_NAME);
  3132. config_param->rth_steering = NO_STEERING;
  3133. config_param->tx_steering_type = NO_STEERING;
  3134. device_config->rth_en = 0;
  3135. }
  3136. /* configure bandwidth */
  3137. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
  3138. device_config->vp_config[i].min_bandwidth = bw_percentage[i];
  3139. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
  3140. device_config->vp_config[i].vp_id = i;
  3141. device_config->vp_config[i].mtu = VXGE_HW_DEFAULT_MTU;
  3142. if (no_of_vpaths < driver_config->vpath_per_dev) {
  3143. if (!vxge_bVALn(vpath_mask, i, 1)) {
  3144. vxge_debug_ll_config(VXGE_TRACE,
  3145. "%s: vpath: %d is not available",
  3146. VXGE_DRIVER_NAME, i);
  3147. continue;
  3148. } else {
  3149. vxge_debug_ll_config(VXGE_TRACE,
  3150. "%s: vpath: %d available",
  3151. VXGE_DRIVER_NAME, i);
  3152. no_of_vpaths++;
  3153. }
  3154. } else {
  3155. vxge_debug_ll_config(VXGE_TRACE,
  3156. "%s: vpath: %d is not configured, "
  3157. "max_config_vpath exceeded",
  3158. VXGE_DRIVER_NAME, i);
  3159. break;
  3160. }
  3161. /* Configure Tx fifo's */
  3162. device_config->vp_config[i].fifo.enable =
  3163. VXGE_HW_FIFO_ENABLE;
  3164. device_config->vp_config[i].fifo.max_frags =
  3165. MAX_SKB_FRAGS + 1;
  3166. device_config->vp_config[i].fifo.memblock_size =
  3167. VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE;
  3168. txdl_size = device_config->vp_config[i].fifo.max_frags *
  3169. sizeof(struct vxge_hw_fifo_txd);
  3170. txdl_per_memblock = VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE / txdl_size;
  3171. device_config->vp_config[i].fifo.fifo_blocks =
  3172. ((VXGE_DEF_FIFO_LENGTH - 1) / txdl_per_memblock) + 1;
  3173. device_config->vp_config[i].fifo.intr =
  3174. VXGE_HW_FIFO_QUEUE_INTR_DISABLE;
  3175. /* Configure tti properties */
  3176. device_config->vp_config[i].tti.intr_enable =
  3177. VXGE_HW_TIM_INTR_ENABLE;
  3178. device_config->vp_config[i].tti.btimer_val =
  3179. (VXGE_TTI_BTIMER_VAL * 1000) / 272;
  3180. device_config->vp_config[i].tti.timer_ac_en =
  3181. VXGE_HW_TIM_TIMER_AC_ENABLE;
  3182. /* For msi-x with napi (each vector has a handler of its own) -
  3183. * Set CI to OFF for all vpaths
  3184. */
  3185. device_config->vp_config[i].tti.timer_ci_en =
  3186. VXGE_HW_TIM_TIMER_CI_DISABLE;
  3187. device_config->vp_config[i].tti.timer_ri_en =
  3188. VXGE_HW_TIM_TIMER_RI_DISABLE;
  3189. device_config->vp_config[i].tti.util_sel =
  3190. VXGE_HW_TIM_UTIL_SEL_LEGACY_TX_NET_UTIL;
  3191. device_config->vp_config[i].tti.ltimer_val =
  3192. (VXGE_TTI_LTIMER_VAL * 1000) / 272;
  3193. device_config->vp_config[i].tti.rtimer_val =
  3194. (VXGE_TTI_RTIMER_VAL * 1000) / 272;
  3195. device_config->vp_config[i].tti.urange_a = TTI_TX_URANGE_A;
  3196. device_config->vp_config[i].tti.urange_b = TTI_TX_URANGE_B;
  3197. device_config->vp_config[i].tti.urange_c = TTI_TX_URANGE_C;
  3198. device_config->vp_config[i].tti.uec_a = TTI_TX_UFC_A;
  3199. device_config->vp_config[i].tti.uec_b = TTI_TX_UFC_B;
  3200. device_config->vp_config[i].tti.uec_c = TTI_TX_UFC_C;
  3201. device_config->vp_config[i].tti.uec_d = TTI_TX_UFC_D;
  3202. /* Configure Rx rings */
  3203. device_config->vp_config[i].ring.enable =
  3204. VXGE_HW_RING_ENABLE;
  3205. device_config->vp_config[i].ring.ring_blocks =
  3206. VXGE_HW_DEF_RING_BLOCKS;
  3207. device_config->vp_config[i].ring.buffer_mode =
  3208. VXGE_HW_RING_RXD_BUFFER_MODE_1;
  3209. device_config->vp_config[i].ring.rxds_limit =
  3210. VXGE_HW_DEF_RING_RXDS_LIMIT;
  3211. device_config->vp_config[i].ring.scatter_mode =
  3212. VXGE_HW_RING_SCATTER_MODE_A;
  3213. /* Configure rti properties */
  3214. device_config->vp_config[i].rti.intr_enable =
  3215. VXGE_HW_TIM_INTR_ENABLE;
  3216. device_config->vp_config[i].rti.btimer_val =
  3217. (VXGE_RTI_BTIMER_VAL * 1000)/272;
  3218. device_config->vp_config[i].rti.timer_ac_en =
  3219. VXGE_HW_TIM_TIMER_AC_ENABLE;
  3220. device_config->vp_config[i].rti.timer_ci_en =
  3221. VXGE_HW_TIM_TIMER_CI_DISABLE;
  3222. device_config->vp_config[i].rti.timer_ri_en =
  3223. VXGE_HW_TIM_TIMER_RI_DISABLE;
  3224. device_config->vp_config[i].rti.util_sel =
  3225. VXGE_HW_TIM_UTIL_SEL_LEGACY_RX_NET_UTIL;
  3226. device_config->vp_config[i].rti.urange_a =
  3227. RTI_RX_URANGE_A;
  3228. device_config->vp_config[i].rti.urange_b =
  3229. RTI_RX_URANGE_B;
  3230. device_config->vp_config[i].rti.urange_c =
  3231. RTI_RX_URANGE_C;
  3232. device_config->vp_config[i].rti.uec_a = RTI_RX_UFC_A;
  3233. device_config->vp_config[i].rti.uec_b = RTI_RX_UFC_B;
  3234. device_config->vp_config[i].rti.uec_c = RTI_RX_UFC_C;
  3235. device_config->vp_config[i].rti.uec_d = RTI_RX_UFC_D;
  3236. device_config->vp_config[i].rti.rtimer_val =
  3237. (VXGE_RTI_RTIMER_VAL * 1000) / 272;
  3238. device_config->vp_config[i].rti.ltimer_val =
  3239. (VXGE_RTI_LTIMER_VAL * 1000) / 272;
  3240. device_config->vp_config[i].rpa_strip_vlan_tag =
  3241. vlan_tag_strip;
  3242. }
  3243. driver_config->vpath_per_dev = temp;
  3244. return no_of_vpaths;
  3245. }
  3246. /* initialize device configuratrions */
  3247. static void __devinit vxge_device_config_init(
  3248. struct vxge_hw_device_config *device_config,
  3249. int *intr_type)
  3250. {
  3251. /* Used for CQRQ/SRQ. */
  3252. device_config->dma_blockpool_initial =
  3253. VXGE_HW_INITIAL_DMA_BLOCK_POOL_SIZE;
  3254. device_config->dma_blockpool_max =
  3255. VXGE_HW_MAX_DMA_BLOCK_POOL_SIZE;
  3256. if (max_mac_vpath > VXGE_MAX_MAC_ADDR_COUNT)
  3257. max_mac_vpath = VXGE_MAX_MAC_ADDR_COUNT;
  3258. #ifndef CONFIG_PCI_MSI
  3259. vxge_debug_init(VXGE_ERR,
  3260. "%s: This Kernel does not support "
  3261. "MSI-X. Defaulting to INTA", VXGE_DRIVER_NAME);
  3262. *intr_type = INTA;
  3263. #endif
  3264. /* Configure whether MSI-X or IRQL. */
  3265. switch (*intr_type) {
  3266. case INTA:
  3267. device_config->intr_mode = VXGE_HW_INTR_MODE_IRQLINE;
  3268. break;
  3269. case MSI_X:
  3270. device_config->intr_mode = VXGE_HW_INTR_MODE_MSIX_ONE_SHOT;
  3271. break;
  3272. }
  3273. /* Timer period between device poll */
  3274. device_config->device_poll_millis = VXGE_TIMER_DELAY;
  3275. /* Configure mac based steering. */
  3276. device_config->rts_mac_en = addr_learn_en;
  3277. /* Configure Vpaths */
  3278. device_config->rth_it_type = VXGE_HW_RTH_IT_TYPE_MULTI_IT;
  3279. vxge_debug_ll_config(VXGE_TRACE, "%s : Device Config Params ",
  3280. __func__);
  3281. vxge_debug_ll_config(VXGE_TRACE, "intr_mode : %d",
  3282. device_config->intr_mode);
  3283. vxge_debug_ll_config(VXGE_TRACE, "device_poll_millis : %d",
  3284. device_config->device_poll_millis);
  3285. vxge_debug_ll_config(VXGE_TRACE, "rth_en : %d",
  3286. device_config->rth_en);
  3287. vxge_debug_ll_config(VXGE_TRACE, "rth_it_type : %d",
  3288. device_config->rth_it_type);
  3289. }
  3290. static void __devinit vxge_print_parm(struct vxgedev *vdev, u64 vpath_mask)
  3291. {
  3292. int i;
  3293. vxge_debug_init(VXGE_TRACE,
  3294. "%s: %d Vpath(s) opened",
  3295. vdev->ndev->name, vdev->no_of_vpath);
  3296. switch (vdev->config.intr_type) {
  3297. case INTA:
  3298. vxge_debug_init(VXGE_TRACE,
  3299. "%s: Interrupt type INTA", vdev->ndev->name);
  3300. break;
  3301. case MSI_X:
  3302. vxge_debug_init(VXGE_TRACE,
  3303. "%s: Interrupt type MSI-X", vdev->ndev->name);
  3304. break;
  3305. }
  3306. if (vdev->config.rth_steering) {
  3307. vxge_debug_init(VXGE_TRACE,
  3308. "%s: RTH steering enabled for TCP_IPV4",
  3309. vdev->ndev->name);
  3310. } else {
  3311. vxge_debug_init(VXGE_TRACE,
  3312. "%s: RTH steering disabled", vdev->ndev->name);
  3313. }
  3314. switch (vdev->config.tx_steering_type) {
  3315. case NO_STEERING:
  3316. vxge_debug_init(VXGE_TRACE,
  3317. "%s: Tx steering disabled", vdev->ndev->name);
  3318. break;
  3319. case TX_PRIORITY_STEERING:
  3320. vxge_debug_init(VXGE_TRACE,
  3321. "%s: Unsupported tx steering option",
  3322. vdev->ndev->name);
  3323. vxge_debug_init(VXGE_TRACE,
  3324. "%s: Tx steering disabled", vdev->ndev->name);
  3325. vdev->config.tx_steering_type = 0;
  3326. break;
  3327. case TX_VLAN_STEERING:
  3328. vxge_debug_init(VXGE_TRACE,
  3329. "%s: Unsupported tx steering option",
  3330. vdev->ndev->name);
  3331. vxge_debug_init(VXGE_TRACE,
  3332. "%s: Tx steering disabled", vdev->ndev->name);
  3333. vdev->config.tx_steering_type = 0;
  3334. break;
  3335. case TX_MULTIQ_STEERING:
  3336. vxge_debug_init(VXGE_TRACE,
  3337. "%s: Tx multiqueue steering enabled",
  3338. vdev->ndev->name);
  3339. break;
  3340. case TX_PORT_STEERING:
  3341. vxge_debug_init(VXGE_TRACE,
  3342. "%s: Tx port steering enabled",
  3343. vdev->ndev->name);
  3344. break;
  3345. default:
  3346. vxge_debug_init(VXGE_ERR,
  3347. "%s: Unsupported tx steering type",
  3348. vdev->ndev->name);
  3349. vxge_debug_init(VXGE_TRACE,
  3350. "%s: Tx steering disabled", vdev->ndev->name);
  3351. vdev->config.tx_steering_type = 0;
  3352. }
  3353. if (vdev->config.addr_learn_en)
  3354. vxge_debug_init(VXGE_TRACE,
  3355. "%s: MAC Address learning enabled", vdev->ndev->name);
  3356. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
  3357. if (!vxge_bVALn(vpath_mask, i, 1))
  3358. continue;
  3359. vxge_debug_ll_config(VXGE_TRACE,
  3360. "%s: MTU size - %d", vdev->ndev->name,
  3361. ((vdev->devh))->
  3362. config.vp_config[i].mtu);
  3363. vxge_debug_init(VXGE_TRACE,
  3364. "%s: VLAN tag stripping %s", vdev->ndev->name,
  3365. ((vdev->devh))->
  3366. config.vp_config[i].rpa_strip_vlan_tag
  3367. ? "Enabled" : "Disabled");
  3368. vxge_debug_ll_config(VXGE_TRACE,
  3369. "%s: Max frags : %d", vdev->ndev->name,
  3370. ((vdev->devh))->
  3371. config.vp_config[i].fifo.max_frags);
  3372. break;
  3373. }
  3374. }
  3375. #ifdef CONFIG_PM
  3376. /**
  3377. * vxge_pm_suspend - vxge power management suspend entry point
  3378. *
  3379. */
  3380. static int vxge_pm_suspend(struct pci_dev *pdev, pm_message_t state)
  3381. {
  3382. return -ENOSYS;
  3383. }
  3384. /**
  3385. * vxge_pm_resume - vxge power management resume entry point
  3386. *
  3387. */
  3388. static int vxge_pm_resume(struct pci_dev *pdev)
  3389. {
  3390. return -ENOSYS;
  3391. }
  3392. #endif
  3393. /**
  3394. * vxge_io_error_detected - called when PCI error is detected
  3395. * @pdev: Pointer to PCI device
  3396. * @state: The current pci connection state
  3397. *
  3398. * This function is called after a PCI bus error affecting
  3399. * this device has been detected.
  3400. */
  3401. static pci_ers_result_t vxge_io_error_detected(struct pci_dev *pdev,
  3402. pci_channel_state_t state)
  3403. {
  3404. struct __vxge_hw_device *hldev = pci_get_drvdata(pdev);
  3405. struct net_device *netdev = hldev->ndev;
  3406. netif_device_detach(netdev);
  3407. if (state == pci_channel_io_perm_failure)
  3408. return PCI_ERS_RESULT_DISCONNECT;
  3409. if (netif_running(netdev)) {
  3410. /* Bring down the card, while avoiding PCI I/O */
  3411. do_vxge_close(netdev, 0);
  3412. }
  3413. pci_disable_device(pdev);
  3414. return PCI_ERS_RESULT_NEED_RESET;
  3415. }
  3416. /**
  3417. * vxge_io_slot_reset - called after the pci bus has been reset.
  3418. * @pdev: Pointer to PCI device
  3419. *
  3420. * Restart the card from scratch, as if from a cold-boot.
  3421. * At this point, the card has exprienced a hard reset,
  3422. * followed by fixups by BIOS, and has its config space
  3423. * set up identically to what it was at cold boot.
  3424. */
  3425. static pci_ers_result_t vxge_io_slot_reset(struct pci_dev *pdev)
  3426. {
  3427. struct __vxge_hw_device *hldev = pci_get_drvdata(pdev);
  3428. struct net_device *netdev = hldev->ndev;
  3429. struct vxgedev *vdev = netdev_priv(netdev);
  3430. if (pci_enable_device(pdev)) {
  3431. netdev_err(netdev, "Cannot re-enable device after reset\n");
  3432. return PCI_ERS_RESULT_DISCONNECT;
  3433. }
  3434. pci_set_master(pdev);
  3435. do_vxge_reset(vdev, VXGE_LL_FULL_RESET);
  3436. return PCI_ERS_RESULT_RECOVERED;
  3437. }
  3438. /**
  3439. * vxge_io_resume - called when traffic can start flowing again.
  3440. * @pdev: Pointer to PCI device
  3441. *
  3442. * This callback is called when the error recovery driver tells
  3443. * us that its OK to resume normal operation.
  3444. */
  3445. static void vxge_io_resume(struct pci_dev *pdev)
  3446. {
  3447. struct __vxge_hw_device *hldev = pci_get_drvdata(pdev);
  3448. struct net_device *netdev = hldev->ndev;
  3449. if (netif_running(netdev)) {
  3450. if (vxge_open(netdev)) {
  3451. netdev_err(netdev,
  3452. "Can't bring device back up after reset\n");
  3453. return;
  3454. }
  3455. }
  3456. netif_device_attach(netdev);
  3457. }
  3458. static inline u32 vxge_get_num_vfs(u64 function_mode)
  3459. {
  3460. u32 num_functions = 0;
  3461. switch (function_mode) {
  3462. case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION:
  3463. case VXGE_HW_FUNCTION_MODE_SRIOV_8:
  3464. num_functions = 8;
  3465. break;
  3466. case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION:
  3467. num_functions = 1;
  3468. break;
  3469. case VXGE_HW_FUNCTION_MODE_SRIOV:
  3470. case VXGE_HW_FUNCTION_MODE_MRIOV:
  3471. case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION_17:
  3472. num_functions = 17;
  3473. break;
  3474. case VXGE_HW_FUNCTION_MODE_SRIOV_4:
  3475. num_functions = 4;
  3476. break;
  3477. case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION_2:
  3478. num_functions = 2;
  3479. break;
  3480. case VXGE_HW_FUNCTION_MODE_MRIOV_8:
  3481. num_functions = 8; /* TODO */
  3482. break;
  3483. }
  3484. return num_functions;
  3485. }
  3486. int vxge_fw_upgrade(struct vxgedev *vdev, char *fw_name, int override)
  3487. {
  3488. struct __vxge_hw_device *hldev = vdev->devh;
  3489. u32 maj, min, bld, cmaj, cmin, cbld;
  3490. enum vxge_hw_status status;
  3491. const struct firmware *fw;
  3492. int ret;
  3493. ret = request_firmware(&fw, fw_name, &vdev->pdev->dev);
  3494. if (ret) {
  3495. vxge_debug_init(VXGE_ERR, "%s: Firmware file '%s' not found",
  3496. VXGE_DRIVER_NAME, fw_name);
  3497. goto out;
  3498. }
  3499. /* Load the new firmware onto the adapter */
  3500. status = vxge_update_fw_image(hldev, fw->data, fw->size);
  3501. if (status != VXGE_HW_OK) {
  3502. vxge_debug_init(VXGE_ERR,
  3503. "%s: FW image download to adapter failed '%s'.",
  3504. VXGE_DRIVER_NAME, fw_name);
  3505. ret = -EIO;
  3506. goto out;
  3507. }
  3508. /* Read the version of the new firmware */
  3509. status = vxge_hw_upgrade_read_version(hldev, &maj, &min, &bld);
  3510. if (status != VXGE_HW_OK) {
  3511. vxge_debug_init(VXGE_ERR,
  3512. "%s: Upgrade read version failed '%s'.",
  3513. VXGE_DRIVER_NAME, fw_name);
  3514. ret = -EIO;
  3515. goto out;
  3516. }
  3517. cmaj = vdev->config.device_hw_info.fw_version.major;
  3518. cmin = vdev->config.device_hw_info.fw_version.minor;
  3519. cbld = vdev->config.device_hw_info.fw_version.build;
  3520. /* It's possible the version in /lib/firmware is not the latest version.
  3521. * If so, we could get into a loop of trying to upgrade to the latest
  3522. * and flashing the older version.
  3523. */
  3524. if (VXGE_FW_VER(maj, min, bld) == VXGE_FW_VER(cmaj, cmin, cbld) &&
  3525. !override) {
  3526. ret = -EINVAL;
  3527. goto out;
  3528. }
  3529. printk(KERN_NOTICE "Upgrade to firmware version %d.%d.%d commencing\n",
  3530. maj, min, bld);
  3531. /* Flash the adapter with the new firmware */
  3532. status = vxge_hw_flash_fw(hldev);
  3533. if (status != VXGE_HW_OK) {
  3534. vxge_debug_init(VXGE_ERR, "%s: Upgrade commit failed '%s'.",
  3535. VXGE_DRIVER_NAME, fw_name);
  3536. ret = -EIO;
  3537. goto out;
  3538. }
  3539. printk(KERN_NOTICE "Upgrade of firmware successful! Adapter must be "
  3540. "hard reset before using, thus requiring a system reboot or a "
  3541. "hotplug event.\n");
  3542. out:
  3543. release_firmware(fw);
  3544. return ret;
  3545. }
  3546. static int vxge_probe_fw_update(struct vxgedev *vdev)
  3547. {
  3548. u32 maj, min, bld;
  3549. int ret, gpxe = 0;
  3550. char *fw_name;
  3551. maj = vdev->config.device_hw_info.fw_version.major;
  3552. min = vdev->config.device_hw_info.fw_version.minor;
  3553. bld = vdev->config.device_hw_info.fw_version.build;
  3554. if (VXGE_FW_VER(maj, min, bld) == VXGE_CERT_FW_VER)
  3555. return 0;
  3556. /* Ignore the build number when determining if the current firmware is
  3557. * "too new" to load the driver
  3558. */
  3559. if (VXGE_FW_VER(maj, min, 0) > VXGE_CERT_FW_VER) {
  3560. vxge_debug_init(VXGE_ERR, "%s: Firmware newer than last known "
  3561. "version, unable to load driver\n",
  3562. VXGE_DRIVER_NAME);
  3563. return -EINVAL;
  3564. }
  3565. /* Firmware 1.4.4 and older cannot be upgraded, and is too ancient to
  3566. * work with this driver.
  3567. */
  3568. if (VXGE_FW_VER(maj, min, bld) <= VXGE_FW_DEAD_VER) {
  3569. vxge_debug_init(VXGE_ERR, "%s: Firmware %d.%d.%d cannot be "
  3570. "upgraded\n", VXGE_DRIVER_NAME, maj, min, bld);
  3571. return -EINVAL;
  3572. }
  3573. /* If file not specified, determine gPXE or not */
  3574. if (VXGE_FW_VER(maj, min, bld) >= VXGE_EPROM_FW_VER) {
  3575. int i;
  3576. for (i = 0; i < VXGE_HW_MAX_ROM_IMAGES; i++)
  3577. if (vdev->devh->eprom_versions[i]) {
  3578. gpxe = 1;
  3579. break;
  3580. }
  3581. }
  3582. if (gpxe)
  3583. fw_name = "vxge/X3fw-pxe.ncf";
  3584. else
  3585. fw_name = "vxge/X3fw.ncf";
  3586. ret = vxge_fw_upgrade(vdev, fw_name, 0);
  3587. /* -EINVAL and -ENOENT are not fatal errors for flashing firmware on
  3588. * probe, so ignore them
  3589. */
  3590. if (ret != -EINVAL && ret != -ENOENT)
  3591. return -EIO;
  3592. else
  3593. ret = 0;
  3594. if (VXGE_FW_VER(VXGE_CERT_FW_VER_MAJOR, VXGE_CERT_FW_VER_MINOR, 0) >
  3595. VXGE_FW_VER(maj, min, 0)) {
  3596. vxge_debug_init(VXGE_ERR, "%s: Firmware %d.%d.%d is too old to"
  3597. " be used with this driver.\n"
  3598. "Please get the latest version from "
  3599. "ftp://ftp.s2io.com/pub/X3100-Drivers/FIRMWARE",
  3600. VXGE_DRIVER_NAME, maj, min, bld);
  3601. return -EINVAL;
  3602. }
  3603. return ret;
  3604. }
  3605. static int __devinit is_sriov_initialized(struct pci_dev *pdev)
  3606. {
  3607. int pos;
  3608. u16 ctrl;
  3609. pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
  3610. if (pos) {
  3611. pci_read_config_word(pdev, pos + PCI_SRIOV_CTRL, &ctrl);
  3612. if (ctrl & PCI_SRIOV_CTRL_VFE)
  3613. return 1;
  3614. }
  3615. return 0;
  3616. }
  3617. static const struct vxge_hw_uld_cbs vxge_callbacks = {
  3618. .link_up = vxge_callback_link_up,
  3619. .link_down = vxge_callback_link_down,
  3620. .crit_err = vxge_callback_crit_err,
  3621. };
  3622. /**
  3623. * vxge_probe
  3624. * @pdev : structure containing the PCI related information of the device.
  3625. * @pre: List of PCI devices supported by the driver listed in vxge_id_table.
  3626. * Description:
  3627. * This function is called when a new PCI device gets detected and initializes
  3628. * it.
  3629. * Return value:
  3630. * returns 0 on success and negative on failure.
  3631. *
  3632. */
  3633. static int __devinit
  3634. vxge_probe(struct pci_dev *pdev, const struct pci_device_id *pre)
  3635. {
  3636. struct __vxge_hw_device *hldev;
  3637. enum vxge_hw_status status;
  3638. int ret;
  3639. int high_dma = 0;
  3640. u64 vpath_mask = 0;
  3641. struct vxgedev *vdev;
  3642. struct vxge_config *ll_config = NULL;
  3643. struct vxge_hw_device_config *device_config = NULL;
  3644. struct vxge_hw_device_attr attr;
  3645. int i, j, no_of_vpath = 0, max_vpath_supported = 0;
  3646. u8 *macaddr;
  3647. struct vxge_mac_addrs *entry;
  3648. static int bus = -1, device = -1;
  3649. u32 host_type;
  3650. u8 new_device = 0;
  3651. enum vxge_hw_status is_privileged;
  3652. u32 function_mode;
  3653. u32 num_vfs = 0;
  3654. vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
  3655. attr.pdev = pdev;
  3656. /* In SRIOV-17 mode, functions of the same adapter
  3657. * can be deployed on different buses
  3658. */
  3659. if (((bus != pdev->bus->number) || (device != PCI_SLOT(pdev->devfn))) &&
  3660. !pdev->is_virtfn)
  3661. new_device = 1;
  3662. bus = pdev->bus->number;
  3663. device = PCI_SLOT(pdev->devfn);
  3664. if (new_device) {
  3665. if (driver_config->config_dev_cnt &&
  3666. (driver_config->config_dev_cnt !=
  3667. driver_config->total_dev_cnt))
  3668. vxge_debug_init(VXGE_ERR,
  3669. "%s: Configured %d of %d devices",
  3670. VXGE_DRIVER_NAME,
  3671. driver_config->config_dev_cnt,
  3672. driver_config->total_dev_cnt);
  3673. driver_config->config_dev_cnt = 0;
  3674. driver_config->total_dev_cnt = 0;
  3675. }
  3676. /* Now making the CPU based no of vpath calculation
  3677. * applicable for individual functions as well.
  3678. */
  3679. driver_config->g_no_cpus = 0;
  3680. driver_config->vpath_per_dev = max_config_vpath;
  3681. driver_config->total_dev_cnt++;
  3682. if (++driver_config->config_dev_cnt > max_config_dev) {
  3683. ret = 0;
  3684. goto _exit0;
  3685. }
  3686. device_config = kzalloc(sizeof(struct vxge_hw_device_config),
  3687. GFP_KERNEL);
  3688. if (!device_config) {
  3689. ret = -ENOMEM;
  3690. vxge_debug_init(VXGE_ERR,
  3691. "device_config : malloc failed %s %d",
  3692. __FILE__, __LINE__);
  3693. goto _exit0;
  3694. }
  3695. ll_config = kzalloc(sizeof(struct vxge_config), GFP_KERNEL);
  3696. if (!ll_config) {
  3697. ret = -ENOMEM;
  3698. vxge_debug_init(VXGE_ERR,
  3699. "device_config : malloc failed %s %d",
  3700. __FILE__, __LINE__);
  3701. goto _exit0;
  3702. }
  3703. ll_config->tx_steering_type = TX_MULTIQ_STEERING;
  3704. ll_config->intr_type = MSI_X;
  3705. ll_config->napi_weight = NEW_NAPI_WEIGHT;
  3706. ll_config->rth_steering = RTH_STEERING;
  3707. /* get the default configuration parameters */
  3708. vxge_hw_device_config_default_get(device_config);
  3709. /* initialize configuration parameters */
  3710. vxge_device_config_init(device_config, &ll_config->intr_type);
  3711. ret = pci_enable_device(pdev);
  3712. if (ret) {
  3713. vxge_debug_init(VXGE_ERR,
  3714. "%s : can not enable PCI device", __func__);
  3715. goto _exit0;
  3716. }
  3717. if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
  3718. vxge_debug_ll_config(VXGE_TRACE,
  3719. "%s : using 64bit DMA", __func__);
  3720. high_dma = 1;
  3721. if (pci_set_consistent_dma_mask(pdev,
  3722. DMA_BIT_MASK(64))) {
  3723. vxge_debug_init(VXGE_ERR,
  3724. "%s : unable to obtain 64bit DMA for "
  3725. "consistent allocations", __func__);
  3726. ret = -ENOMEM;
  3727. goto _exit1;
  3728. }
  3729. } else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
  3730. vxge_debug_ll_config(VXGE_TRACE,
  3731. "%s : using 32bit DMA", __func__);
  3732. } else {
  3733. ret = -ENOMEM;
  3734. goto _exit1;
  3735. }
  3736. ret = pci_request_region(pdev, 0, VXGE_DRIVER_NAME);
  3737. if (ret) {
  3738. vxge_debug_init(VXGE_ERR,
  3739. "%s : request regions failed", __func__);
  3740. goto _exit1;
  3741. }
  3742. pci_set_master(pdev);
  3743. attr.bar0 = pci_ioremap_bar(pdev, 0);
  3744. if (!attr.bar0) {
  3745. vxge_debug_init(VXGE_ERR,
  3746. "%s : cannot remap io memory bar0", __func__);
  3747. ret = -ENODEV;
  3748. goto _exit2;
  3749. }
  3750. vxge_debug_ll_config(VXGE_TRACE,
  3751. "pci ioremap bar0: %p:0x%llx",
  3752. attr.bar0,
  3753. (unsigned long long)pci_resource_start(pdev, 0));
  3754. status = vxge_hw_device_hw_info_get(attr.bar0,
  3755. &ll_config->device_hw_info);
  3756. if (status != VXGE_HW_OK) {
  3757. vxge_debug_init(VXGE_ERR,
  3758. "%s: Reading of hardware info failed."
  3759. "Please try upgrading the firmware.", VXGE_DRIVER_NAME);
  3760. ret = -EINVAL;
  3761. goto _exit3;
  3762. }
  3763. vpath_mask = ll_config->device_hw_info.vpath_mask;
  3764. if (vpath_mask == 0) {
  3765. vxge_debug_ll_config(VXGE_TRACE,
  3766. "%s: No vpaths available in device", VXGE_DRIVER_NAME);
  3767. ret = -EINVAL;
  3768. goto _exit3;
  3769. }
  3770. vxge_debug_ll_config(VXGE_TRACE,
  3771. "%s:%d Vpath mask = %llx", __func__, __LINE__,
  3772. (unsigned long long)vpath_mask);
  3773. function_mode = ll_config->device_hw_info.function_mode;
  3774. host_type = ll_config->device_hw_info.host_type;
  3775. is_privileged = __vxge_hw_device_is_privilaged(host_type,
  3776. ll_config->device_hw_info.func_id);
  3777. /* Check how many vpaths are available */
  3778. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
  3779. if (!((vpath_mask) & vxge_mBIT(i)))
  3780. continue;
  3781. max_vpath_supported++;
  3782. }
  3783. if (new_device)
  3784. num_vfs = vxge_get_num_vfs(function_mode) - 1;
  3785. /* Enable SRIOV mode, if firmware has SRIOV support and if it is a PF */
  3786. if (is_sriov(function_mode) && !is_sriov_initialized(pdev) &&
  3787. (ll_config->intr_type != INTA)) {
  3788. ret = pci_enable_sriov(pdev, num_vfs);
  3789. if (ret)
  3790. vxge_debug_ll_config(VXGE_ERR,
  3791. "Failed in enabling SRIOV mode: %d\n", ret);
  3792. /* No need to fail out, as an error here is non-fatal */
  3793. }
  3794. /*
  3795. * Configure vpaths and get driver configured number of vpaths
  3796. * which is less than or equal to the maximum vpaths per function.
  3797. */
  3798. no_of_vpath = vxge_config_vpaths(device_config, vpath_mask, ll_config);
  3799. if (!no_of_vpath) {
  3800. vxge_debug_ll_config(VXGE_ERR,
  3801. "%s: No more vpaths to configure", VXGE_DRIVER_NAME);
  3802. ret = 0;
  3803. goto _exit3;
  3804. }
  3805. /* Setting driver callbacks */
  3806. attr.uld_callbacks = &vxge_callbacks;
  3807. status = vxge_hw_device_initialize(&hldev, &attr, device_config);
  3808. if (status != VXGE_HW_OK) {
  3809. vxge_debug_init(VXGE_ERR,
  3810. "Failed to initialize device (%d)", status);
  3811. ret = -EINVAL;
  3812. goto _exit3;
  3813. }
  3814. if (VXGE_FW_VER(ll_config->device_hw_info.fw_version.major,
  3815. ll_config->device_hw_info.fw_version.minor,
  3816. ll_config->device_hw_info.fw_version.build) >=
  3817. VXGE_EPROM_FW_VER) {
  3818. struct eprom_image img[VXGE_HW_MAX_ROM_IMAGES];
  3819. status = vxge_hw_vpath_eprom_img_ver_get(hldev, img);
  3820. if (status != VXGE_HW_OK) {
  3821. vxge_debug_init(VXGE_ERR, "%s: Reading of EPROM failed",
  3822. VXGE_DRIVER_NAME);
  3823. /* This is a non-fatal error, continue */
  3824. }
  3825. for (i = 0; i < VXGE_HW_MAX_ROM_IMAGES; i++) {
  3826. hldev->eprom_versions[i] = img[i].version;
  3827. if (!img[i].is_valid)
  3828. break;
  3829. vxge_debug_init(VXGE_TRACE, "%s: EPROM %d, version "
  3830. "%d.%d.%d.%d", VXGE_DRIVER_NAME, i,
  3831. VXGE_EPROM_IMG_MAJOR(img[i].version),
  3832. VXGE_EPROM_IMG_MINOR(img[i].version),
  3833. VXGE_EPROM_IMG_FIX(img[i].version),
  3834. VXGE_EPROM_IMG_BUILD(img[i].version));
  3835. }
  3836. }
  3837. /* if FCS stripping is not disabled in MAC fail driver load */
  3838. status = vxge_hw_vpath_strip_fcs_check(hldev, vpath_mask);
  3839. if (status != VXGE_HW_OK) {
  3840. vxge_debug_init(VXGE_ERR, "%s: FCS stripping is enabled in MAC"
  3841. " failing driver load", VXGE_DRIVER_NAME);
  3842. ret = -EINVAL;
  3843. goto _exit4;
  3844. }
  3845. /* Always enable HWTS. This will always cause the FCS to be invalid,
  3846. * due to the fact that HWTS is using the FCS as the location of the
  3847. * timestamp. The HW FCS checking will still correctly determine if
  3848. * there is a valid checksum, and the FCS is being removed by the driver
  3849. * anyway. So no fucntionality is being lost. Since it is always
  3850. * enabled, we now simply use the ioctl call to set whether or not the
  3851. * driver should be paying attention to the HWTS.
  3852. */
  3853. if (is_privileged == VXGE_HW_OK) {
  3854. status = vxge_timestamp_config(hldev);
  3855. if (status != VXGE_HW_OK) {
  3856. vxge_debug_init(VXGE_ERR, "%s: HWTS enable failed",
  3857. VXGE_DRIVER_NAME);
  3858. ret = -EFAULT;
  3859. goto _exit4;
  3860. }
  3861. }
  3862. vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_LL);
  3863. /* set private device info */
  3864. pci_set_drvdata(pdev, hldev);
  3865. ll_config->fifo_indicate_max_pkts = VXGE_FIFO_INDICATE_MAX_PKTS;
  3866. ll_config->addr_learn_en = addr_learn_en;
  3867. ll_config->rth_algorithm = RTH_ALG_JENKINS;
  3868. ll_config->rth_hash_type_tcpipv4 = 1;
  3869. ll_config->rth_hash_type_ipv4 = 0;
  3870. ll_config->rth_hash_type_tcpipv6 = 0;
  3871. ll_config->rth_hash_type_ipv6 = 0;
  3872. ll_config->rth_hash_type_tcpipv6ex = 0;
  3873. ll_config->rth_hash_type_ipv6ex = 0;
  3874. ll_config->rth_bkt_sz = RTH_BUCKET_SIZE;
  3875. ll_config->tx_pause_enable = VXGE_PAUSE_CTRL_ENABLE;
  3876. ll_config->rx_pause_enable = VXGE_PAUSE_CTRL_ENABLE;
  3877. ret = vxge_device_register(hldev, ll_config, high_dma, no_of_vpath,
  3878. &vdev);
  3879. if (ret) {
  3880. ret = -EINVAL;
  3881. goto _exit4;
  3882. }
  3883. ret = vxge_probe_fw_update(vdev);
  3884. if (ret)
  3885. goto _exit5;
  3886. vxge_hw_device_debug_set(hldev, VXGE_TRACE, VXGE_COMPONENT_LL);
  3887. VXGE_COPY_DEBUG_INFO_TO_LL(vdev, vxge_hw_device_error_level_get(hldev),
  3888. vxge_hw_device_trace_level_get(hldev));
  3889. /* set private HW device info */
  3890. vdev->mtu = VXGE_HW_DEFAULT_MTU;
  3891. vdev->bar0 = attr.bar0;
  3892. vdev->max_vpath_supported = max_vpath_supported;
  3893. vdev->no_of_vpath = no_of_vpath;
  3894. /* Virtual Path count */
  3895. for (i = 0, j = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
  3896. if (!vxge_bVALn(vpath_mask, i, 1))
  3897. continue;
  3898. if (j >= vdev->no_of_vpath)
  3899. break;
  3900. vdev->vpaths[j].is_configured = 1;
  3901. vdev->vpaths[j].device_id = i;
  3902. vdev->vpaths[j].ring.driver_id = j;
  3903. vdev->vpaths[j].vdev = vdev;
  3904. vdev->vpaths[j].max_mac_addr_cnt = max_mac_vpath;
  3905. memcpy((u8 *)vdev->vpaths[j].macaddr,
  3906. ll_config->device_hw_info.mac_addrs[i],
  3907. ETH_ALEN);
  3908. /* Initialize the mac address list header */
  3909. INIT_LIST_HEAD(&vdev->vpaths[j].mac_addr_list);
  3910. vdev->vpaths[j].mac_addr_cnt = 0;
  3911. vdev->vpaths[j].mcast_addr_cnt = 0;
  3912. j++;
  3913. }
  3914. vdev->exec_mode = VXGE_EXEC_MODE_DISABLE;
  3915. vdev->max_config_port = max_config_port;
  3916. vdev->vlan_tag_strip = vlan_tag_strip;
  3917. /* map the hashing selector table to the configured vpaths */
  3918. for (i = 0; i < vdev->no_of_vpath; i++)
  3919. vdev->vpath_selector[i] = vpath_selector[i];
  3920. macaddr = (u8 *)vdev->vpaths[0].macaddr;
  3921. ll_config->device_hw_info.serial_number[VXGE_HW_INFO_LEN - 1] = '\0';
  3922. ll_config->device_hw_info.product_desc[VXGE_HW_INFO_LEN - 1] = '\0';
  3923. ll_config->device_hw_info.part_number[VXGE_HW_INFO_LEN - 1] = '\0';
  3924. vxge_debug_init(VXGE_TRACE, "%s: SERIAL NUMBER: %s",
  3925. vdev->ndev->name, ll_config->device_hw_info.serial_number);
  3926. vxge_debug_init(VXGE_TRACE, "%s: PART NUMBER: %s",
  3927. vdev->ndev->name, ll_config->device_hw_info.part_number);
  3928. vxge_debug_init(VXGE_TRACE, "%s: Neterion %s Server Adapter",
  3929. vdev->ndev->name, ll_config->device_hw_info.product_desc);
  3930. vxge_debug_init(VXGE_TRACE, "%s: MAC ADDR: %pM",
  3931. vdev->ndev->name, macaddr);
  3932. vxge_debug_init(VXGE_TRACE, "%s: Link Width x%d",
  3933. vdev->ndev->name, vxge_hw_device_link_width_get(hldev));
  3934. vxge_debug_init(VXGE_TRACE,
  3935. "%s: Firmware version : %s Date : %s", vdev->ndev->name,
  3936. ll_config->device_hw_info.fw_version.version,
  3937. ll_config->device_hw_info.fw_date.date);
  3938. if (new_device) {
  3939. switch (ll_config->device_hw_info.function_mode) {
  3940. case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION:
  3941. vxge_debug_init(VXGE_TRACE,
  3942. "%s: Single Function Mode Enabled", vdev->ndev->name);
  3943. break;
  3944. case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION:
  3945. vxge_debug_init(VXGE_TRACE,
  3946. "%s: Multi Function Mode Enabled", vdev->ndev->name);
  3947. break;
  3948. case VXGE_HW_FUNCTION_MODE_SRIOV:
  3949. vxge_debug_init(VXGE_TRACE,
  3950. "%s: Single Root IOV Mode Enabled", vdev->ndev->name);
  3951. break;
  3952. case VXGE_HW_FUNCTION_MODE_MRIOV:
  3953. vxge_debug_init(VXGE_TRACE,
  3954. "%s: Multi Root IOV Mode Enabled", vdev->ndev->name);
  3955. break;
  3956. }
  3957. }
  3958. vxge_print_parm(vdev, vpath_mask);
  3959. /* Store the fw version for ethttool option */
  3960. strcpy(vdev->fw_version, ll_config->device_hw_info.fw_version.version);
  3961. memcpy(vdev->ndev->dev_addr, (u8 *)vdev->vpaths[0].macaddr, ETH_ALEN);
  3962. memcpy(vdev->ndev->perm_addr, vdev->ndev->dev_addr, ETH_ALEN);
  3963. /* Copy the station mac address to the list */
  3964. for (i = 0; i < vdev->no_of_vpath; i++) {
  3965. entry = kzalloc(sizeof(struct vxge_mac_addrs), GFP_KERNEL);
  3966. if (NULL == entry) {
  3967. vxge_debug_init(VXGE_ERR,
  3968. "%s: mac_addr_list : memory allocation failed",
  3969. vdev->ndev->name);
  3970. ret = -EPERM;
  3971. goto _exit6;
  3972. }
  3973. macaddr = (u8 *)&entry->macaddr;
  3974. memcpy(macaddr, vdev->ndev->dev_addr, ETH_ALEN);
  3975. list_add(&entry->item, &vdev->vpaths[i].mac_addr_list);
  3976. vdev->vpaths[i].mac_addr_cnt = 1;
  3977. }
  3978. kfree(device_config);
  3979. /*
  3980. * INTA is shared in multi-function mode. This is unlike the INTA
  3981. * implementation in MR mode, where each VH has its own INTA message.
  3982. * - INTA is masked (disabled) as long as at least one function sets
  3983. * its TITAN_MASK_ALL_INT.ALARM bit.
  3984. * - INTA is unmasked (enabled) when all enabled functions have cleared
  3985. * their own TITAN_MASK_ALL_INT.ALARM bit.
  3986. * The TITAN_MASK_ALL_INT ALARM & TRAFFIC bits are cleared on power up.
  3987. * Though this driver leaves the top level interrupts unmasked while
  3988. * leaving the required module interrupt bits masked on exit, there
  3989. * could be a rougue driver around that does not follow this procedure
  3990. * resulting in a failure to generate interrupts. The following code is
  3991. * present to prevent such a failure.
  3992. */
  3993. if (ll_config->device_hw_info.function_mode ==
  3994. VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION)
  3995. if (vdev->config.intr_type == INTA)
  3996. vxge_hw_device_unmask_all(hldev);
  3997. vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...",
  3998. vdev->ndev->name, __func__, __LINE__);
  3999. vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_LL);
  4000. VXGE_COPY_DEBUG_INFO_TO_LL(vdev, vxge_hw_device_error_level_get(hldev),
  4001. vxge_hw_device_trace_level_get(hldev));
  4002. kfree(ll_config);
  4003. return 0;
  4004. _exit6:
  4005. for (i = 0; i < vdev->no_of_vpath; i++)
  4006. vxge_free_mac_add_list(&vdev->vpaths[i]);
  4007. _exit5:
  4008. vxge_device_unregister(hldev);
  4009. _exit4:
  4010. pci_set_drvdata(pdev, NULL);
  4011. vxge_hw_device_terminate(hldev);
  4012. pci_disable_sriov(pdev);
  4013. _exit3:
  4014. iounmap(attr.bar0);
  4015. _exit2:
  4016. pci_release_region(pdev, 0);
  4017. _exit1:
  4018. pci_disable_device(pdev);
  4019. _exit0:
  4020. kfree(ll_config);
  4021. kfree(device_config);
  4022. driver_config->config_dev_cnt--;
  4023. driver_config->total_dev_cnt--;
  4024. return ret;
  4025. }
  4026. /**
  4027. * vxge_rem_nic - Free the PCI device
  4028. * @pdev: structure containing the PCI related information of the device.
  4029. * Description: This function is called by the Pci subsystem to release a
  4030. * PCI device and free up all resource held up by the device.
  4031. */
  4032. static void __devexit vxge_remove(struct pci_dev *pdev)
  4033. {
  4034. struct __vxge_hw_device *hldev;
  4035. struct vxgedev *vdev;
  4036. int i;
  4037. hldev = pci_get_drvdata(pdev);
  4038. if (hldev == NULL)
  4039. return;
  4040. vdev = netdev_priv(hldev->ndev);
  4041. vxge_debug_entryexit(vdev->level_trace, "%s:%d", __func__, __LINE__);
  4042. vxge_debug_init(vdev->level_trace, "%s : removing PCI device...",
  4043. __func__);
  4044. for (i = 0; i < vdev->no_of_vpath; i++)
  4045. vxge_free_mac_add_list(&vdev->vpaths[i]);
  4046. vxge_device_unregister(hldev);
  4047. pci_set_drvdata(pdev, NULL);
  4048. /* Do not call pci_disable_sriov here, as it will break child devices */
  4049. vxge_hw_device_terminate(hldev);
  4050. iounmap(vdev->bar0);
  4051. pci_release_region(pdev, 0);
  4052. pci_disable_device(pdev);
  4053. driver_config->config_dev_cnt--;
  4054. driver_config->total_dev_cnt--;
  4055. vxge_debug_init(vdev->level_trace, "%s:%d Device unregistered",
  4056. __func__, __LINE__);
  4057. vxge_debug_entryexit(vdev->level_trace, "%s:%d Exiting...", __func__,
  4058. __LINE__);
  4059. }
  4060. static struct pci_error_handlers vxge_err_handler = {
  4061. .error_detected = vxge_io_error_detected,
  4062. .slot_reset = vxge_io_slot_reset,
  4063. .resume = vxge_io_resume,
  4064. };
  4065. static struct pci_driver vxge_driver = {
  4066. .name = VXGE_DRIVER_NAME,
  4067. .id_table = vxge_id_table,
  4068. .probe = vxge_probe,
  4069. .remove = __devexit_p(vxge_remove),
  4070. #ifdef CONFIG_PM
  4071. .suspend = vxge_pm_suspend,
  4072. .resume = vxge_pm_resume,
  4073. #endif
  4074. .err_handler = &vxge_err_handler,
  4075. };
  4076. static int __init
  4077. vxge_starter(void)
  4078. {
  4079. int ret = 0;
  4080. pr_info("Copyright(c) 2002-2010 Exar Corp.\n");
  4081. pr_info("Driver version: %s\n", DRV_VERSION);
  4082. verify_bandwidth();
  4083. driver_config = kzalloc(sizeof(struct vxge_drv_config), GFP_KERNEL);
  4084. if (!driver_config)
  4085. return -ENOMEM;
  4086. ret = pci_register_driver(&vxge_driver);
  4087. if (ret) {
  4088. kfree(driver_config);
  4089. goto err;
  4090. }
  4091. if (driver_config->config_dev_cnt &&
  4092. (driver_config->config_dev_cnt != driver_config->total_dev_cnt))
  4093. vxge_debug_init(VXGE_ERR,
  4094. "%s: Configured %d of %d devices",
  4095. VXGE_DRIVER_NAME, driver_config->config_dev_cnt,
  4096. driver_config->total_dev_cnt);
  4097. err:
  4098. return ret;
  4099. }
  4100. static void __exit
  4101. vxge_closer(void)
  4102. {
  4103. pci_unregister_driver(&vxge_driver);
  4104. kfree(driver_config);
  4105. }
  4106. module_init(vxge_starter);
  4107. module_exit(vxge_closer);