vxge-main.c 117 KB

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