vxge-main.c 118 KB

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