vxge-main.c 118 KB

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