vxge-main.c 119 KB

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