vxge-main.c 118 KB

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