vmxnet3_drv.c 86 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281
  1. /*
  2. * Linux driver for VMware's vmxnet3 ethernet NIC.
  3. *
  4. * Copyright (C) 2008-2009, VMware, Inc. All Rights Reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; version 2 of the License and no later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  13. * NON INFRINGEMENT. See the GNU General Public License for more
  14. * details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * The full GNU General Public License is included in this distribution in
  21. * the file called "COPYING".
  22. *
  23. * Maintained by: Shreyas Bhatewara <pv-drivers@vmware.com>
  24. *
  25. */
  26. #include <net/ip6_checksum.h>
  27. #include "vmxnet3_int.h"
  28. char vmxnet3_driver_name[] = "vmxnet3";
  29. #define VMXNET3_DRIVER_DESC "VMware vmxnet3 virtual NIC driver"
  30. /*
  31. * PCI Device ID Table
  32. * Last entry must be all 0s
  33. */
  34. static DEFINE_PCI_DEVICE_TABLE(vmxnet3_pciid_table) = {
  35. {PCI_VDEVICE(VMWARE, PCI_DEVICE_ID_VMWARE_VMXNET3)},
  36. {0}
  37. };
  38. MODULE_DEVICE_TABLE(pci, vmxnet3_pciid_table);
  39. static atomic_t devices_found;
  40. #define VMXNET3_MAX_DEVICES 10
  41. static int enable_mq = 1;
  42. static int irq_share_mode;
  43. /*
  44. * Enable/Disable the given intr
  45. */
  46. static void
  47. vmxnet3_enable_intr(struct vmxnet3_adapter *adapter, unsigned intr_idx)
  48. {
  49. VMXNET3_WRITE_BAR0_REG(adapter, VMXNET3_REG_IMR + intr_idx * 8, 0);
  50. }
  51. static void
  52. vmxnet3_disable_intr(struct vmxnet3_adapter *adapter, unsigned intr_idx)
  53. {
  54. VMXNET3_WRITE_BAR0_REG(adapter, VMXNET3_REG_IMR + intr_idx * 8, 1);
  55. }
  56. /*
  57. * Enable/Disable all intrs used by the device
  58. */
  59. static void
  60. vmxnet3_enable_all_intrs(struct vmxnet3_adapter *adapter)
  61. {
  62. int i;
  63. for (i = 0; i < adapter->intr.num_intrs; i++)
  64. vmxnet3_enable_intr(adapter, i);
  65. adapter->shared->devRead.intrConf.intrCtrl &=
  66. cpu_to_le32(~VMXNET3_IC_DISABLE_ALL);
  67. }
  68. static void
  69. vmxnet3_disable_all_intrs(struct vmxnet3_adapter *adapter)
  70. {
  71. int i;
  72. adapter->shared->devRead.intrConf.intrCtrl |=
  73. cpu_to_le32(VMXNET3_IC_DISABLE_ALL);
  74. for (i = 0; i < adapter->intr.num_intrs; i++)
  75. vmxnet3_disable_intr(adapter, i);
  76. }
  77. static void
  78. vmxnet3_ack_events(struct vmxnet3_adapter *adapter, u32 events)
  79. {
  80. VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_ECR, events);
  81. }
  82. static bool
  83. vmxnet3_tq_stopped(struct vmxnet3_tx_queue *tq, struct vmxnet3_adapter *adapter)
  84. {
  85. return tq->stopped;
  86. }
  87. static void
  88. vmxnet3_tq_start(struct vmxnet3_tx_queue *tq, struct vmxnet3_adapter *adapter)
  89. {
  90. tq->stopped = false;
  91. netif_start_subqueue(adapter->netdev, tq - adapter->tx_queue);
  92. }
  93. static void
  94. vmxnet3_tq_wake(struct vmxnet3_tx_queue *tq, struct vmxnet3_adapter *adapter)
  95. {
  96. tq->stopped = false;
  97. netif_wake_subqueue(adapter->netdev, (tq - adapter->tx_queue));
  98. }
  99. static void
  100. vmxnet3_tq_stop(struct vmxnet3_tx_queue *tq, struct vmxnet3_adapter *adapter)
  101. {
  102. tq->stopped = true;
  103. tq->num_stop++;
  104. netif_stop_subqueue(adapter->netdev, (tq - adapter->tx_queue));
  105. }
  106. /*
  107. * Check the link state. This may start or stop the tx queue.
  108. */
  109. static void
  110. vmxnet3_check_link(struct vmxnet3_adapter *adapter, bool affectTxQueue)
  111. {
  112. u32 ret;
  113. int i;
  114. VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD, VMXNET3_CMD_GET_LINK);
  115. ret = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_CMD);
  116. adapter->link_speed = ret >> 16;
  117. if (ret & 1) { /* Link is up. */
  118. printk(KERN_INFO "%s: NIC Link is Up %d Mbps\n",
  119. adapter->netdev->name, adapter->link_speed);
  120. if (!netif_carrier_ok(adapter->netdev))
  121. netif_carrier_on(adapter->netdev);
  122. if (affectTxQueue) {
  123. for (i = 0; i < adapter->num_tx_queues; i++)
  124. vmxnet3_tq_start(&adapter->tx_queue[i],
  125. adapter);
  126. }
  127. } else {
  128. printk(KERN_INFO "%s: NIC Link is Down\n",
  129. adapter->netdev->name);
  130. if (netif_carrier_ok(adapter->netdev))
  131. netif_carrier_off(adapter->netdev);
  132. if (affectTxQueue) {
  133. for (i = 0; i < adapter->num_tx_queues; i++)
  134. vmxnet3_tq_stop(&adapter->tx_queue[i], adapter);
  135. }
  136. }
  137. }
  138. static void
  139. vmxnet3_process_events(struct vmxnet3_adapter *adapter)
  140. {
  141. int i;
  142. u32 events = le32_to_cpu(adapter->shared->ecr);
  143. if (!events)
  144. return;
  145. vmxnet3_ack_events(adapter, events);
  146. /* Check if link state has changed */
  147. if (events & VMXNET3_ECR_LINK)
  148. vmxnet3_check_link(adapter, true);
  149. /* Check if there is an error on xmit/recv queues */
  150. if (events & (VMXNET3_ECR_TQERR | VMXNET3_ECR_RQERR)) {
  151. VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
  152. VMXNET3_CMD_GET_QUEUE_STATUS);
  153. for (i = 0; i < adapter->num_tx_queues; i++)
  154. if (adapter->tqd_start[i].status.stopped)
  155. dev_err(&adapter->netdev->dev,
  156. "%s: tq[%d] error 0x%x\n",
  157. adapter->netdev->name, i, le32_to_cpu(
  158. adapter->tqd_start[i].status.error));
  159. for (i = 0; i < adapter->num_rx_queues; i++)
  160. if (adapter->rqd_start[i].status.stopped)
  161. dev_err(&adapter->netdev->dev,
  162. "%s: rq[%d] error 0x%x\n",
  163. adapter->netdev->name, i,
  164. adapter->rqd_start[i].status.error);
  165. schedule_work(&adapter->work);
  166. }
  167. }
  168. #ifdef __BIG_ENDIAN_BITFIELD
  169. /*
  170. * The device expects the bitfields in shared structures to be written in
  171. * little endian. When CPU is big endian, the following routines are used to
  172. * correctly read and write into ABI.
  173. * The general technique used here is : double word bitfields are defined in
  174. * opposite order for big endian architecture. Then before reading them in
  175. * driver the complete double word is translated using le32_to_cpu. Similarly
  176. * After the driver writes into bitfields, cpu_to_le32 is used to translate the
  177. * double words into required format.
  178. * In order to avoid touching bits in shared structure more than once, temporary
  179. * descriptors are used. These are passed as srcDesc to following functions.
  180. */
  181. static void vmxnet3_RxDescToCPU(const struct Vmxnet3_RxDesc *srcDesc,
  182. struct Vmxnet3_RxDesc *dstDesc)
  183. {
  184. u32 *src = (u32 *)srcDesc + 2;
  185. u32 *dst = (u32 *)dstDesc + 2;
  186. dstDesc->addr = le64_to_cpu(srcDesc->addr);
  187. *dst = le32_to_cpu(*src);
  188. dstDesc->ext1 = le32_to_cpu(srcDesc->ext1);
  189. }
  190. static void vmxnet3_TxDescToLe(const struct Vmxnet3_TxDesc *srcDesc,
  191. struct Vmxnet3_TxDesc *dstDesc)
  192. {
  193. int i;
  194. u32 *src = (u32 *)(srcDesc + 1);
  195. u32 *dst = (u32 *)(dstDesc + 1);
  196. /* Working backwards so that the gen bit is set at the end. */
  197. for (i = 2; i > 0; i--) {
  198. src--;
  199. dst--;
  200. *dst = cpu_to_le32(*src);
  201. }
  202. }
  203. static void vmxnet3_RxCompToCPU(const struct Vmxnet3_RxCompDesc *srcDesc,
  204. struct Vmxnet3_RxCompDesc *dstDesc)
  205. {
  206. int i = 0;
  207. u32 *src = (u32 *)srcDesc;
  208. u32 *dst = (u32 *)dstDesc;
  209. for (i = 0; i < sizeof(struct Vmxnet3_RxCompDesc) / sizeof(u32); i++) {
  210. *dst = le32_to_cpu(*src);
  211. src++;
  212. dst++;
  213. }
  214. }
  215. /* Used to read bitfield values from double words. */
  216. static u32 get_bitfield32(const __le32 *bitfield, u32 pos, u32 size)
  217. {
  218. u32 temp = le32_to_cpu(*bitfield);
  219. u32 mask = ((1 << size) - 1) << pos;
  220. temp &= mask;
  221. temp >>= pos;
  222. return temp;
  223. }
  224. #endif /* __BIG_ENDIAN_BITFIELD */
  225. #ifdef __BIG_ENDIAN_BITFIELD
  226. # define VMXNET3_TXDESC_GET_GEN(txdesc) get_bitfield32(((const __le32 *) \
  227. txdesc) + VMXNET3_TXD_GEN_DWORD_SHIFT, \
  228. VMXNET3_TXD_GEN_SHIFT, VMXNET3_TXD_GEN_SIZE)
  229. # define VMXNET3_TXDESC_GET_EOP(txdesc) get_bitfield32(((const __le32 *) \
  230. txdesc) + VMXNET3_TXD_EOP_DWORD_SHIFT, \
  231. VMXNET3_TXD_EOP_SHIFT, VMXNET3_TXD_EOP_SIZE)
  232. # define VMXNET3_TCD_GET_GEN(tcd) get_bitfield32(((const __le32 *)tcd) + \
  233. VMXNET3_TCD_GEN_DWORD_SHIFT, VMXNET3_TCD_GEN_SHIFT, \
  234. VMXNET3_TCD_GEN_SIZE)
  235. # define VMXNET3_TCD_GET_TXIDX(tcd) get_bitfield32((const __le32 *)tcd, \
  236. VMXNET3_TCD_TXIDX_SHIFT, VMXNET3_TCD_TXIDX_SIZE)
  237. # define vmxnet3_getRxComp(dstrcd, rcd, tmp) do { \
  238. (dstrcd) = (tmp); \
  239. vmxnet3_RxCompToCPU((rcd), (tmp)); \
  240. } while (0)
  241. # define vmxnet3_getRxDesc(dstrxd, rxd, tmp) do { \
  242. (dstrxd) = (tmp); \
  243. vmxnet3_RxDescToCPU((rxd), (tmp)); \
  244. } while (0)
  245. #else
  246. # define VMXNET3_TXDESC_GET_GEN(txdesc) ((txdesc)->gen)
  247. # define VMXNET3_TXDESC_GET_EOP(txdesc) ((txdesc)->eop)
  248. # define VMXNET3_TCD_GET_GEN(tcd) ((tcd)->gen)
  249. # define VMXNET3_TCD_GET_TXIDX(tcd) ((tcd)->txdIdx)
  250. # define vmxnet3_getRxComp(dstrcd, rcd, tmp) (dstrcd) = (rcd)
  251. # define vmxnet3_getRxDesc(dstrxd, rxd, tmp) (dstrxd) = (rxd)
  252. #endif /* __BIG_ENDIAN_BITFIELD */
  253. static void
  254. vmxnet3_unmap_tx_buf(struct vmxnet3_tx_buf_info *tbi,
  255. struct pci_dev *pdev)
  256. {
  257. if (tbi->map_type == VMXNET3_MAP_SINGLE)
  258. pci_unmap_single(pdev, tbi->dma_addr, tbi->len,
  259. PCI_DMA_TODEVICE);
  260. else if (tbi->map_type == VMXNET3_MAP_PAGE)
  261. pci_unmap_page(pdev, tbi->dma_addr, tbi->len,
  262. PCI_DMA_TODEVICE);
  263. else
  264. BUG_ON(tbi->map_type != VMXNET3_MAP_NONE);
  265. tbi->map_type = VMXNET3_MAP_NONE; /* to help debugging */
  266. }
  267. static int
  268. vmxnet3_unmap_pkt(u32 eop_idx, struct vmxnet3_tx_queue *tq,
  269. struct pci_dev *pdev, struct vmxnet3_adapter *adapter)
  270. {
  271. struct sk_buff *skb;
  272. int entries = 0;
  273. /* no out of order completion */
  274. BUG_ON(tq->buf_info[eop_idx].sop_idx != tq->tx_ring.next2comp);
  275. BUG_ON(VMXNET3_TXDESC_GET_EOP(&(tq->tx_ring.base[eop_idx].txd)) != 1);
  276. skb = tq->buf_info[eop_idx].skb;
  277. BUG_ON(skb == NULL);
  278. tq->buf_info[eop_idx].skb = NULL;
  279. VMXNET3_INC_RING_IDX_ONLY(eop_idx, tq->tx_ring.size);
  280. while (tq->tx_ring.next2comp != eop_idx) {
  281. vmxnet3_unmap_tx_buf(tq->buf_info + tq->tx_ring.next2comp,
  282. pdev);
  283. /* update next2comp w/o tx_lock. Since we are marking more,
  284. * instead of less, tx ring entries avail, the worst case is
  285. * that the tx routine incorrectly re-queues a pkt due to
  286. * insufficient tx ring entries.
  287. */
  288. vmxnet3_cmd_ring_adv_next2comp(&tq->tx_ring);
  289. entries++;
  290. }
  291. dev_kfree_skb_any(skb);
  292. return entries;
  293. }
  294. static int
  295. vmxnet3_tq_tx_complete(struct vmxnet3_tx_queue *tq,
  296. struct vmxnet3_adapter *adapter)
  297. {
  298. int completed = 0;
  299. union Vmxnet3_GenericDesc *gdesc;
  300. gdesc = tq->comp_ring.base + tq->comp_ring.next2proc;
  301. while (VMXNET3_TCD_GET_GEN(&gdesc->tcd) == tq->comp_ring.gen) {
  302. completed += vmxnet3_unmap_pkt(VMXNET3_TCD_GET_TXIDX(
  303. &gdesc->tcd), tq, adapter->pdev,
  304. adapter);
  305. vmxnet3_comp_ring_adv_next2proc(&tq->comp_ring);
  306. gdesc = tq->comp_ring.base + tq->comp_ring.next2proc;
  307. }
  308. if (completed) {
  309. spin_lock(&tq->tx_lock);
  310. if (unlikely(vmxnet3_tq_stopped(tq, adapter) &&
  311. vmxnet3_cmd_ring_desc_avail(&tq->tx_ring) >
  312. VMXNET3_WAKE_QUEUE_THRESHOLD(tq) &&
  313. netif_carrier_ok(adapter->netdev))) {
  314. vmxnet3_tq_wake(tq, adapter);
  315. }
  316. spin_unlock(&tq->tx_lock);
  317. }
  318. return completed;
  319. }
  320. static void
  321. vmxnet3_tq_cleanup(struct vmxnet3_tx_queue *tq,
  322. struct vmxnet3_adapter *adapter)
  323. {
  324. int i;
  325. while (tq->tx_ring.next2comp != tq->tx_ring.next2fill) {
  326. struct vmxnet3_tx_buf_info *tbi;
  327. union Vmxnet3_GenericDesc *gdesc;
  328. tbi = tq->buf_info + tq->tx_ring.next2comp;
  329. gdesc = tq->tx_ring.base + tq->tx_ring.next2comp;
  330. vmxnet3_unmap_tx_buf(tbi, adapter->pdev);
  331. if (tbi->skb) {
  332. dev_kfree_skb_any(tbi->skb);
  333. tbi->skb = NULL;
  334. }
  335. vmxnet3_cmd_ring_adv_next2comp(&tq->tx_ring);
  336. }
  337. /* sanity check, verify all buffers are indeed unmapped and freed */
  338. for (i = 0; i < tq->tx_ring.size; i++) {
  339. BUG_ON(tq->buf_info[i].skb != NULL ||
  340. tq->buf_info[i].map_type != VMXNET3_MAP_NONE);
  341. }
  342. tq->tx_ring.gen = VMXNET3_INIT_GEN;
  343. tq->tx_ring.next2fill = tq->tx_ring.next2comp = 0;
  344. tq->comp_ring.gen = VMXNET3_INIT_GEN;
  345. tq->comp_ring.next2proc = 0;
  346. }
  347. static void
  348. vmxnet3_tq_destroy(struct vmxnet3_tx_queue *tq,
  349. struct vmxnet3_adapter *adapter)
  350. {
  351. if (tq->tx_ring.base) {
  352. pci_free_consistent(adapter->pdev, tq->tx_ring.size *
  353. sizeof(struct Vmxnet3_TxDesc),
  354. tq->tx_ring.base, tq->tx_ring.basePA);
  355. tq->tx_ring.base = NULL;
  356. }
  357. if (tq->data_ring.base) {
  358. pci_free_consistent(adapter->pdev, tq->data_ring.size *
  359. sizeof(struct Vmxnet3_TxDataDesc),
  360. tq->data_ring.base, tq->data_ring.basePA);
  361. tq->data_ring.base = NULL;
  362. }
  363. if (tq->comp_ring.base) {
  364. pci_free_consistent(adapter->pdev, tq->comp_ring.size *
  365. sizeof(struct Vmxnet3_TxCompDesc),
  366. tq->comp_ring.base, tq->comp_ring.basePA);
  367. tq->comp_ring.base = NULL;
  368. }
  369. kfree(tq->buf_info);
  370. tq->buf_info = NULL;
  371. }
  372. /* Destroy all tx queues */
  373. void
  374. vmxnet3_tq_destroy_all(struct vmxnet3_adapter *adapter)
  375. {
  376. int i;
  377. for (i = 0; i < adapter->num_tx_queues; i++)
  378. vmxnet3_tq_destroy(&adapter->tx_queue[i], adapter);
  379. }
  380. static void
  381. vmxnet3_tq_init(struct vmxnet3_tx_queue *tq,
  382. struct vmxnet3_adapter *adapter)
  383. {
  384. int i;
  385. /* reset the tx ring contents to 0 and reset the tx ring states */
  386. memset(tq->tx_ring.base, 0, tq->tx_ring.size *
  387. sizeof(struct Vmxnet3_TxDesc));
  388. tq->tx_ring.next2fill = tq->tx_ring.next2comp = 0;
  389. tq->tx_ring.gen = VMXNET3_INIT_GEN;
  390. memset(tq->data_ring.base, 0, tq->data_ring.size *
  391. sizeof(struct Vmxnet3_TxDataDesc));
  392. /* reset the tx comp ring contents to 0 and reset comp ring states */
  393. memset(tq->comp_ring.base, 0, tq->comp_ring.size *
  394. sizeof(struct Vmxnet3_TxCompDesc));
  395. tq->comp_ring.next2proc = 0;
  396. tq->comp_ring.gen = VMXNET3_INIT_GEN;
  397. /* reset the bookkeeping data */
  398. memset(tq->buf_info, 0, sizeof(tq->buf_info[0]) * tq->tx_ring.size);
  399. for (i = 0; i < tq->tx_ring.size; i++)
  400. tq->buf_info[i].map_type = VMXNET3_MAP_NONE;
  401. /* stats are not reset */
  402. }
  403. static int
  404. vmxnet3_tq_create(struct vmxnet3_tx_queue *tq,
  405. struct vmxnet3_adapter *adapter)
  406. {
  407. BUG_ON(tq->tx_ring.base || tq->data_ring.base ||
  408. tq->comp_ring.base || tq->buf_info);
  409. tq->tx_ring.base = pci_alloc_consistent(adapter->pdev, tq->tx_ring.size
  410. * sizeof(struct Vmxnet3_TxDesc),
  411. &tq->tx_ring.basePA);
  412. if (!tq->tx_ring.base) {
  413. printk(KERN_ERR "%s: failed to allocate tx ring\n",
  414. adapter->netdev->name);
  415. goto err;
  416. }
  417. tq->data_ring.base = pci_alloc_consistent(adapter->pdev,
  418. tq->data_ring.size *
  419. sizeof(struct Vmxnet3_TxDataDesc),
  420. &tq->data_ring.basePA);
  421. if (!tq->data_ring.base) {
  422. printk(KERN_ERR "%s: failed to allocate data ring\n",
  423. adapter->netdev->name);
  424. goto err;
  425. }
  426. tq->comp_ring.base = pci_alloc_consistent(adapter->pdev,
  427. tq->comp_ring.size *
  428. sizeof(struct Vmxnet3_TxCompDesc),
  429. &tq->comp_ring.basePA);
  430. if (!tq->comp_ring.base) {
  431. printk(KERN_ERR "%s: failed to allocate tx comp ring\n",
  432. adapter->netdev->name);
  433. goto err;
  434. }
  435. tq->buf_info = kcalloc(tq->tx_ring.size, sizeof(tq->buf_info[0]),
  436. GFP_KERNEL);
  437. if (!tq->buf_info) {
  438. printk(KERN_ERR "%s: failed to allocate tx bufinfo\n",
  439. adapter->netdev->name);
  440. goto err;
  441. }
  442. return 0;
  443. err:
  444. vmxnet3_tq_destroy(tq, adapter);
  445. return -ENOMEM;
  446. }
  447. static void
  448. vmxnet3_tq_cleanup_all(struct vmxnet3_adapter *adapter)
  449. {
  450. int i;
  451. for (i = 0; i < adapter->num_tx_queues; i++)
  452. vmxnet3_tq_cleanup(&adapter->tx_queue[i], adapter);
  453. }
  454. /*
  455. * starting from ring->next2fill, allocate rx buffers for the given ring
  456. * of the rx queue and update the rx desc. stop after @num_to_alloc buffers
  457. * are allocated or allocation fails
  458. */
  459. static int
  460. vmxnet3_rq_alloc_rx_buf(struct vmxnet3_rx_queue *rq, u32 ring_idx,
  461. int num_to_alloc, struct vmxnet3_adapter *adapter)
  462. {
  463. int num_allocated = 0;
  464. struct vmxnet3_rx_buf_info *rbi_base = rq->buf_info[ring_idx];
  465. struct vmxnet3_cmd_ring *ring = &rq->rx_ring[ring_idx];
  466. u32 val;
  467. while (num_allocated < num_to_alloc) {
  468. struct vmxnet3_rx_buf_info *rbi;
  469. union Vmxnet3_GenericDesc *gd;
  470. rbi = rbi_base + ring->next2fill;
  471. gd = ring->base + ring->next2fill;
  472. if (rbi->buf_type == VMXNET3_RX_BUF_SKB) {
  473. if (rbi->skb == NULL) {
  474. rbi->skb = dev_alloc_skb(rbi->len +
  475. NET_IP_ALIGN);
  476. if (unlikely(rbi->skb == NULL)) {
  477. rq->stats.rx_buf_alloc_failure++;
  478. break;
  479. }
  480. rbi->skb->dev = adapter->netdev;
  481. skb_reserve(rbi->skb, NET_IP_ALIGN);
  482. rbi->dma_addr = pci_map_single(adapter->pdev,
  483. rbi->skb->data, rbi->len,
  484. PCI_DMA_FROMDEVICE);
  485. } else {
  486. /* rx buffer skipped by the device */
  487. }
  488. val = VMXNET3_RXD_BTYPE_HEAD << VMXNET3_RXD_BTYPE_SHIFT;
  489. } else {
  490. BUG_ON(rbi->buf_type != VMXNET3_RX_BUF_PAGE ||
  491. rbi->len != PAGE_SIZE);
  492. if (rbi->page == NULL) {
  493. rbi->page = alloc_page(GFP_ATOMIC);
  494. if (unlikely(rbi->page == NULL)) {
  495. rq->stats.rx_buf_alloc_failure++;
  496. break;
  497. }
  498. rbi->dma_addr = pci_map_page(adapter->pdev,
  499. rbi->page, 0, PAGE_SIZE,
  500. PCI_DMA_FROMDEVICE);
  501. } else {
  502. /* rx buffers skipped by the device */
  503. }
  504. val = VMXNET3_RXD_BTYPE_BODY << VMXNET3_RXD_BTYPE_SHIFT;
  505. }
  506. BUG_ON(rbi->dma_addr == 0);
  507. gd->rxd.addr = cpu_to_le64(rbi->dma_addr);
  508. gd->dword[2] = cpu_to_le32((ring->gen << VMXNET3_RXD_GEN_SHIFT)
  509. | val | rbi->len);
  510. num_allocated++;
  511. vmxnet3_cmd_ring_adv_next2fill(ring);
  512. }
  513. rq->uncommitted[ring_idx] += num_allocated;
  514. dev_dbg(&adapter->netdev->dev,
  515. "alloc_rx_buf: %d allocated, next2fill %u, next2comp "
  516. "%u, uncommited %u\n", num_allocated, ring->next2fill,
  517. ring->next2comp, rq->uncommitted[ring_idx]);
  518. /* so that the device can distinguish a full ring and an empty ring */
  519. BUG_ON(num_allocated != 0 && ring->next2fill == ring->next2comp);
  520. return num_allocated;
  521. }
  522. static void
  523. vmxnet3_append_frag(struct sk_buff *skb, struct Vmxnet3_RxCompDesc *rcd,
  524. struct vmxnet3_rx_buf_info *rbi)
  525. {
  526. struct skb_frag_struct *frag = skb_shinfo(skb)->frags +
  527. skb_shinfo(skb)->nr_frags;
  528. BUG_ON(skb_shinfo(skb)->nr_frags >= MAX_SKB_FRAGS);
  529. frag->page = rbi->page;
  530. frag->page_offset = 0;
  531. frag->size = rcd->len;
  532. skb->data_len += frag->size;
  533. skb_shinfo(skb)->nr_frags++;
  534. }
  535. static void
  536. vmxnet3_map_pkt(struct sk_buff *skb, struct vmxnet3_tx_ctx *ctx,
  537. struct vmxnet3_tx_queue *tq, struct pci_dev *pdev,
  538. struct vmxnet3_adapter *adapter)
  539. {
  540. u32 dw2, len;
  541. unsigned long buf_offset;
  542. int i;
  543. union Vmxnet3_GenericDesc *gdesc;
  544. struct vmxnet3_tx_buf_info *tbi = NULL;
  545. BUG_ON(ctx->copy_size > skb_headlen(skb));
  546. /* use the previous gen bit for the SOP desc */
  547. dw2 = (tq->tx_ring.gen ^ 0x1) << VMXNET3_TXD_GEN_SHIFT;
  548. ctx->sop_txd = tq->tx_ring.base + tq->tx_ring.next2fill;
  549. gdesc = ctx->sop_txd; /* both loops below can be skipped */
  550. /* no need to map the buffer if headers are copied */
  551. if (ctx->copy_size) {
  552. ctx->sop_txd->txd.addr = cpu_to_le64(tq->data_ring.basePA +
  553. tq->tx_ring.next2fill *
  554. sizeof(struct Vmxnet3_TxDataDesc));
  555. ctx->sop_txd->dword[2] = cpu_to_le32(dw2 | ctx->copy_size);
  556. ctx->sop_txd->dword[3] = 0;
  557. tbi = tq->buf_info + tq->tx_ring.next2fill;
  558. tbi->map_type = VMXNET3_MAP_NONE;
  559. dev_dbg(&adapter->netdev->dev,
  560. "txd[%u]: 0x%Lx 0x%x 0x%x\n",
  561. tq->tx_ring.next2fill,
  562. le64_to_cpu(ctx->sop_txd->txd.addr),
  563. ctx->sop_txd->dword[2], ctx->sop_txd->dword[3]);
  564. vmxnet3_cmd_ring_adv_next2fill(&tq->tx_ring);
  565. /* use the right gen for non-SOP desc */
  566. dw2 = tq->tx_ring.gen << VMXNET3_TXD_GEN_SHIFT;
  567. }
  568. /* linear part can use multiple tx desc if it's big */
  569. len = skb_headlen(skb) - ctx->copy_size;
  570. buf_offset = ctx->copy_size;
  571. while (len) {
  572. u32 buf_size;
  573. if (len < VMXNET3_MAX_TX_BUF_SIZE) {
  574. buf_size = len;
  575. dw2 |= len;
  576. } else {
  577. buf_size = VMXNET3_MAX_TX_BUF_SIZE;
  578. /* spec says that for TxDesc.len, 0 == 2^14 */
  579. }
  580. tbi = tq->buf_info + tq->tx_ring.next2fill;
  581. tbi->map_type = VMXNET3_MAP_SINGLE;
  582. tbi->dma_addr = pci_map_single(adapter->pdev,
  583. skb->data + buf_offset, buf_size,
  584. PCI_DMA_TODEVICE);
  585. tbi->len = buf_size;
  586. gdesc = tq->tx_ring.base + tq->tx_ring.next2fill;
  587. BUG_ON(gdesc->txd.gen == tq->tx_ring.gen);
  588. gdesc->txd.addr = cpu_to_le64(tbi->dma_addr);
  589. gdesc->dword[2] = cpu_to_le32(dw2);
  590. gdesc->dword[3] = 0;
  591. dev_dbg(&adapter->netdev->dev,
  592. "txd[%u]: 0x%Lx 0x%x 0x%x\n",
  593. tq->tx_ring.next2fill, le64_to_cpu(gdesc->txd.addr),
  594. le32_to_cpu(gdesc->dword[2]), gdesc->dword[3]);
  595. vmxnet3_cmd_ring_adv_next2fill(&tq->tx_ring);
  596. dw2 = tq->tx_ring.gen << VMXNET3_TXD_GEN_SHIFT;
  597. len -= buf_size;
  598. buf_offset += buf_size;
  599. }
  600. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  601. struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[i];
  602. tbi = tq->buf_info + tq->tx_ring.next2fill;
  603. tbi->map_type = VMXNET3_MAP_PAGE;
  604. tbi->dma_addr = pci_map_page(adapter->pdev, frag->page,
  605. frag->page_offset, frag->size,
  606. PCI_DMA_TODEVICE);
  607. tbi->len = frag->size;
  608. gdesc = tq->tx_ring.base + tq->tx_ring.next2fill;
  609. BUG_ON(gdesc->txd.gen == tq->tx_ring.gen);
  610. gdesc->txd.addr = cpu_to_le64(tbi->dma_addr);
  611. gdesc->dword[2] = cpu_to_le32(dw2 | frag->size);
  612. gdesc->dword[3] = 0;
  613. dev_dbg(&adapter->netdev->dev,
  614. "txd[%u]: 0x%llu %u %u\n",
  615. tq->tx_ring.next2fill, le64_to_cpu(gdesc->txd.addr),
  616. le32_to_cpu(gdesc->dword[2]), gdesc->dword[3]);
  617. vmxnet3_cmd_ring_adv_next2fill(&tq->tx_ring);
  618. dw2 = tq->tx_ring.gen << VMXNET3_TXD_GEN_SHIFT;
  619. }
  620. ctx->eop_txd = gdesc;
  621. /* set the last buf_info for the pkt */
  622. tbi->skb = skb;
  623. tbi->sop_idx = ctx->sop_txd - tq->tx_ring.base;
  624. }
  625. /* Init all tx queues */
  626. static void
  627. vmxnet3_tq_init_all(struct vmxnet3_adapter *adapter)
  628. {
  629. int i;
  630. for (i = 0; i < adapter->num_tx_queues; i++)
  631. vmxnet3_tq_init(&adapter->tx_queue[i], adapter);
  632. }
  633. /*
  634. * parse and copy relevant protocol headers:
  635. * For a tso pkt, relevant headers are L2/3/4 including options
  636. * For a pkt requesting csum offloading, they are L2/3 and may include L4
  637. * if it's a TCP/UDP pkt
  638. *
  639. * Returns:
  640. * -1: error happens during parsing
  641. * 0: protocol headers parsed, but too big to be copied
  642. * 1: protocol headers parsed and copied
  643. *
  644. * Other effects:
  645. * 1. related *ctx fields are updated.
  646. * 2. ctx->copy_size is # of bytes copied
  647. * 3. the portion copied is guaranteed to be in the linear part
  648. *
  649. */
  650. static int
  651. vmxnet3_parse_and_copy_hdr(struct sk_buff *skb, struct vmxnet3_tx_queue *tq,
  652. struct vmxnet3_tx_ctx *ctx,
  653. struct vmxnet3_adapter *adapter)
  654. {
  655. struct Vmxnet3_TxDataDesc *tdd;
  656. if (ctx->mss) { /* TSO */
  657. ctx->eth_ip_hdr_size = skb_transport_offset(skb);
  658. ctx->l4_hdr_size = ((struct tcphdr *)
  659. skb_transport_header(skb))->doff * 4;
  660. ctx->copy_size = ctx->eth_ip_hdr_size + ctx->l4_hdr_size;
  661. } else {
  662. unsigned int pull_size;
  663. if (skb->ip_summed == CHECKSUM_PARTIAL) {
  664. ctx->eth_ip_hdr_size = skb_checksum_start_offset(skb);
  665. if (ctx->ipv4) {
  666. struct iphdr *iph = (struct iphdr *)
  667. skb_network_header(skb);
  668. if (iph->protocol == IPPROTO_TCP) {
  669. pull_size = ctx->eth_ip_hdr_size +
  670. sizeof(struct tcphdr);
  671. if (unlikely(!pskb_may_pull(skb,
  672. pull_size))) {
  673. goto err;
  674. }
  675. ctx->l4_hdr_size = ((struct tcphdr *)
  676. skb_transport_header(skb))->doff * 4;
  677. } else if (iph->protocol == IPPROTO_UDP) {
  678. ctx->l4_hdr_size =
  679. sizeof(struct udphdr);
  680. } else {
  681. ctx->l4_hdr_size = 0;
  682. }
  683. } else {
  684. /* for simplicity, don't copy L4 headers */
  685. ctx->l4_hdr_size = 0;
  686. }
  687. ctx->copy_size = ctx->eth_ip_hdr_size +
  688. ctx->l4_hdr_size;
  689. } else {
  690. ctx->eth_ip_hdr_size = 0;
  691. ctx->l4_hdr_size = 0;
  692. /* copy as much as allowed */
  693. ctx->copy_size = min((unsigned int)VMXNET3_HDR_COPY_SIZE
  694. , skb_headlen(skb));
  695. }
  696. /* make sure headers are accessible directly */
  697. if (unlikely(!pskb_may_pull(skb, ctx->copy_size)))
  698. goto err;
  699. }
  700. if (unlikely(ctx->copy_size > VMXNET3_HDR_COPY_SIZE)) {
  701. tq->stats.oversized_hdr++;
  702. ctx->copy_size = 0;
  703. return 0;
  704. }
  705. tdd = tq->data_ring.base + tq->tx_ring.next2fill;
  706. memcpy(tdd->data, skb->data, ctx->copy_size);
  707. dev_dbg(&adapter->netdev->dev,
  708. "copy %u bytes to dataRing[%u]\n",
  709. ctx->copy_size, tq->tx_ring.next2fill);
  710. return 1;
  711. err:
  712. return -1;
  713. }
  714. static void
  715. vmxnet3_prepare_tso(struct sk_buff *skb,
  716. struct vmxnet3_tx_ctx *ctx)
  717. {
  718. struct tcphdr *tcph = (struct tcphdr *)skb_transport_header(skb);
  719. if (ctx->ipv4) {
  720. struct iphdr *iph = (struct iphdr *)skb_network_header(skb);
  721. iph->check = 0;
  722. tcph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr, 0,
  723. IPPROTO_TCP, 0);
  724. } else {
  725. struct ipv6hdr *iph = (struct ipv6hdr *)skb_network_header(skb);
  726. tcph->check = ~csum_ipv6_magic(&iph->saddr, &iph->daddr, 0,
  727. IPPROTO_TCP, 0);
  728. }
  729. }
  730. /*
  731. * Transmits a pkt thru a given tq
  732. * Returns:
  733. * NETDEV_TX_OK: descriptors are setup successfully
  734. * NETDEV_TX_OK: error occured, the pkt is dropped
  735. * NETDEV_TX_BUSY: tx ring is full, queue is stopped
  736. *
  737. * Side-effects:
  738. * 1. tx ring may be changed
  739. * 2. tq stats may be updated accordingly
  740. * 3. shared->txNumDeferred may be updated
  741. */
  742. static int
  743. vmxnet3_tq_xmit(struct sk_buff *skb, struct vmxnet3_tx_queue *tq,
  744. struct vmxnet3_adapter *adapter, struct net_device *netdev)
  745. {
  746. int ret;
  747. u32 count;
  748. unsigned long flags;
  749. struct vmxnet3_tx_ctx ctx;
  750. union Vmxnet3_GenericDesc *gdesc;
  751. #ifdef __BIG_ENDIAN_BITFIELD
  752. /* Use temporary descriptor to avoid touching bits multiple times */
  753. union Vmxnet3_GenericDesc tempTxDesc;
  754. #endif
  755. /* conservatively estimate # of descriptors to use */
  756. count = VMXNET3_TXD_NEEDED(skb_headlen(skb)) +
  757. skb_shinfo(skb)->nr_frags + 1;
  758. ctx.ipv4 = (skb->protocol == cpu_to_be16(ETH_P_IP));
  759. ctx.mss = skb_shinfo(skb)->gso_size;
  760. if (ctx.mss) {
  761. if (skb_header_cloned(skb)) {
  762. if (unlikely(pskb_expand_head(skb, 0, 0,
  763. GFP_ATOMIC) != 0)) {
  764. tq->stats.drop_tso++;
  765. goto drop_pkt;
  766. }
  767. tq->stats.copy_skb_header++;
  768. }
  769. vmxnet3_prepare_tso(skb, &ctx);
  770. } else {
  771. if (unlikely(count > VMXNET3_MAX_TXD_PER_PKT)) {
  772. /* non-tso pkts must not use more than
  773. * VMXNET3_MAX_TXD_PER_PKT entries
  774. */
  775. if (skb_linearize(skb) != 0) {
  776. tq->stats.drop_too_many_frags++;
  777. goto drop_pkt;
  778. }
  779. tq->stats.linearized++;
  780. /* recalculate the # of descriptors to use */
  781. count = VMXNET3_TXD_NEEDED(skb_headlen(skb)) + 1;
  782. }
  783. }
  784. spin_lock_irqsave(&tq->tx_lock, flags);
  785. if (count > vmxnet3_cmd_ring_desc_avail(&tq->tx_ring)) {
  786. tq->stats.tx_ring_full++;
  787. dev_dbg(&adapter->netdev->dev,
  788. "tx queue stopped on %s, next2comp %u"
  789. " next2fill %u\n", adapter->netdev->name,
  790. tq->tx_ring.next2comp, tq->tx_ring.next2fill);
  791. vmxnet3_tq_stop(tq, adapter);
  792. spin_unlock_irqrestore(&tq->tx_lock, flags);
  793. return NETDEV_TX_BUSY;
  794. }
  795. ret = vmxnet3_parse_and_copy_hdr(skb, tq, &ctx, adapter);
  796. if (ret >= 0) {
  797. BUG_ON(ret <= 0 && ctx.copy_size != 0);
  798. /* hdrs parsed, check against other limits */
  799. if (ctx.mss) {
  800. if (unlikely(ctx.eth_ip_hdr_size + ctx.l4_hdr_size >
  801. VMXNET3_MAX_TX_BUF_SIZE)) {
  802. goto hdr_too_big;
  803. }
  804. } else {
  805. if (skb->ip_summed == CHECKSUM_PARTIAL) {
  806. if (unlikely(ctx.eth_ip_hdr_size +
  807. skb->csum_offset >
  808. VMXNET3_MAX_CSUM_OFFSET)) {
  809. goto hdr_too_big;
  810. }
  811. }
  812. }
  813. } else {
  814. tq->stats.drop_hdr_inspect_err++;
  815. goto unlock_drop_pkt;
  816. }
  817. /* fill tx descs related to addr & len */
  818. vmxnet3_map_pkt(skb, &ctx, tq, adapter->pdev, adapter);
  819. /* setup the EOP desc */
  820. ctx.eop_txd->dword[3] = cpu_to_le32(VMXNET3_TXD_CQ | VMXNET3_TXD_EOP);
  821. /* setup the SOP desc */
  822. #ifdef __BIG_ENDIAN_BITFIELD
  823. gdesc = &tempTxDesc;
  824. gdesc->dword[2] = ctx.sop_txd->dword[2];
  825. gdesc->dword[3] = ctx.sop_txd->dword[3];
  826. #else
  827. gdesc = ctx.sop_txd;
  828. #endif
  829. if (ctx.mss) {
  830. gdesc->txd.hlen = ctx.eth_ip_hdr_size + ctx.l4_hdr_size;
  831. gdesc->txd.om = VMXNET3_OM_TSO;
  832. gdesc->txd.msscof = ctx.mss;
  833. le32_add_cpu(&tq->shared->txNumDeferred, (skb->len -
  834. gdesc->txd.hlen + ctx.mss - 1) / ctx.mss);
  835. } else {
  836. if (skb->ip_summed == CHECKSUM_PARTIAL) {
  837. gdesc->txd.hlen = ctx.eth_ip_hdr_size;
  838. gdesc->txd.om = VMXNET3_OM_CSUM;
  839. gdesc->txd.msscof = ctx.eth_ip_hdr_size +
  840. skb->csum_offset;
  841. } else {
  842. gdesc->txd.om = 0;
  843. gdesc->txd.msscof = 0;
  844. }
  845. le32_add_cpu(&tq->shared->txNumDeferred, 1);
  846. }
  847. if (vlan_tx_tag_present(skb)) {
  848. gdesc->txd.ti = 1;
  849. gdesc->txd.tci = vlan_tx_tag_get(skb);
  850. }
  851. /* finally flips the GEN bit of the SOP desc. */
  852. gdesc->dword[2] = cpu_to_le32(le32_to_cpu(gdesc->dword[2]) ^
  853. VMXNET3_TXD_GEN);
  854. #ifdef __BIG_ENDIAN_BITFIELD
  855. /* Finished updating in bitfields of Tx Desc, so write them in original
  856. * place.
  857. */
  858. vmxnet3_TxDescToLe((struct Vmxnet3_TxDesc *)gdesc,
  859. (struct Vmxnet3_TxDesc *)ctx.sop_txd);
  860. gdesc = ctx.sop_txd;
  861. #endif
  862. dev_dbg(&adapter->netdev->dev,
  863. "txd[%u]: SOP 0x%Lx 0x%x 0x%x\n",
  864. (u32)((union Vmxnet3_GenericDesc *)ctx.sop_txd -
  865. tq->tx_ring.base), le64_to_cpu(gdesc->txd.addr),
  866. le32_to_cpu(gdesc->dword[2]), le32_to_cpu(gdesc->dword[3]));
  867. spin_unlock_irqrestore(&tq->tx_lock, flags);
  868. if (le32_to_cpu(tq->shared->txNumDeferred) >=
  869. le32_to_cpu(tq->shared->txThreshold)) {
  870. tq->shared->txNumDeferred = 0;
  871. VMXNET3_WRITE_BAR0_REG(adapter,
  872. VMXNET3_REG_TXPROD + tq->qid * 8,
  873. tq->tx_ring.next2fill);
  874. }
  875. return NETDEV_TX_OK;
  876. hdr_too_big:
  877. tq->stats.drop_oversized_hdr++;
  878. unlock_drop_pkt:
  879. spin_unlock_irqrestore(&tq->tx_lock, flags);
  880. drop_pkt:
  881. tq->stats.drop_total++;
  882. dev_kfree_skb(skb);
  883. return NETDEV_TX_OK;
  884. }
  885. static netdev_tx_t
  886. vmxnet3_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
  887. {
  888. struct vmxnet3_adapter *adapter = netdev_priv(netdev);
  889. BUG_ON(skb->queue_mapping > adapter->num_tx_queues);
  890. return vmxnet3_tq_xmit(skb,
  891. &adapter->tx_queue[skb->queue_mapping],
  892. adapter, netdev);
  893. }
  894. static void
  895. vmxnet3_rx_csum(struct vmxnet3_adapter *adapter,
  896. struct sk_buff *skb,
  897. union Vmxnet3_GenericDesc *gdesc)
  898. {
  899. if (!gdesc->rcd.cnc && adapter->rxcsum) {
  900. /* typical case: TCP/UDP over IP and both csums are correct */
  901. if ((le32_to_cpu(gdesc->dword[3]) & VMXNET3_RCD_CSUM_OK) ==
  902. VMXNET3_RCD_CSUM_OK) {
  903. skb->ip_summed = CHECKSUM_UNNECESSARY;
  904. BUG_ON(!(gdesc->rcd.tcp || gdesc->rcd.udp));
  905. BUG_ON(!(gdesc->rcd.v4 || gdesc->rcd.v6));
  906. BUG_ON(gdesc->rcd.frg);
  907. } else {
  908. if (gdesc->rcd.csum) {
  909. skb->csum = htons(gdesc->rcd.csum);
  910. skb->ip_summed = CHECKSUM_PARTIAL;
  911. } else {
  912. skb_checksum_none_assert(skb);
  913. }
  914. }
  915. } else {
  916. skb_checksum_none_assert(skb);
  917. }
  918. }
  919. static void
  920. vmxnet3_rx_error(struct vmxnet3_rx_queue *rq, struct Vmxnet3_RxCompDesc *rcd,
  921. struct vmxnet3_rx_ctx *ctx, struct vmxnet3_adapter *adapter)
  922. {
  923. rq->stats.drop_err++;
  924. if (!rcd->fcs)
  925. rq->stats.drop_fcs++;
  926. rq->stats.drop_total++;
  927. /*
  928. * We do not unmap and chain the rx buffer to the skb.
  929. * We basically pretend this buffer is not used and will be recycled
  930. * by vmxnet3_rq_alloc_rx_buf()
  931. */
  932. /*
  933. * ctx->skb may be NULL if this is the first and the only one
  934. * desc for the pkt
  935. */
  936. if (ctx->skb)
  937. dev_kfree_skb_irq(ctx->skb);
  938. ctx->skb = NULL;
  939. }
  940. static int
  941. vmxnet3_rq_rx_complete(struct vmxnet3_rx_queue *rq,
  942. struct vmxnet3_adapter *adapter, int quota)
  943. {
  944. static u32 rxprod_reg[2] = {VMXNET3_REG_RXPROD, VMXNET3_REG_RXPROD2};
  945. u32 num_rxd = 0;
  946. struct Vmxnet3_RxCompDesc *rcd;
  947. struct vmxnet3_rx_ctx *ctx = &rq->rx_ctx;
  948. #ifdef __BIG_ENDIAN_BITFIELD
  949. struct Vmxnet3_RxDesc rxCmdDesc;
  950. struct Vmxnet3_RxCompDesc rxComp;
  951. #endif
  952. vmxnet3_getRxComp(rcd, &rq->comp_ring.base[rq->comp_ring.next2proc].rcd,
  953. &rxComp);
  954. while (rcd->gen == rq->comp_ring.gen) {
  955. struct vmxnet3_rx_buf_info *rbi;
  956. struct sk_buff *skb;
  957. int num_to_alloc;
  958. struct Vmxnet3_RxDesc *rxd;
  959. u32 idx, ring_idx;
  960. if (num_rxd >= quota) {
  961. /* we may stop even before we see the EOP desc of
  962. * the current pkt
  963. */
  964. break;
  965. }
  966. num_rxd++;
  967. BUG_ON(rcd->rqID != rq->qid && rcd->rqID != rq->qid2);
  968. idx = rcd->rxdIdx;
  969. ring_idx = rcd->rqID < adapter->num_rx_queues ? 0 : 1;
  970. vmxnet3_getRxDesc(rxd, &rq->rx_ring[ring_idx].base[idx].rxd,
  971. &rxCmdDesc);
  972. rbi = rq->buf_info[ring_idx] + idx;
  973. BUG_ON(rxd->addr != rbi->dma_addr ||
  974. rxd->len != rbi->len);
  975. if (unlikely(rcd->eop && rcd->err)) {
  976. vmxnet3_rx_error(rq, rcd, ctx, adapter);
  977. goto rcd_done;
  978. }
  979. if (rcd->sop) { /* first buf of the pkt */
  980. BUG_ON(rxd->btype != VMXNET3_RXD_BTYPE_HEAD ||
  981. rcd->rqID != rq->qid);
  982. BUG_ON(rbi->buf_type != VMXNET3_RX_BUF_SKB);
  983. BUG_ON(ctx->skb != NULL || rbi->skb == NULL);
  984. if (unlikely(rcd->len == 0)) {
  985. /* Pretend the rx buffer is skipped. */
  986. BUG_ON(!(rcd->sop && rcd->eop));
  987. dev_dbg(&adapter->netdev->dev,
  988. "rxRing[%u][%u] 0 length\n",
  989. ring_idx, idx);
  990. goto rcd_done;
  991. }
  992. ctx->skb = rbi->skb;
  993. rbi->skb = NULL;
  994. pci_unmap_single(adapter->pdev, rbi->dma_addr, rbi->len,
  995. PCI_DMA_FROMDEVICE);
  996. skb_put(ctx->skb, rcd->len);
  997. } else {
  998. BUG_ON(ctx->skb == NULL);
  999. /* non SOP buffer must be type 1 in most cases */
  1000. if (rbi->buf_type == VMXNET3_RX_BUF_PAGE) {
  1001. BUG_ON(rxd->btype != VMXNET3_RXD_BTYPE_BODY);
  1002. if (rcd->len) {
  1003. pci_unmap_page(adapter->pdev,
  1004. rbi->dma_addr, rbi->len,
  1005. PCI_DMA_FROMDEVICE);
  1006. vmxnet3_append_frag(ctx->skb, rcd, rbi);
  1007. rbi->page = NULL;
  1008. }
  1009. } else {
  1010. /*
  1011. * The only time a non-SOP buffer is type 0 is
  1012. * when it's EOP and error flag is raised, which
  1013. * has already been handled.
  1014. */
  1015. BUG_ON(true);
  1016. }
  1017. }
  1018. skb = ctx->skb;
  1019. if (rcd->eop) {
  1020. skb->len += skb->data_len;
  1021. skb->truesize += skb->data_len;
  1022. vmxnet3_rx_csum(adapter, skb,
  1023. (union Vmxnet3_GenericDesc *)rcd);
  1024. skb->protocol = eth_type_trans(skb, adapter->netdev);
  1025. if (unlikely(adapter->vlan_grp && rcd->ts)) {
  1026. vlan_hwaccel_receive_skb(skb,
  1027. adapter->vlan_grp, rcd->tci);
  1028. } else {
  1029. netif_receive_skb(skb);
  1030. }
  1031. ctx->skb = NULL;
  1032. }
  1033. rcd_done:
  1034. /* device may skip some rx descs */
  1035. rq->rx_ring[ring_idx].next2comp = idx;
  1036. VMXNET3_INC_RING_IDX_ONLY(rq->rx_ring[ring_idx].next2comp,
  1037. rq->rx_ring[ring_idx].size);
  1038. /* refill rx buffers frequently to avoid starving the h/w */
  1039. num_to_alloc = vmxnet3_cmd_ring_desc_avail(rq->rx_ring +
  1040. ring_idx);
  1041. if (unlikely(num_to_alloc > VMXNET3_RX_ALLOC_THRESHOLD(rq,
  1042. ring_idx, adapter))) {
  1043. vmxnet3_rq_alloc_rx_buf(rq, ring_idx, num_to_alloc,
  1044. adapter);
  1045. /* if needed, update the register */
  1046. if (unlikely(rq->shared->updateRxProd)) {
  1047. VMXNET3_WRITE_BAR0_REG(adapter,
  1048. rxprod_reg[ring_idx] + rq->qid * 8,
  1049. rq->rx_ring[ring_idx].next2fill);
  1050. rq->uncommitted[ring_idx] = 0;
  1051. }
  1052. }
  1053. vmxnet3_comp_ring_adv_next2proc(&rq->comp_ring);
  1054. vmxnet3_getRxComp(rcd,
  1055. &rq->comp_ring.base[rq->comp_ring.next2proc].rcd, &rxComp);
  1056. }
  1057. return num_rxd;
  1058. }
  1059. static void
  1060. vmxnet3_rq_cleanup(struct vmxnet3_rx_queue *rq,
  1061. struct vmxnet3_adapter *adapter)
  1062. {
  1063. u32 i, ring_idx;
  1064. struct Vmxnet3_RxDesc *rxd;
  1065. for (ring_idx = 0; ring_idx < 2; ring_idx++) {
  1066. for (i = 0; i < rq->rx_ring[ring_idx].size; i++) {
  1067. #ifdef __BIG_ENDIAN_BITFIELD
  1068. struct Vmxnet3_RxDesc rxDesc;
  1069. #endif
  1070. vmxnet3_getRxDesc(rxd,
  1071. &rq->rx_ring[ring_idx].base[i].rxd, &rxDesc);
  1072. if (rxd->btype == VMXNET3_RXD_BTYPE_HEAD &&
  1073. rq->buf_info[ring_idx][i].skb) {
  1074. pci_unmap_single(adapter->pdev, rxd->addr,
  1075. rxd->len, PCI_DMA_FROMDEVICE);
  1076. dev_kfree_skb(rq->buf_info[ring_idx][i].skb);
  1077. rq->buf_info[ring_idx][i].skb = NULL;
  1078. } else if (rxd->btype == VMXNET3_RXD_BTYPE_BODY &&
  1079. rq->buf_info[ring_idx][i].page) {
  1080. pci_unmap_page(adapter->pdev, rxd->addr,
  1081. rxd->len, PCI_DMA_FROMDEVICE);
  1082. put_page(rq->buf_info[ring_idx][i].page);
  1083. rq->buf_info[ring_idx][i].page = NULL;
  1084. }
  1085. }
  1086. rq->rx_ring[ring_idx].gen = VMXNET3_INIT_GEN;
  1087. rq->rx_ring[ring_idx].next2fill =
  1088. rq->rx_ring[ring_idx].next2comp = 0;
  1089. rq->uncommitted[ring_idx] = 0;
  1090. }
  1091. rq->comp_ring.gen = VMXNET3_INIT_GEN;
  1092. rq->comp_ring.next2proc = 0;
  1093. }
  1094. static void
  1095. vmxnet3_rq_cleanup_all(struct vmxnet3_adapter *adapter)
  1096. {
  1097. int i;
  1098. for (i = 0; i < adapter->num_rx_queues; i++)
  1099. vmxnet3_rq_cleanup(&adapter->rx_queue[i], adapter);
  1100. }
  1101. void vmxnet3_rq_destroy(struct vmxnet3_rx_queue *rq,
  1102. struct vmxnet3_adapter *adapter)
  1103. {
  1104. int i;
  1105. int j;
  1106. /* all rx buffers must have already been freed */
  1107. for (i = 0; i < 2; i++) {
  1108. if (rq->buf_info[i]) {
  1109. for (j = 0; j < rq->rx_ring[i].size; j++)
  1110. BUG_ON(rq->buf_info[i][j].page != NULL);
  1111. }
  1112. }
  1113. kfree(rq->buf_info[0]);
  1114. for (i = 0; i < 2; i++) {
  1115. if (rq->rx_ring[i].base) {
  1116. pci_free_consistent(adapter->pdev, rq->rx_ring[i].size
  1117. * sizeof(struct Vmxnet3_RxDesc),
  1118. rq->rx_ring[i].base,
  1119. rq->rx_ring[i].basePA);
  1120. rq->rx_ring[i].base = NULL;
  1121. }
  1122. rq->buf_info[i] = NULL;
  1123. }
  1124. if (rq->comp_ring.base) {
  1125. pci_free_consistent(adapter->pdev, rq->comp_ring.size *
  1126. sizeof(struct Vmxnet3_RxCompDesc),
  1127. rq->comp_ring.base, rq->comp_ring.basePA);
  1128. rq->comp_ring.base = NULL;
  1129. }
  1130. }
  1131. static int
  1132. vmxnet3_rq_init(struct vmxnet3_rx_queue *rq,
  1133. struct vmxnet3_adapter *adapter)
  1134. {
  1135. int i;
  1136. /* initialize buf_info */
  1137. for (i = 0; i < rq->rx_ring[0].size; i++) {
  1138. /* 1st buf for a pkt is skbuff */
  1139. if (i % adapter->rx_buf_per_pkt == 0) {
  1140. rq->buf_info[0][i].buf_type = VMXNET3_RX_BUF_SKB;
  1141. rq->buf_info[0][i].len = adapter->skb_buf_size;
  1142. } else { /* subsequent bufs for a pkt is frag */
  1143. rq->buf_info[0][i].buf_type = VMXNET3_RX_BUF_PAGE;
  1144. rq->buf_info[0][i].len = PAGE_SIZE;
  1145. }
  1146. }
  1147. for (i = 0; i < rq->rx_ring[1].size; i++) {
  1148. rq->buf_info[1][i].buf_type = VMXNET3_RX_BUF_PAGE;
  1149. rq->buf_info[1][i].len = PAGE_SIZE;
  1150. }
  1151. /* reset internal state and allocate buffers for both rings */
  1152. for (i = 0; i < 2; i++) {
  1153. rq->rx_ring[i].next2fill = rq->rx_ring[i].next2comp = 0;
  1154. rq->uncommitted[i] = 0;
  1155. memset(rq->rx_ring[i].base, 0, rq->rx_ring[i].size *
  1156. sizeof(struct Vmxnet3_RxDesc));
  1157. rq->rx_ring[i].gen = VMXNET3_INIT_GEN;
  1158. }
  1159. if (vmxnet3_rq_alloc_rx_buf(rq, 0, rq->rx_ring[0].size - 1,
  1160. adapter) == 0) {
  1161. /* at least has 1 rx buffer for the 1st ring */
  1162. return -ENOMEM;
  1163. }
  1164. vmxnet3_rq_alloc_rx_buf(rq, 1, rq->rx_ring[1].size - 1, adapter);
  1165. /* reset the comp ring */
  1166. rq->comp_ring.next2proc = 0;
  1167. memset(rq->comp_ring.base, 0, rq->comp_ring.size *
  1168. sizeof(struct Vmxnet3_RxCompDesc));
  1169. rq->comp_ring.gen = VMXNET3_INIT_GEN;
  1170. /* reset rxctx */
  1171. rq->rx_ctx.skb = NULL;
  1172. /* stats are not reset */
  1173. return 0;
  1174. }
  1175. static int
  1176. vmxnet3_rq_init_all(struct vmxnet3_adapter *adapter)
  1177. {
  1178. int i, err = 0;
  1179. for (i = 0; i < adapter->num_rx_queues; i++) {
  1180. err = vmxnet3_rq_init(&adapter->rx_queue[i], adapter);
  1181. if (unlikely(err)) {
  1182. dev_err(&adapter->netdev->dev, "%s: failed to "
  1183. "initialize rx queue%i\n",
  1184. adapter->netdev->name, i);
  1185. break;
  1186. }
  1187. }
  1188. return err;
  1189. }
  1190. static int
  1191. vmxnet3_rq_create(struct vmxnet3_rx_queue *rq, struct vmxnet3_adapter *adapter)
  1192. {
  1193. int i;
  1194. size_t sz;
  1195. struct vmxnet3_rx_buf_info *bi;
  1196. for (i = 0; i < 2; i++) {
  1197. sz = rq->rx_ring[i].size * sizeof(struct Vmxnet3_RxDesc);
  1198. rq->rx_ring[i].base = pci_alloc_consistent(adapter->pdev, sz,
  1199. &rq->rx_ring[i].basePA);
  1200. if (!rq->rx_ring[i].base) {
  1201. printk(KERN_ERR "%s: failed to allocate rx ring %d\n",
  1202. adapter->netdev->name, i);
  1203. goto err;
  1204. }
  1205. }
  1206. sz = rq->comp_ring.size * sizeof(struct Vmxnet3_RxCompDesc);
  1207. rq->comp_ring.base = pci_alloc_consistent(adapter->pdev, sz,
  1208. &rq->comp_ring.basePA);
  1209. if (!rq->comp_ring.base) {
  1210. printk(KERN_ERR "%s: failed to allocate rx comp ring\n",
  1211. adapter->netdev->name);
  1212. goto err;
  1213. }
  1214. sz = sizeof(struct vmxnet3_rx_buf_info) * (rq->rx_ring[0].size +
  1215. rq->rx_ring[1].size);
  1216. bi = kzalloc(sz, GFP_KERNEL);
  1217. if (!bi) {
  1218. printk(KERN_ERR "%s: failed to allocate rx bufinfo\n",
  1219. adapter->netdev->name);
  1220. goto err;
  1221. }
  1222. rq->buf_info[0] = bi;
  1223. rq->buf_info[1] = bi + rq->rx_ring[0].size;
  1224. return 0;
  1225. err:
  1226. vmxnet3_rq_destroy(rq, adapter);
  1227. return -ENOMEM;
  1228. }
  1229. static int
  1230. vmxnet3_rq_create_all(struct vmxnet3_adapter *adapter)
  1231. {
  1232. int i, err = 0;
  1233. for (i = 0; i < adapter->num_rx_queues; i++) {
  1234. err = vmxnet3_rq_create(&adapter->rx_queue[i], adapter);
  1235. if (unlikely(err)) {
  1236. dev_err(&adapter->netdev->dev,
  1237. "%s: failed to create rx queue%i\n",
  1238. adapter->netdev->name, i);
  1239. goto err_out;
  1240. }
  1241. }
  1242. return err;
  1243. err_out:
  1244. vmxnet3_rq_destroy_all(adapter);
  1245. return err;
  1246. }
  1247. /* Multiple queue aware polling function for tx and rx */
  1248. static int
  1249. vmxnet3_do_poll(struct vmxnet3_adapter *adapter, int budget)
  1250. {
  1251. int rcd_done = 0, i;
  1252. if (unlikely(adapter->shared->ecr))
  1253. vmxnet3_process_events(adapter);
  1254. for (i = 0; i < adapter->num_tx_queues; i++)
  1255. vmxnet3_tq_tx_complete(&adapter->tx_queue[i], adapter);
  1256. for (i = 0; i < adapter->num_rx_queues; i++)
  1257. rcd_done += vmxnet3_rq_rx_complete(&adapter->rx_queue[i],
  1258. adapter, budget);
  1259. return rcd_done;
  1260. }
  1261. static int
  1262. vmxnet3_poll(struct napi_struct *napi, int budget)
  1263. {
  1264. struct vmxnet3_rx_queue *rx_queue = container_of(napi,
  1265. struct vmxnet3_rx_queue, napi);
  1266. int rxd_done;
  1267. rxd_done = vmxnet3_do_poll(rx_queue->adapter, budget);
  1268. if (rxd_done < budget) {
  1269. napi_complete(napi);
  1270. vmxnet3_enable_all_intrs(rx_queue->adapter);
  1271. }
  1272. return rxd_done;
  1273. }
  1274. /*
  1275. * NAPI polling function for MSI-X mode with multiple Rx queues
  1276. * Returns the # of the NAPI credit consumed (# of rx descriptors processed)
  1277. */
  1278. static int
  1279. vmxnet3_poll_rx_only(struct napi_struct *napi, int budget)
  1280. {
  1281. struct vmxnet3_rx_queue *rq = container_of(napi,
  1282. struct vmxnet3_rx_queue, napi);
  1283. struct vmxnet3_adapter *adapter = rq->adapter;
  1284. int rxd_done;
  1285. /* When sharing interrupt with corresponding tx queue, process
  1286. * tx completions in that queue as well
  1287. */
  1288. if (adapter->share_intr == VMXNET3_INTR_BUDDYSHARE) {
  1289. struct vmxnet3_tx_queue *tq =
  1290. &adapter->tx_queue[rq - adapter->rx_queue];
  1291. vmxnet3_tq_tx_complete(tq, adapter);
  1292. }
  1293. rxd_done = vmxnet3_rq_rx_complete(rq, adapter, budget);
  1294. if (rxd_done < budget) {
  1295. napi_complete(napi);
  1296. vmxnet3_enable_intr(adapter, rq->comp_ring.intr_idx);
  1297. }
  1298. return rxd_done;
  1299. }
  1300. #ifdef CONFIG_PCI_MSI
  1301. /*
  1302. * Handle completion interrupts on tx queues
  1303. * Returns whether or not the intr is handled
  1304. */
  1305. static irqreturn_t
  1306. vmxnet3_msix_tx(int irq, void *data)
  1307. {
  1308. struct vmxnet3_tx_queue *tq = data;
  1309. struct vmxnet3_adapter *adapter = tq->adapter;
  1310. if (adapter->intr.mask_mode == VMXNET3_IMM_ACTIVE)
  1311. vmxnet3_disable_intr(adapter, tq->comp_ring.intr_idx);
  1312. /* Handle the case where only one irq is allocate for all tx queues */
  1313. if (adapter->share_intr == VMXNET3_INTR_TXSHARE) {
  1314. int i;
  1315. for (i = 0; i < adapter->num_tx_queues; i++) {
  1316. struct vmxnet3_tx_queue *txq = &adapter->tx_queue[i];
  1317. vmxnet3_tq_tx_complete(txq, adapter);
  1318. }
  1319. } else {
  1320. vmxnet3_tq_tx_complete(tq, adapter);
  1321. }
  1322. vmxnet3_enable_intr(adapter, tq->comp_ring.intr_idx);
  1323. return IRQ_HANDLED;
  1324. }
  1325. /*
  1326. * Handle completion interrupts on rx queues. Returns whether or not the
  1327. * intr is handled
  1328. */
  1329. static irqreturn_t
  1330. vmxnet3_msix_rx(int irq, void *data)
  1331. {
  1332. struct vmxnet3_rx_queue *rq = data;
  1333. struct vmxnet3_adapter *adapter = rq->adapter;
  1334. /* disable intr if needed */
  1335. if (adapter->intr.mask_mode == VMXNET3_IMM_ACTIVE)
  1336. vmxnet3_disable_intr(adapter, rq->comp_ring.intr_idx);
  1337. napi_schedule(&rq->napi);
  1338. return IRQ_HANDLED;
  1339. }
  1340. /*
  1341. *----------------------------------------------------------------------------
  1342. *
  1343. * vmxnet3_msix_event --
  1344. *
  1345. * vmxnet3 msix event intr handler
  1346. *
  1347. * Result:
  1348. * whether or not the intr is handled
  1349. *
  1350. *----------------------------------------------------------------------------
  1351. */
  1352. static irqreturn_t
  1353. vmxnet3_msix_event(int irq, void *data)
  1354. {
  1355. struct net_device *dev = data;
  1356. struct vmxnet3_adapter *adapter = netdev_priv(dev);
  1357. /* disable intr if needed */
  1358. if (adapter->intr.mask_mode == VMXNET3_IMM_ACTIVE)
  1359. vmxnet3_disable_intr(adapter, adapter->intr.event_intr_idx);
  1360. if (adapter->shared->ecr)
  1361. vmxnet3_process_events(adapter);
  1362. vmxnet3_enable_intr(adapter, adapter->intr.event_intr_idx);
  1363. return IRQ_HANDLED;
  1364. }
  1365. #endif /* CONFIG_PCI_MSI */
  1366. /* Interrupt handler for vmxnet3 */
  1367. static irqreturn_t
  1368. vmxnet3_intr(int irq, void *dev_id)
  1369. {
  1370. struct net_device *dev = dev_id;
  1371. struct vmxnet3_adapter *adapter = netdev_priv(dev);
  1372. if (adapter->intr.type == VMXNET3_IT_INTX) {
  1373. u32 icr = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_ICR);
  1374. if (unlikely(icr == 0))
  1375. /* not ours */
  1376. return IRQ_NONE;
  1377. }
  1378. /* disable intr if needed */
  1379. if (adapter->intr.mask_mode == VMXNET3_IMM_ACTIVE)
  1380. vmxnet3_disable_all_intrs(adapter);
  1381. napi_schedule(&adapter->rx_queue[0].napi);
  1382. return IRQ_HANDLED;
  1383. }
  1384. #ifdef CONFIG_NET_POLL_CONTROLLER
  1385. /* netpoll callback. */
  1386. static void
  1387. vmxnet3_netpoll(struct net_device *netdev)
  1388. {
  1389. struct vmxnet3_adapter *adapter = netdev_priv(netdev);
  1390. if (adapter->intr.mask_mode == VMXNET3_IMM_ACTIVE)
  1391. vmxnet3_disable_all_intrs(adapter);
  1392. vmxnet3_do_poll(adapter, adapter->rx_queue[0].rx_ring[0].size);
  1393. vmxnet3_enable_all_intrs(adapter);
  1394. }
  1395. #endif /* CONFIG_NET_POLL_CONTROLLER */
  1396. static int
  1397. vmxnet3_request_irqs(struct vmxnet3_adapter *adapter)
  1398. {
  1399. struct vmxnet3_intr *intr = &adapter->intr;
  1400. int err = 0, i;
  1401. int vector = 0;
  1402. #ifdef CONFIG_PCI_MSI
  1403. if (adapter->intr.type == VMXNET3_IT_MSIX) {
  1404. for (i = 0; i < adapter->num_tx_queues; i++) {
  1405. if (adapter->share_intr != VMXNET3_INTR_BUDDYSHARE) {
  1406. sprintf(adapter->tx_queue[i].name, "%s-tx-%d",
  1407. adapter->netdev->name, vector);
  1408. err = request_irq(
  1409. intr->msix_entries[vector].vector,
  1410. vmxnet3_msix_tx, 0,
  1411. adapter->tx_queue[i].name,
  1412. &adapter->tx_queue[i]);
  1413. } else {
  1414. sprintf(adapter->tx_queue[i].name, "%s-rxtx-%d",
  1415. adapter->netdev->name, vector);
  1416. }
  1417. if (err) {
  1418. dev_err(&adapter->netdev->dev,
  1419. "Failed to request irq for MSIX, %s, "
  1420. "error %d\n",
  1421. adapter->tx_queue[i].name, err);
  1422. return err;
  1423. }
  1424. /* Handle the case where only 1 MSIx was allocated for
  1425. * all tx queues */
  1426. if (adapter->share_intr == VMXNET3_INTR_TXSHARE) {
  1427. for (; i < adapter->num_tx_queues; i++)
  1428. adapter->tx_queue[i].comp_ring.intr_idx
  1429. = vector;
  1430. vector++;
  1431. break;
  1432. } else {
  1433. adapter->tx_queue[i].comp_ring.intr_idx
  1434. = vector++;
  1435. }
  1436. }
  1437. if (adapter->share_intr == VMXNET3_INTR_BUDDYSHARE)
  1438. vector = 0;
  1439. for (i = 0; i < adapter->num_rx_queues; i++) {
  1440. if (adapter->share_intr != VMXNET3_INTR_BUDDYSHARE)
  1441. sprintf(adapter->rx_queue[i].name, "%s-rx-%d",
  1442. adapter->netdev->name, vector);
  1443. else
  1444. sprintf(adapter->rx_queue[i].name, "%s-rxtx-%d",
  1445. adapter->netdev->name, vector);
  1446. err = request_irq(intr->msix_entries[vector].vector,
  1447. vmxnet3_msix_rx, 0,
  1448. adapter->rx_queue[i].name,
  1449. &(adapter->rx_queue[i]));
  1450. if (err) {
  1451. printk(KERN_ERR "Failed to request irq for MSIX"
  1452. ", %s, error %d\n",
  1453. adapter->rx_queue[i].name, err);
  1454. return err;
  1455. }
  1456. adapter->rx_queue[i].comp_ring.intr_idx = vector++;
  1457. }
  1458. sprintf(intr->event_msi_vector_name, "%s-event-%d",
  1459. adapter->netdev->name, vector);
  1460. err = request_irq(intr->msix_entries[vector].vector,
  1461. vmxnet3_msix_event, 0,
  1462. intr->event_msi_vector_name, adapter->netdev);
  1463. intr->event_intr_idx = vector;
  1464. } else if (intr->type == VMXNET3_IT_MSI) {
  1465. adapter->num_rx_queues = 1;
  1466. err = request_irq(adapter->pdev->irq, vmxnet3_intr, 0,
  1467. adapter->netdev->name, adapter->netdev);
  1468. } else {
  1469. #endif
  1470. adapter->num_rx_queues = 1;
  1471. err = request_irq(adapter->pdev->irq, vmxnet3_intr,
  1472. IRQF_SHARED, adapter->netdev->name,
  1473. adapter->netdev);
  1474. #ifdef CONFIG_PCI_MSI
  1475. }
  1476. #endif
  1477. intr->num_intrs = vector + 1;
  1478. if (err) {
  1479. printk(KERN_ERR "Failed to request irq %s (intr type:%d), error"
  1480. ":%d\n", adapter->netdev->name, intr->type, err);
  1481. } else {
  1482. /* Number of rx queues will not change after this */
  1483. for (i = 0; i < adapter->num_rx_queues; i++) {
  1484. struct vmxnet3_rx_queue *rq = &adapter->rx_queue[i];
  1485. rq->qid = i;
  1486. rq->qid2 = i + adapter->num_rx_queues;
  1487. }
  1488. /* init our intr settings */
  1489. for (i = 0; i < intr->num_intrs; i++)
  1490. intr->mod_levels[i] = UPT1_IML_ADAPTIVE;
  1491. if (adapter->intr.type != VMXNET3_IT_MSIX) {
  1492. adapter->intr.event_intr_idx = 0;
  1493. for (i = 0; i < adapter->num_tx_queues; i++)
  1494. adapter->tx_queue[i].comp_ring.intr_idx = 0;
  1495. adapter->rx_queue[0].comp_ring.intr_idx = 0;
  1496. }
  1497. printk(KERN_INFO "%s: intr type %u, mode %u, %u vectors "
  1498. "allocated\n", adapter->netdev->name, intr->type,
  1499. intr->mask_mode, intr->num_intrs);
  1500. }
  1501. return err;
  1502. }
  1503. static void
  1504. vmxnet3_free_irqs(struct vmxnet3_adapter *adapter)
  1505. {
  1506. struct vmxnet3_intr *intr = &adapter->intr;
  1507. BUG_ON(intr->type == VMXNET3_IT_AUTO || intr->num_intrs <= 0);
  1508. switch (intr->type) {
  1509. #ifdef CONFIG_PCI_MSI
  1510. case VMXNET3_IT_MSIX:
  1511. {
  1512. int i, vector = 0;
  1513. if (adapter->share_intr != VMXNET3_INTR_BUDDYSHARE) {
  1514. for (i = 0; i < adapter->num_tx_queues; i++) {
  1515. free_irq(intr->msix_entries[vector++].vector,
  1516. &(adapter->tx_queue[i]));
  1517. if (adapter->share_intr == VMXNET3_INTR_TXSHARE)
  1518. break;
  1519. }
  1520. }
  1521. for (i = 0; i < adapter->num_rx_queues; i++) {
  1522. free_irq(intr->msix_entries[vector++].vector,
  1523. &(adapter->rx_queue[i]));
  1524. }
  1525. free_irq(intr->msix_entries[vector].vector,
  1526. adapter->netdev);
  1527. BUG_ON(vector >= intr->num_intrs);
  1528. break;
  1529. }
  1530. #endif
  1531. case VMXNET3_IT_MSI:
  1532. free_irq(adapter->pdev->irq, adapter->netdev);
  1533. break;
  1534. case VMXNET3_IT_INTX:
  1535. free_irq(adapter->pdev->irq, adapter->netdev);
  1536. break;
  1537. default:
  1538. BUG_ON(true);
  1539. }
  1540. }
  1541. static void
  1542. vmxnet3_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
  1543. {
  1544. struct vmxnet3_adapter *adapter = netdev_priv(netdev);
  1545. struct Vmxnet3_DriverShared *shared = adapter->shared;
  1546. u32 *vfTable = adapter->shared->devRead.rxFilterConf.vfTable;
  1547. if (grp) {
  1548. /* add vlan rx stripping. */
  1549. if (adapter->netdev->features & NETIF_F_HW_VLAN_RX) {
  1550. int i;
  1551. struct Vmxnet3_DSDevRead *devRead = &shared->devRead;
  1552. adapter->vlan_grp = grp;
  1553. /* update FEATURES to device */
  1554. devRead->misc.uptFeatures |= UPT1_F_RXVLAN;
  1555. VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
  1556. VMXNET3_CMD_UPDATE_FEATURE);
  1557. /*
  1558. * Clear entire vfTable; then enable untagged pkts.
  1559. * Note: setting one entry in vfTable to non-zero turns
  1560. * on VLAN rx filtering.
  1561. */
  1562. for (i = 0; i < VMXNET3_VFT_SIZE; i++)
  1563. vfTable[i] = 0;
  1564. VMXNET3_SET_VFTABLE_ENTRY(vfTable, 0);
  1565. VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
  1566. VMXNET3_CMD_UPDATE_VLAN_FILTERS);
  1567. } else {
  1568. printk(KERN_ERR "%s: vlan_rx_register when device has "
  1569. "no NETIF_F_HW_VLAN_RX\n", netdev->name);
  1570. }
  1571. } else {
  1572. /* remove vlan rx stripping. */
  1573. struct Vmxnet3_DSDevRead *devRead = &shared->devRead;
  1574. adapter->vlan_grp = NULL;
  1575. if (devRead->misc.uptFeatures & UPT1_F_RXVLAN) {
  1576. int i;
  1577. for (i = 0; i < VMXNET3_VFT_SIZE; i++) {
  1578. /* clear entire vfTable; this also disables
  1579. * VLAN rx filtering
  1580. */
  1581. vfTable[i] = 0;
  1582. }
  1583. VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
  1584. VMXNET3_CMD_UPDATE_VLAN_FILTERS);
  1585. /* update FEATURES to device */
  1586. devRead->misc.uptFeatures &= ~UPT1_F_RXVLAN;
  1587. VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
  1588. VMXNET3_CMD_UPDATE_FEATURE);
  1589. }
  1590. }
  1591. }
  1592. static void
  1593. vmxnet3_restore_vlan(struct vmxnet3_adapter *adapter)
  1594. {
  1595. if (adapter->vlan_grp) {
  1596. u16 vid;
  1597. u32 *vfTable = adapter->shared->devRead.rxFilterConf.vfTable;
  1598. bool activeVlan = false;
  1599. for (vid = 0; vid < VLAN_N_VID; vid++) {
  1600. if (vlan_group_get_device(adapter->vlan_grp, vid)) {
  1601. VMXNET3_SET_VFTABLE_ENTRY(vfTable, vid);
  1602. activeVlan = true;
  1603. }
  1604. }
  1605. if (activeVlan) {
  1606. /* continue to allow untagged pkts */
  1607. VMXNET3_SET_VFTABLE_ENTRY(vfTable, 0);
  1608. }
  1609. }
  1610. }
  1611. static void
  1612. vmxnet3_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
  1613. {
  1614. struct vmxnet3_adapter *adapter = netdev_priv(netdev);
  1615. u32 *vfTable = adapter->shared->devRead.rxFilterConf.vfTable;
  1616. VMXNET3_SET_VFTABLE_ENTRY(vfTable, vid);
  1617. VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
  1618. VMXNET3_CMD_UPDATE_VLAN_FILTERS);
  1619. }
  1620. static void
  1621. vmxnet3_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
  1622. {
  1623. struct vmxnet3_adapter *adapter = netdev_priv(netdev);
  1624. u32 *vfTable = adapter->shared->devRead.rxFilterConf.vfTable;
  1625. VMXNET3_CLEAR_VFTABLE_ENTRY(vfTable, vid);
  1626. VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
  1627. VMXNET3_CMD_UPDATE_VLAN_FILTERS);
  1628. }
  1629. static u8 *
  1630. vmxnet3_copy_mc(struct net_device *netdev)
  1631. {
  1632. u8 *buf = NULL;
  1633. u32 sz = netdev_mc_count(netdev) * ETH_ALEN;
  1634. /* struct Vmxnet3_RxFilterConf.mfTableLen is u16. */
  1635. if (sz <= 0xffff) {
  1636. /* We may be called with BH disabled */
  1637. buf = kmalloc(sz, GFP_ATOMIC);
  1638. if (buf) {
  1639. struct netdev_hw_addr *ha;
  1640. int i = 0;
  1641. netdev_for_each_mc_addr(ha, netdev)
  1642. memcpy(buf + i++ * ETH_ALEN, ha->addr,
  1643. ETH_ALEN);
  1644. }
  1645. }
  1646. return buf;
  1647. }
  1648. static void
  1649. vmxnet3_set_mc(struct net_device *netdev)
  1650. {
  1651. struct vmxnet3_adapter *adapter = netdev_priv(netdev);
  1652. struct Vmxnet3_RxFilterConf *rxConf =
  1653. &adapter->shared->devRead.rxFilterConf;
  1654. u8 *new_table = NULL;
  1655. u32 new_mode = VMXNET3_RXM_UCAST;
  1656. if (netdev->flags & IFF_PROMISC)
  1657. new_mode |= VMXNET3_RXM_PROMISC;
  1658. if (netdev->flags & IFF_BROADCAST)
  1659. new_mode |= VMXNET3_RXM_BCAST;
  1660. if (netdev->flags & IFF_ALLMULTI)
  1661. new_mode |= VMXNET3_RXM_ALL_MULTI;
  1662. else
  1663. if (!netdev_mc_empty(netdev)) {
  1664. new_table = vmxnet3_copy_mc(netdev);
  1665. if (new_table) {
  1666. new_mode |= VMXNET3_RXM_MCAST;
  1667. rxConf->mfTableLen = cpu_to_le16(
  1668. netdev_mc_count(netdev) * ETH_ALEN);
  1669. rxConf->mfTablePA = cpu_to_le64(virt_to_phys(
  1670. new_table));
  1671. } else {
  1672. printk(KERN_INFO "%s: failed to copy mcast list"
  1673. ", setting ALL_MULTI\n", netdev->name);
  1674. new_mode |= VMXNET3_RXM_ALL_MULTI;
  1675. }
  1676. }
  1677. if (!(new_mode & VMXNET3_RXM_MCAST)) {
  1678. rxConf->mfTableLen = 0;
  1679. rxConf->mfTablePA = 0;
  1680. }
  1681. if (new_mode != rxConf->rxMode) {
  1682. rxConf->rxMode = cpu_to_le32(new_mode);
  1683. VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
  1684. VMXNET3_CMD_UPDATE_RX_MODE);
  1685. }
  1686. VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
  1687. VMXNET3_CMD_UPDATE_MAC_FILTERS);
  1688. kfree(new_table);
  1689. }
  1690. void
  1691. vmxnet3_rq_destroy_all(struct vmxnet3_adapter *adapter)
  1692. {
  1693. int i;
  1694. for (i = 0; i < adapter->num_rx_queues; i++)
  1695. vmxnet3_rq_destroy(&adapter->rx_queue[i], adapter);
  1696. }
  1697. /*
  1698. * Set up driver_shared based on settings in adapter.
  1699. */
  1700. static void
  1701. vmxnet3_setup_driver_shared(struct vmxnet3_adapter *adapter)
  1702. {
  1703. struct Vmxnet3_DriverShared *shared = adapter->shared;
  1704. struct Vmxnet3_DSDevRead *devRead = &shared->devRead;
  1705. struct Vmxnet3_TxQueueConf *tqc;
  1706. struct Vmxnet3_RxQueueConf *rqc;
  1707. int i;
  1708. memset(shared, 0, sizeof(*shared));
  1709. /* driver settings */
  1710. shared->magic = cpu_to_le32(VMXNET3_REV1_MAGIC);
  1711. devRead->misc.driverInfo.version = cpu_to_le32(
  1712. VMXNET3_DRIVER_VERSION_NUM);
  1713. devRead->misc.driverInfo.gos.gosBits = (sizeof(void *) == 4 ?
  1714. VMXNET3_GOS_BITS_32 : VMXNET3_GOS_BITS_64);
  1715. devRead->misc.driverInfo.gos.gosType = VMXNET3_GOS_TYPE_LINUX;
  1716. *((u32 *)&devRead->misc.driverInfo.gos) = cpu_to_le32(
  1717. *((u32 *)&devRead->misc.driverInfo.gos));
  1718. devRead->misc.driverInfo.vmxnet3RevSpt = cpu_to_le32(1);
  1719. devRead->misc.driverInfo.uptVerSpt = cpu_to_le32(1);
  1720. devRead->misc.ddPA = cpu_to_le64(virt_to_phys(adapter));
  1721. devRead->misc.ddLen = cpu_to_le32(sizeof(struct vmxnet3_adapter));
  1722. /* set up feature flags */
  1723. if (adapter->rxcsum)
  1724. devRead->misc.uptFeatures |= UPT1_F_RXCSUM;
  1725. if (adapter->lro) {
  1726. devRead->misc.uptFeatures |= UPT1_F_LRO;
  1727. devRead->misc.maxNumRxSG = cpu_to_le16(1 + MAX_SKB_FRAGS);
  1728. }
  1729. if ((adapter->netdev->features & NETIF_F_HW_VLAN_RX) &&
  1730. adapter->vlan_grp) {
  1731. devRead->misc.uptFeatures |= UPT1_F_RXVLAN;
  1732. }
  1733. devRead->misc.mtu = cpu_to_le32(adapter->netdev->mtu);
  1734. devRead->misc.queueDescPA = cpu_to_le64(adapter->queue_desc_pa);
  1735. devRead->misc.queueDescLen = cpu_to_le32(
  1736. adapter->num_tx_queues * sizeof(struct Vmxnet3_TxQueueDesc) +
  1737. adapter->num_rx_queues * sizeof(struct Vmxnet3_RxQueueDesc));
  1738. /* tx queue settings */
  1739. devRead->misc.numTxQueues = adapter->num_tx_queues;
  1740. for (i = 0; i < adapter->num_tx_queues; i++) {
  1741. struct vmxnet3_tx_queue *tq = &adapter->tx_queue[i];
  1742. BUG_ON(adapter->tx_queue[i].tx_ring.base == NULL);
  1743. tqc = &adapter->tqd_start[i].conf;
  1744. tqc->txRingBasePA = cpu_to_le64(tq->tx_ring.basePA);
  1745. tqc->dataRingBasePA = cpu_to_le64(tq->data_ring.basePA);
  1746. tqc->compRingBasePA = cpu_to_le64(tq->comp_ring.basePA);
  1747. tqc->ddPA = cpu_to_le64(virt_to_phys(tq->buf_info));
  1748. tqc->txRingSize = cpu_to_le32(tq->tx_ring.size);
  1749. tqc->dataRingSize = cpu_to_le32(tq->data_ring.size);
  1750. tqc->compRingSize = cpu_to_le32(tq->comp_ring.size);
  1751. tqc->ddLen = cpu_to_le32(
  1752. sizeof(struct vmxnet3_tx_buf_info) *
  1753. tqc->txRingSize);
  1754. tqc->intrIdx = tq->comp_ring.intr_idx;
  1755. }
  1756. /* rx queue settings */
  1757. devRead->misc.numRxQueues = adapter->num_rx_queues;
  1758. for (i = 0; i < adapter->num_rx_queues; i++) {
  1759. struct vmxnet3_rx_queue *rq = &adapter->rx_queue[i];
  1760. rqc = &adapter->rqd_start[i].conf;
  1761. rqc->rxRingBasePA[0] = cpu_to_le64(rq->rx_ring[0].basePA);
  1762. rqc->rxRingBasePA[1] = cpu_to_le64(rq->rx_ring[1].basePA);
  1763. rqc->compRingBasePA = cpu_to_le64(rq->comp_ring.basePA);
  1764. rqc->ddPA = cpu_to_le64(virt_to_phys(
  1765. rq->buf_info));
  1766. rqc->rxRingSize[0] = cpu_to_le32(rq->rx_ring[0].size);
  1767. rqc->rxRingSize[1] = cpu_to_le32(rq->rx_ring[1].size);
  1768. rqc->compRingSize = cpu_to_le32(rq->comp_ring.size);
  1769. rqc->ddLen = cpu_to_le32(
  1770. sizeof(struct vmxnet3_rx_buf_info) *
  1771. (rqc->rxRingSize[0] +
  1772. rqc->rxRingSize[1]));
  1773. rqc->intrIdx = rq->comp_ring.intr_idx;
  1774. }
  1775. #ifdef VMXNET3_RSS
  1776. memset(adapter->rss_conf, 0, sizeof(*adapter->rss_conf));
  1777. if (adapter->rss) {
  1778. struct UPT1_RSSConf *rssConf = adapter->rss_conf;
  1779. devRead->misc.uptFeatures |= UPT1_F_RSS;
  1780. devRead->misc.numRxQueues = adapter->num_rx_queues;
  1781. rssConf->hashType = UPT1_RSS_HASH_TYPE_TCP_IPV4 |
  1782. UPT1_RSS_HASH_TYPE_IPV4 |
  1783. UPT1_RSS_HASH_TYPE_TCP_IPV6 |
  1784. UPT1_RSS_HASH_TYPE_IPV6;
  1785. rssConf->hashFunc = UPT1_RSS_HASH_FUNC_TOEPLITZ;
  1786. rssConf->hashKeySize = UPT1_RSS_MAX_KEY_SIZE;
  1787. rssConf->indTableSize = VMXNET3_RSS_IND_TABLE_SIZE;
  1788. get_random_bytes(&rssConf->hashKey[0], rssConf->hashKeySize);
  1789. for (i = 0; i < rssConf->indTableSize; i++)
  1790. rssConf->indTable[i] = i % adapter->num_rx_queues;
  1791. devRead->rssConfDesc.confVer = 1;
  1792. devRead->rssConfDesc.confLen = sizeof(*rssConf);
  1793. devRead->rssConfDesc.confPA = virt_to_phys(rssConf);
  1794. }
  1795. #endif /* VMXNET3_RSS */
  1796. /* intr settings */
  1797. devRead->intrConf.autoMask = adapter->intr.mask_mode ==
  1798. VMXNET3_IMM_AUTO;
  1799. devRead->intrConf.numIntrs = adapter->intr.num_intrs;
  1800. for (i = 0; i < adapter->intr.num_intrs; i++)
  1801. devRead->intrConf.modLevels[i] = adapter->intr.mod_levels[i];
  1802. devRead->intrConf.eventIntrIdx = adapter->intr.event_intr_idx;
  1803. devRead->intrConf.intrCtrl |= cpu_to_le32(VMXNET3_IC_DISABLE_ALL);
  1804. /* rx filter settings */
  1805. devRead->rxFilterConf.rxMode = 0;
  1806. vmxnet3_restore_vlan(adapter);
  1807. /* the rest are already zeroed */
  1808. }
  1809. int
  1810. vmxnet3_activate_dev(struct vmxnet3_adapter *adapter)
  1811. {
  1812. int err, i;
  1813. u32 ret;
  1814. dev_dbg(&adapter->netdev->dev, "%s: skb_buf_size %d, rx_buf_per_pkt %d,"
  1815. " ring sizes %u %u %u\n", adapter->netdev->name,
  1816. adapter->skb_buf_size, adapter->rx_buf_per_pkt,
  1817. adapter->tx_queue[0].tx_ring.size,
  1818. adapter->rx_queue[0].rx_ring[0].size,
  1819. adapter->rx_queue[0].rx_ring[1].size);
  1820. vmxnet3_tq_init_all(adapter);
  1821. err = vmxnet3_rq_init_all(adapter);
  1822. if (err) {
  1823. printk(KERN_ERR "Failed to init rx queue for %s: error %d\n",
  1824. adapter->netdev->name, err);
  1825. goto rq_err;
  1826. }
  1827. err = vmxnet3_request_irqs(adapter);
  1828. if (err) {
  1829. printk(KERN_ERR "Failed to setup irq for %s: error %d\n",
  1830. adapter->netdev->name, err);
  1831. goto irq_err;
  1832. }
  1833. vmxnet3_setup_driver_shared(adapter);
  1834. VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_DSAL, VMXNET3_GET_ADDR_LO(
  1835. adapter->shared_pa));
  1836. VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_DSAH, VMXNET3_GET_ADDR_HI(
  1837. adapter->shared_pa));
  1838. VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
  1839. VMXNET3_CMD_ACTIVATE_DEV);
  1840. ret = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_CMD);
  1841. if (ret != 0) {
  1842. printk(KERN_ERR "Failed to activate dev %s: error %u\n",
  1843. adapter->netdev->name, ret);
  1844. err = -EINVAL;
  1845. goto activate_err;
  1846. }
  1847. for (i = 0; i < adapter->num_rx_queues; i++) {
  1848. VMXNET3_WRITE_BAR0_REG(adapter,
  1849. VMXNET3_REG_RXPROD + i * VMXNET3_REG_ALIGN,
  1850. adapter->rx_queue[i].rx_ring[0].next2fill);
  1851. VMXNET3_WRITE_BAR0_REG(adapter, (VMXNET3_REG_RXPROD2 +
  1852. (i * VMXNET3_REG_ALIGN)),
  1853. adapter->rx_queue[i].rx_ring[1].next2fill);
  1854. }
  1855. /* Apply the rx filter settins last. */
  1856. vmxnet3_set_mc(adapter->netdev);
  1857. /*
  1858. * Check link state when first activating device. It will start the
  1859. * tx queue if the link is up.
  1860. */
  1861. vmxnet3_check_link(adapter, true);
  1862. for (i = 0; i < adapter->num_rx_queues; i++)
  1863. napi_enable(&adapter->rx_queue[i].napi);
  1864. vmxnet3_enable_all_intrs(adapter);
  1865. clear_bit(VMXNET3_STATE_BIT_QUIESCED, &adapter->state);
  1866. return 0;
  1867. activate_err:
  1868. VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_DSAL, 0);
  1869. VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_DSAH, 0);
  1870. vmxnet3_free_irqs(adapter);
  1871. irq_err:
  1872. rq_err:
  1873. /* free up buffers we allocated */
  1874. vmxnet3_rq_cleanup_all(adapter);
  1875. return err;
  1876. }
  1877. void
  1878. vmxnet3_reset_dev(struct vmxnet3_adapter *adapter)
  1879. {
  1880. VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD, VMXNET3_CMD_RESET_DEV);
  1881. }
  1882. int
  1883. vmxnet3_quiesce_dev(struct vmxnet3_adapter *adapter)
  1884. {
  1885. int i;
  1886. if (test_and_set_bit(VMXNET3_STATE_BIT_QUIESCED, &adapter->state))
  1887. return 0;
  1888. VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
  1889. VMXNET3_CMD_QUIESCE_DEV);
  1890. vmxnet3_disable_all_intrs(adapter);
  1891. for (i = 0; i < adapter->num_rx_queues; i++)
  1892. napi_disable(&adapter->rx_queue[i].napi);
  1893. netif_tx_disable(adapter->netdev);
  1894. adapter->link_speed = 0;
  1895. netif_carrier_off(adapter->netdev);
  1896. vmxnet3_tq_cleanup_all(adapter);
  1897. vmxnet3_rq_cleanup_all(adapter);
  1898. vmxnet3_free_irqs(adapter);
  1899. return 0;
  1900. }
  1901. static void
  1902. vmxnet3_write_mac_addr(struct vmxnet3_adapter *adapter, u8 *mac)
  1903. {
  1904. u32 tmp;
  1905. tmp = *(u32 *)mac;
  1906. VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_MACL, tmp);
  1907. tmp = (mac[5] << 8) | mac[4];
  1908. VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_MACH, tmp);
  1909. }
  1910. static int
  1911. vmxnet3_set_mac_addr(struct net_device *netdev, void *p)
  1912. {
  1913. struct sockaddr *addr = p;
  1914. struct vmxnet3_adapter *adapter = netdev_priv(netdev);
  1915. memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
  1916. vmxnet3_write_mac_addr(adapter, addr->sa_data);
  1917. return 0;
  1918. }
  1919. /* ==================== initialization and cleanup routines ============ */
  1920. static int
  1921. vmxnet3_alloc_pci_resources(struct vmxnet3_adapter *adapter, bool *dma64)
  1922. {
  1923. int err;
  1924. unsigned long mmio_start, mmio_len;
  1925. struct pci_dev *pdev = adapter->pdev;
  1926. err = pci_enable_device(pdev);
  1927. if (err) {
  1928. printk(KERN_ERR "Failed to enable adapter %s: error %d\n",
  1929. pci_name(pdev), err);
  1930. return err;
  1931. }
  1932. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) == 0) {
  1933. if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)) != 0) {
  1934. printk(KERN_ERR "pci_set_consistent_dma_mask failed "
  1935. "for adapter %s\n", pci_name(pdev));
  1936. err = -EIO;
  1937. goto err_set_mask;
  1938. }
  1939. *dma64 = true;
  1940. } else {
  1941. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) {
  1942. printk(KERN_ERR "pci_set_dma_mask failed for adapter "
  1943. "%s\n", pci_name(pdev));
  1944. err = -EIO;
  1945. goto err_set_mask;
  1946. }
  1947. *dma64 = false;
  1948. }
  1949. err = pci_request_selected_regions(pdev, (1 << 2) - 1,
  1950. vmxnet3_driver_name);
  1951. if (err) {
  1952. printk(KERN_ERR "Failed to request region for adapter %s: "
  1953. "error %d\n", pci_name(pdev), err);
  1954. goto err_set_mask;
  1955. }
  1956. pci_set_master(pdev);
  1957. mmio_start = pci_resource_start(pdev, 0);
  1958. mmio_len = pci_resource_len(pdev, 0);
  1959. adapter->hw_addr0 = ioremap(mmio_start, mmio_len);
  1960. if (!adapter->hw_addr0) {
  1961. printk(KERN_ERR "Failed to map bar0 for adapter %s\n",
  1962. pci_name(pdev));
  1963. err = -EIO;
  1964. goto err_ioremap;
  1965. }
  1966. mmio_start = pci_resource_start(pdev, 1);
  1967. mmio_len = pci_resource_len(pdev, 1);
  1968. adapter->hw_addr1 = ioremap(mmio_start, mmio_len);
  1969. if (!adapter->hw_addr1) {
  1970. printk(KERN_ERR "Failed to map bar1 for adapter %s\n",
  1971. pci_name(pdev));
  1972. err = -EIO;
  1973. goto err_bar1;
  1974. }
  1975. return 0;
  1976. err_bar1:
  1977. iounmap(adapter->hw_addr0);
  1978. err_ioremap:
  1979. pci_release_selected_regions(pdev, (1 << 2) - 1);
  1980. err_set_mask:
  1981. pci_disable_device(pdev);
  1982. return err;
  1983. }
  1984. static void
  1985. vmxnet3_free_pci_resources(struct vmxnet3_adapter *adapter)
  1986. {
  1987. BUG_ON(!adapter->pdev);
  1988. iounmap(adapter->hw_addr0);
  1989. iounmap(adapter->hw_addr1);
  1990. pci_release_selected_regions(adapter->pdev, (1 << 2) - 1);
  1991. pci_disable_device(adapter->pdev);
  1992. }
  1993. static void
  1994. vmxnet3_adjust_rx_ring_size(struct vmxnet3_adapter *adapter)
  1995. {
  1996. size_t sz, i, ring0_size, ring1_size, comp_size;
  1997. struct vmxnet3_rx_queue *rq = &adapter->rx_queue[0];
  1998. if (adapter->netdev->mtu <= VMXNET3_MAX_SKB_BUF_SIZE -
  1999. VMXNET3_MAX_ETH_HDR_SIZE) {
  2000. adapter->skb_buf_size = adapter->netdev->mtu +
  2001. VMXNET3_MAX_ETH_HDR_SIZE;
  2002. if (adapter->skb_buf_size < VMXNET3_MIN_T0_BUF_SIZE)
  2003. adapter->skb_buf_size = VMXNET3_MIN_T0_BUF_SIZE;
  2004. adapter->rx_buf_per_pkt = 1;
  2005. } else {
  2006. adapter->skb_buf_size = VMXNET3_MAX_SKB_BUF_SIZE;
  2007. sz = adapter->netdev->mtu - VMXNET3_MAX_SKB_BUF_SIZE +
  2008. VMXNET3_MAX_ETH_HDR_SIZE;
  2009. adapter->rx_buf_per_pkt = 1 + (sz + PAGE_SIZE - 1) / PAGE_SIZE;
  2010. }
  2011. /*
  2012. * for simplicity, force the ring0 size to be a multiple of
  2013. * rx_buf_per_pkt * VMXNET3_RING_SIZE_ALIGN
  2014. */
  2015. sz = adapter->rx_buf_per_pkt * VMXNET3_RING_SIZE_ALIGN;
  2016. ring0_size = adapter->rx_queue[0].rx_ring[0].size;
  2017. ring0_size = (ring0_size + sz - 1) / sz * sz;
  2018. ring0_size = min_t(u32, rq->rx_ring[0].size, VMXNET3_RX_RING_MAX_SIZE /
  2019. sz * sz);
  2020. ring1_size = adapter->rx_queue[0].rx_ring[1].size;
  2021. comp_size = ring0_size + ring1_size;
  2022. for (i = 0; i < adapter->num_rx_queues; i++) {
  2023. rq = &adapter->rx_queue[i];
  2024. rq->rx_ring[0].size = ring0_size;
  2025. rq->rx_ring[1].size = ring1_size;
  2026. rq->comp_ring.size = comp_size;
  2027. }
  2028. }
  2029. int
  2030. vmxnet3_create_queues(struct vmxnet3_adapter *adapter, u32 tx_ring_size,
  2031. u32 rx_ring_size, u32 rx_ring2_size)
  2032. {
  2033. int err = 0, i;
  2034. for (i = 0; i < adapter->num_tx_queues; i++) {
  2035. struct vmxnet3_tx_queue *tq = &adapter->tx_queue[i];
  2036. tq->tx_ring.size = tx_ring_size;
  2037. tq->data_ring.size = tx_ring_size;
  2038. tq->comp_ring.size = tx_ring_size;
  2039. tq->shared = &adapter->tqd_start[i].ctrl;
  2040. tq->stopped = true;
  2041. tq->adapter = adapter;
  2042. tq->qid = i;
  2043. err = vmxnet3_tq_create(tq, adapter);
  2044. /*
  2045. * Too late to change num_tx_queues. We cannot do away with
  2046. * lesser number of queues than what we asked for
  2047. */
  2048. if (err)
  2049. goto queue_err;
  2050. }
  2051. adapter->rx_queue[0].rx_ring[0].size = rx_ring_size;
  2052. adapter->rx_queue[0].rx_ring[1].size = rx_ring2_size;
  2053. vmxnet3_adjust_rx_ring_size(adapter);
  2054. for (i = 0; i < adapter->num_rx_queues; i++) {
  2055. struct vmxnet3_rx_queue *rq = &adapter->rx_queue[i];
  2056. /* qid and qid2 for rx queues will be assigned later when num
  2057. * of rx queues is finalized after allocating intrs */
  2058. rq->shared = &adapter->rqd_start[i].ctrl;
  2059. rq->adapter = adapter;
  2060. err = vmxnet3_rq_create(rq, adapter);
  2061. if (err) {
  2062. if (i == 0) {
  2063. printk(KERN_ERR "Could not allocate any rx"
  2064. "queues. Aborting.\n");
  2065. goto queue_err;
  2066. } else {
  2067. printk(KERN_INFO "Number of rx queues changed "
  2068. "to : %d.\n", i);
  2069. adapter->num_rx_queues = i;
  2070. err = 0;
  2071. break;
  2072. }
  2073. }
  2074. }
  2075. return err;
  2076. queue_err:
  2077. vmxnet3_tq_destroy_all(adapter);
  2078. return err;
  2079. }
  2080. static int
  2081. vmxnet3_open(struct net_device *netdev)
  2082. {
  2083. struct vmxnet3_adapter *adapter;
  2084. int err, i;
  2085. adapter = netdev_priv(netdev);
  2086. for (i = 0; i < adapter->num_tx_queues; i++)
  2087. spin_lock_init(&adapter->tx_queue[i].tx_lock);
  2088. err = vmxnet3_create_queues(adapter, VMXNET3_DEF_TX_RING_SIZE,
  2089. VMXNET3_DEF_RX_RING_SIZE,
  2090. VMXNET3_DEF_RX_RING_SIZE);
  2091. if (err)
  2092. goto queue_err;
  2093. err = vmxnet3_activate_dev(adapter);
  2094. if (err)
  2095. goto activate_err;
  2096. return 0;
  2097. activate_err:
  2098. vmxnet3_rq_destroy_all(adapter);
  2099. vmxnet3_tq_destroy_all(adapter);
  2100. queue_err:
  2101. return err;
  2102. }
  2103. static int
  2104. vmxnet3_close(struct net_device *netdev)
  2105. {
  2106. struct vmxnet3_adapter *adapter = netdev_priv(netdev);
  2107. /*
  2108. * Reset_work may be in the middle of resetting the device, wait for its
  2109. * completion.
  2110. */
  2111. while (test_and_set_bit(VMXNET3_STATE_BIT_RESETTING, &adapter->state))
  2112. msleep(1);
  2113. vmxnet3_quiesce_dev(adapter);
  2114. vmxnet3_rq_destroy_all(adapter);
  2115. vmxnet3_tq_destroy_all(adapter);
  2116. clear_bit(VMXNET3_STATE_BIT_RESETTING, &adapter->state);
  2117. return 0;
  2118. }
  2119. void
  2120. vmxnet3_force_close(struct vmxnet3_adapter *adapter)
  2121. {
  2122. int i;
  2123. /*
  2124. * we must clear VMXNET3_STATE_BIT_RESETTING, otherwise
  2125. * vmxnet3_close() will deadlock.
  2126. */
  2127. BUG_ON(test_bit(VMXNET3_STATE_BIT_RESETTING, &adapter->state));
  2128. /* we need to enable NAPI, otherwise dev_close will deadlock */
  2129. for (i = 0; i < adapter->num_rx_queues; i++)
  2130. napi_enable(&adapter->rx_queue[i].napi);
  2131. dev_close(adapter->netdev);
  2132. }
  2133. static int
  2134. vmxnet3_change_mtu(struct net_device *netdev, int new_mtu)
  2135. {
  2136. struct vmxnet3_adapter *adapter = netdev_priv(netdev);
  2137. int err = 0;
  2138. if (new_mtu < VMXNET3_MIN_MTU || new_mtu > VMXNET3_MAX_MTU)
  2139. return -EINVAL;
  2140. if (new_mtu > 1500 && !adapter->jumbo_frame)
  2141. return -EINVAL;
  2142. netdev->mtu = new_mtu;
  2143. /*
  2144. * Reset_work may be in the middle of resetting the device, wait for its
  2145. * completion.
  2146. */
  2147. while (test_and_set_bit(VMXNET3_STATE_BIT_RESETTING, &adapter->state))
  2148. msleep(1);
  2149. if (netif_running(netdev)) {
  2150. vmxnet3_quiesce_dev(adapter);
  2151. vmxnet3_reset_dev(adapter);
  2152. /* we need to re-create the rx queue based on the new mtu */
  2153. vmxnet3_rq_destroy_all(adapter);
  2154. vmxnet3_adjust_rx_ring_size(adapter);
  2155. err = vmxnet3_rq_create_all(adapter);
  2156. if (err) {
  2157. printk(KERN_ERR "%s: failed to re-create rx queues,"
  2158. " error %d. Closing it.\n", netdev->name, err);
  2159. goto out;
  2160. }
  2161. err = vmxnet3_activate_dev(adapter);
  2162. if (err) {
  2163. printk(KERN_ERR "%s: failed to re-activate, error %d. "
  2164. "Closing it\n", netdev->name, err);
  2165. goto out;
  2166. }
  2167. }
  2168. out:
  2169. clear_bit(VMXNET3_STATE_BIT_RESETTING, &adapter->state);
  2170. if (err)
  2171. vmxnet3_force_close(adapter);
  2172. return err;
  2173. }
  2174. static void
  2175. vmxnet3_declare_features(struct vmxnet3_adapter *adapter, bool dma64)
  2176. {
  2177. struct net_device *netdev = adapter->netdev;
  2178. netdev->features = NETIF_F_SG |
  2179. NETIF_F_HW_CSUM |
  2180. NETIF_F_HW_VLAN_TX |
  2181. NETIF_F_HW_VLAN_RX |
  2182. NETIF_F_HW_VLAN_FILTER |
  2183. NETIF_F_TSO |
  2184. NETIF_F_TSO6 |
  2185. NETIF_F_LRO;
  2186. printk(KERN_INFO "features: sg csum vlan jf tso tsoIPv6 lro");
  2187. adapter->rxcsum = true;
  2188. adapter->jumbo_frame = true;
  2189. adapter->lro = true;
  2190. if (dma64) {
  2191. netdev->features |= NETIF_F_HIGHDMA;
  2192. printk(" highDMA");
  2193. }
  2194. netdev->vlan_features = netdev->features;
  2195. printk("\n");
  2196. }
  2197. static void
  2198. vmxnet3_read_mac_addr(struct vmxnet3_adapter *adapter, u8 *mac)
  2199. {
  2200. u32 tmp;
  2201. tmp = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_MACL);
  2202. *(u32 *)mac = tmp;
  2203. tmp = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_MACH);
  2204. mac[4] = tmp & 0xff;
  2205. mac[5] = (tmp >> 8) & 0xff;
  2206. }
  2207. #ifdef CONFIG_PCI_MSI
  2208. /*
  2209. * Enable MSIx vectors.
  2210. * Returns :
  2211. * 0 on successful enabling of required vectors,
  2212. * VMXNET3_LINUX_MIN_MSIX_VECT when only minumum number of vectors required
  2213. * could be enabled.
  2214. * number of vectors which can be enabled otherwise (this number is smaller
  2215. * than VMXNET3_LINUX_MIN_MSIX_VECT)
  2216. */
  2217. static int
  2218. vmxnet3_acquire_msix_vectors(struct vmxnet3_adapter *adapter,
  2219. int vectors)
  2220. {
  2221. int err = 0, vector_threshold;
  2222. vector_threshold = VMXNET3_LINUX_MIN_MSIX_VECT;
  2223. while (vectors >= vector_threshold) {
  2224. err = pci_enable_msix(adapter->pdev, adapter->intr.msix_entries,
  2225. vectors);
  2226. if (!err) {
  2227. adapter->intr.num_intrs = vectors;
  2228. return 0;
  2229. } else if (err < 0) {
  2230. printk(KERN_ERR "Failed to enable MSI-X for %s, error"
  2231. " %d\n", adapter->netdev->name, err);
  2232. vectors = 0;
  2233. } else if (err < vector_threshold) {
  2234. break;
  2235. } else {
  2236. /* If fails to enable required number of MSI-x vectors
  2237. * try enabling 3 of them. One each for rx, tx and event
  2238. */
  2239. vectors = vector_threshold;
  2240. printk(KERN_ERR "Failed to enable %d MSI-X for %s, try"
  2241. " %d instead\n", vectors, adapter->netdev->name,
  2242. vector_threshold);
  2243. }
  2244. }
  2245. printk(KERN_INFO "Number of MSI-X interrupts which can be allocatedi"
  2246. " are lower than min threshold required.\n");
  2247. return err;
  2248. }
  2249. #endif /* CONFIG_PCI_MSI */
  2250. static void
  2251. vmxnet3_alloc_intr_resources(struct vmxnet3_adapter *adapter)
  2252. {
  2253. u32 cfg;
  2254. /* intr settings */
  2255. VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
  2256. VMXNET3_CMD_GET_CONF_INTR);
  2257. cfg = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_CMD);
  2258. adapter->intr.type = cfg & 0x3;
  2259. adapter->intr.mask_mode = (cfg >> 2) & 0x3;
  2260. if (adapter->intr.type == VMXNET3_IT_AUTO) {
  2261. adapter->intr.type = VMXNET3_IT_MSIX;
  2262. }
  2263. #ifdef CONFIG_PCI_MSI
  2264. if (adapter->intr.type == VMXNET3_IT_MSIX) {
  2265. int vector, err = 0;
  2266. adapter->intr.num_intrs = (adapter->share_intr ==
  2267. VMXNET3_INTR_TXSHARE) ? 1 :
  2268. adapter->num_tx_queues;
  2269. adapter->intr.num_intrs += (adapter->share_intr ==
  2270. VMXNET3_INTR_BUDDYSHARE) ? 0 :
  2271. adapter->num_rx_queues;
  2272. adapter->intr.num_intrs += 1; /* for link event */
  2273. adapter->intr.num_intrs = (adapter->intr.num_intrs >
  2274. VMXNET3_LINUX_MIN_MSIX_VECT
  2275. ? adapter->intr.num_intrs :
  2276. VMXNET3_LINUX_MIN_MSIX_VECT);
  2277. for (vector = 0; vector < adapter->intr.num_intrs; vector++)
  2278. adapter->intr.msix_entries[vector].entry = vector;
  2279. err = vmxnet3_acquire_msix_vectors(adapter,
  2280. adapter->intr.num_intrs);
  2281. /* If we cannot allocate one MSIx vector per queue
  2282. * then limit the number of rx queues to 1
  2283. */
  2284. if (err == VMXNET3_LINUX_MIN_MSIX_VECT) {
  2285. if (adapter->share_intr != VMXNET3_INTR_BUDDYSHARE
  2286. || adapter->num_rx_queues != 2) {
  2287. adapter->share_intr = VMXNET3_INTR_TXSHARE;
  2288. printk(KERN_ERR "Number of rx queues : 1\n");
  2289. adapter->num_rx_queues = 1;
  2290. adapter->intr.num_intrs =
  2291. VMXNET3_LINUX_MIN_MSIX_VECT;
  2292. }
  2293. return;
  2294. }
  2295. if (!err)
  2296. return;
  2297. /* If we cannot allocate MSIx vectors use only one rx queue */
  2298. printk(KERN_INFO "Failed to enable MSI-X for %s, error %d."
  2299. "#rx queues : 1, try MSI\n", adapter->netdev->name, err);
  2300. adapter->intr.type = VMXNET3_IT_MSI;
  2301. }
  2302. if (adapter->intr.type == VMXNET3_IT_MSI) {
  2303. int err;
  2304. err = pci_enable_msi(adapter->pdev);
  2305. if (!err) {
  2306. adapter->num_rx_queues = 1;
  2307. adapter->intr.num_intrs = 1;
  2308. return;
  2309. }
  2310. }
  2311. #endif /* CONFIG_PCI_MSI */
  2312. adapter->num_rx_queues = 1;
  2313. printk(KERN_INFO "Using INTx interrupt, #Rx queues: 1.\n");
  2314. adapter->intr.type = VMXNET3_IT_INTX;
  2315. /* INT-X related setting */
  2316. adapter->intr.num_intrs = 1;
  2317. }
  2318. static void
  2319. vmxnet3_free_intr_resources(struct vmxnet3_adapter *adapter)
  2320. {
  2321. if (adapter->intr.type == VMXNET3_IT_MSIX)
  2322. pci_disable_msix(adapter->pdev);
  2323. else if (adapter->intr.type == VMXNET3_IT_MSI)
  2324. pci_disable_msi(adapter->pdev);
  2325. else
  2326. BUG_ON(adapter->intr.type != VMXNET3_IT_INTX);
  2327. }
  2328. static void
  2329. vmxnet3_tx_timeout(struct net_device *netdev)
  2330. {
  2331. struct vmxnet3_adapter *adapter = netdev_priv(netdev);
  2332. adapter->tx_timeout_count++;
  2333. printk(KERN_ERR "%s: tx hang\n", adapter->netdev->name);
  2334. schedule_work(&adapter->work);
  2335. netif_wake_queue(adapter->netdev);
  2336. }
  2337. static void
  2338. vmxnet3_reset_work(struct work_struct *data)
  2339. {
  2340. struct vmxnet3_adapter *adapter;
  2341. adapter = container_of(data, struct vmxnet3_adapter, work);
  2342. /* if another thread is resetting the device, no need to proceed */
  2343. if (test_and_set_bit(VMXNET3_STATE_BIT_RESETTING, &adapter->state))
  2344. return;
  2345. /* if the device is closed, we must leave it alone */
  2346. rtnl_lock();
  2347. if (netif_running(adapter->netdev)) {
  2348. printk(KERN_INFO "%s: resetting\n", adapter->netdev->name);
  2349. vmxnet3_quiesce_dev(adapter);
  2350. vmxnet3_reset_dev(adapter);
  2351. vmxnet3_activate_dev(adapter);
  2352. } else {
  2353. printk(KERN_INFO "%s: already closed\n", adapter->netdev->name);
  2354. }
  2355. rtnl_unlock();
  2356. clear_bit(VMXNET3_STATE_BIT_RESETTING, &adapter->state);
  2357. }
  2358. static int __devinit
  2359. vmxnet3_probe_device(struct pci_dev *pdev,
  2360. const struct pci_device_id *id)
  2361. {
  2362. static const struct net_device_ops vmxnet3_netdev_ops = {
  2363. .ndo_open = vmxnet3_open,
  2364. .ndo_stop = vmxnet3_close,
  2365. .ndo_start_xmit = vmxnet3_xmit_frame,
  2366. .ndo_set_mac_address = vmxnet3_set_mac_addr,
  2367. .ndo_change_mtu = vmxnet3_change_mtu,
  2368. .ndo_get_stats = vmxnet3_get_stats,
  2369. .ndo_tx_timeout = vmxnet3_tx_timeout,
  2370. .ndo_set_multicast_list = vmxnet3_set_mc,
  2371. .ndo_vlan_rx_register = vmxnet3_vlan_rx_register,
  2372. .ndo_vlan_rx_add_vid = vmxnet3_vlan_rx_add_vid,
  2373. .ndo_vlan_rx_kill_vid = vmxnet3_vlan_rx_kill_vid,
  2374. #ifdef CONFIG_NET_POLL_CONTROLLER
  2375. .ndo_poll_controller = vmxnet3_netpoll,
  2376. #endif
  2377. };
  2378. int err;
  2379. bool dma64 = false; /* stupid gcc */
  2380. u32 ver;
  2381. struct net_device *netdev;
  2382. struct vmxnet3_adapter *adapter;
  2383. u8 mac[ETH_ALEN];
  2384. int size;
  2385. int num_tx_queues;
  2386. int num_rx_queues;
  2387. #ifdef VMXNET3_RSS
  2388. if (enable_mq)
  2389. num_rx_queues = min(VMXNET3_DEVICE_MAX_RX_QUEUES,
  2390. (int)num_online_cpus());
  2391. else
  2392. #endif
  2393. num_rx_queues = 1;
  2394. if (enable_mq)
  2395. num_tx_queues = min(VMXNET3_DEVICE_MAX_TX_QUEUES,
  2396. (int)num_online_cpus());
  2397. else
  2398. num_tx_queues = 1;
  2399. netdev = alloc_etherdev_mq(sizeof(struct vmxnet3_adapter),
  2400. max(num_tx_queues, num_rx_queues));
  2401. printk(KERN_INFO "# of Tx queues : %d, # of Rx queues : %d\n",
  2402. num_tx_queues, num_rx_queues);
  2403. if (!netdev) {
  2404. printk(KERN_ERR "Failed to alloc ethernet device for adapter "
  2405. "%s\n", pci_name(pdev));
  2406. return -ENOMEM;
  2407. }
  2408. pci_set_drvdata(pdev, netdev);
  2409. adapter = netdev_priv(netdev);
  2410. adapter->netdev = netdev;
  2411. adapter->pdev = pdev;
  2412. adapter->shared = pci_alloc_consistent(adapter->pdev,
  2413. sizeof(struct Vmxnet3_DriverShared),
  2414. &adapter->shared_pa);
  2415. if (!adapter->shared) {
  2416. printk(KERN_ERR "Failed to allocate memory for %s\n",
  2417. pci_name(pdev));
  2418. err = -ENOMEM;
  2419. goto err_alloc_shared;
  2420. }
  2421. adapter->num_rx_queues = num_rx_queues;
  2422. adapter->num_tx_queues = num_tx_queues;
  2423. size = sizeof(struct Vmxnet3_TxQueueDesc) * adapter->num_tx_queues;
  2424. size += sizeof(struct Vmxnet3_RxQueueDesc) * adapter->num_rx_queues;
  2425. adapter->tqd_start = pci_alloc_consistent(adapter->pdev, size,
  2426. &adapter->queue_desc_pa);
  2427. if (!adapter->tqd_start) {
  2428. printk(KERN_ERR "Failed to allocate memory for %s\n",
  2429. pci_name(pdev));
  2430. err = -ENOMEM;
  2431. goto err_alloc_queue_desc;
  2432. }
  2433. adapter->rqd_start = (struct Vmxnet3_RxQueueDesc *)(adapter->tqd_start +
  2434. adapter->num_tx_queues);
  2435. adapter->pm_conf = kmalloc(sizeof(struct Vmxnet3_PMConf), GFP_KERNEL);
  2436. if (adapter->pm_conf == NULL) {
  2437. printk(KERN_ERR "Failed to allocate memory for %s\n",
  2438. pci_name(pdev));
  2439. err = -ENOMEM;
  2440. goto err_alloc_pm;
  2441. }
  2442. #ifdef VMXNET3_RSS
  2443. adapter->rss_conf = kmalloc(sizeof(struct UPT1_RSSConf), GFP_KERNEL);
  2444. if (adapter->rss_conf == NULL) {
  2445. printk(KERN_ERR "Failed to allocate memory for %s\n",
  2446. pci_name(pdev));
  2447. err = -ENOMEM;
  2448. goto err_alloc_rss;
  2449. }
  2450. #endif /* VMXNET3_RSS */
  2451. err = vmxnet3_alloc_pci_resources(adapter, &dma64);
  2452. if (err < 0)
  2453. goto err_alloc_pci;
  2454. ver = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_VRRS);
  2455. if (ver & 1) {
  2456. VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_VRRS, 1);
  2457. } else {
  2458. printk(KERN_ERR "Incompatible h/w version (0x%x) for adapter"
  2459. " %s\n", ver, pci_name(pdev));
  2460. err = -EBUSY;
  2461. goto err_ver;
  2462. }
  2463. ver = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_UVRS);
  2464. if (ver & 1) {
  2465. VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_UVRS, 1);
  2466. } else {
  2467. printk(KERN_ERR "Incompatible upt version (0x%x) for "
  2468. "adapter %s\n", ver, pci_name(pdev));
  2469. err = -EBUSY;
  2470. goto err_ver;
  2471. }
  2472. vmxnet3_declare_features(adapter, dma64);
  2473. adapter->dev_number = atomic_read(&devices_found);
  2474. adapter->share_intr = irq_share_mode;
  2475. if (adapter->share_intr == VMXNET3_INTR_BUDDYSHARE &&
  2476. adapter->num_tx_queues != adapter->num_rx_queues)
  2477. adapter->share_intr = VMXNET3_INTR_DONTSHARE;
  2478. vmxnet3_alloc_intr_resources(adapter);
  2479. #ifdef VMXNET3_RSS
  2480. if (adapter->num_rx_queues > 1 &&
  2481. adapter->intr.type == VMXNET3_IT_MSIX) {
  2482. adapter->rss = true;
  2483. printk(KERN_INFO "RSS is enabled.\n");
  2484. } else {
  2485. adapter->rss = false;
  2486. }
  2487. #endif
  2488. vmxnet3_read_mac_addr(adapter, mac);
  2489. memcpy(netdev->dev_addr, mac, netdev->addr_len);
  2490. netdev->netdev_ops = &vmxnet3_netdev_ops;
  2491. vmxnet3_set_ethtool_ops(netdev);
  2492. netdev->watchdog_timeo = 5 * HZ;
  2493. INIT_WORK(&adapter->work, vmxnet3_reset_work);
  2494. if (adapter->intr.type == VMXNET3_IT_MSIX) {
  2495. int i;
  2496. for (i = 0; i < adapter->num_rx_queues; i++) {
  2497. netif_napi_add(adapter->netdev,
  2498. &adapter->rx_queue[i].napi,
  2499. vmxnet3_poll_rx_only, 64);
  2500. }
  2501. } else {
  2502. netif_napi_add(adapter->netdev, &adapter->rx_queue[0].napi,
  2503. vmxnet3_poll, 64);
  2504. }
  2505. netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues);
  2506. netif_set_real_num_rx_queues(adapter->netdev, adapter->num_rx_queues);
  2507. SET_NETDEV_DEV(netdev, &pdev->dev);
  2508. err = register_netdev(netdev);
  2509. if (err) {
  2510. printk(KERN_ERR "Failed to register adapter %s\n",
  2511. pci_name(pdev));
  2512. goto err_register;
  2513. }
  2514. set_bit(VMXNET3_STATE_BIT_QUIESCED, &adapter->state);
  2515. vmxnet3_check_link(adapter, false);
  2516. atomic_inc(&devices_found);
  2517. return 0;
  2518. err_register:
  2519. vmxnet3_free_intr_resources(adapter);
  2520. err_ver:
  2521. vmxnet3_free_pci_resources(adapter);
  2522. err_alloc_pci:
  2523. #ifdef VMXNET3_RSS
  2524. kfree(adapter->rss_conf);
  2525. err_alloc_rss:
  2526. #endif
  2527. kfree(adapter->pm_conf);
  2528. err_alloc_pm:
  2529. pci_free_consistent(adapter->pdev, size, adapter->tqd_start,
  2530. adapter->queue_desc_pa);
  2531. err_alloc_queue_desc:
  2532. pci_free_consistent(adapter->pdev, sizeof(struct Vmxnet3_DriverShared),
  2533. adapter->shared, adapter->shared_pa);
  2534. err_alloc_shared:
  2535. pci_set_drvdata(pdev, NULL);
  2536. free_netdev(netdev);
  2537. return err;
  2538. }
  2539. static void __devexit
  2540. vmxnet3_remove_device(struct pci_dev *pdev)
  2541. {
  2542. struct net_device *netdev = pci_get_drvdata(pdev);
  2543. struct vmxnet3_adapter *adapter = netdev_priv(netdev);
  2544. int size = 0;
  2545. int num_rx_queues;
  2546. #ifdef VMXNET3_RSS
  2547. if (enable_mq)
  2548. num_rx_queues = min(VMXNET3_DEVICE_MAX_RX_QUEUES,
  2549. (int)num_online_cpus());
  2550. else
  2551. #endif
  2552. num_rx_queues = 1;
  2553. cancel_work_sync(&adapter->work);
  2554. unregister_netdev(netdev);
  2555. vmxnet3_free_intr_resources(adapter);
  2556. vmxnet3_free_pci_resources(adapter);
  2557. #ifdef VMXNET3_RSS
  2558. kfree(adapter->rss_conf);
  2559. #endif
  2560. kfree(adapter->pm_conf);
  2561. size = sizeof(struct Vmxnet3_TxQueueDesc) * adapter->num_tx_queues;
  2562. size += sizeof(struct Vmxnet3_RxQueueDesc) * num_rx_queues;
  2563. pci_free_consistent(adapter->pdev, size, adapter->tqd_start,
  2564. adapter->queue_desc_pa);
  2565. pci_free_consistent(adapter->pdev, sizeof(struct Vmxnet3_DriverShared),
  2566. adapter->shared, adapter->shared_pa);
  2567. free_netdev(netdev);
  2568. }
  2569. #ifdef CONFIG_PM
  2570. static int
  2571. vmxnet3_suspend(struct device *device)
  2572. {
  2573. struct pci_dev *pdev = to_pci_dev(device);
  2574. struct net_device *netdev = pci_get_drvdata(pdev);
  2575. struct vmxnet3_adapter *adapter = netdev_priv(netdev);
  2576. struct Vmxnet3_PMConf *pmConf;
  2577. struct ethhdr *ehdr;
  2578. struct arphdr *ahdr;
  2579. u8 *arpreq;
  2580. struct in_device *in_dev;
  2581. struct in_ifaddr *ifa;
  2582. int i = 0;
  2583. if (!netif_running(netdev))
  2584. return 0;
  2585. vmxnet3_disable_all_intrs(adapter);
  2586. vmxnet3_free_irqs(adapter);
  2587. vmxnet3_free_intr_resources(adapter);
  2588. netif_device_detach(netdev);
  2589. netif_tx_stop_all_queues(netdev);
  2590. /* Create wake-up filters. */
  2591. pmConf = adapter->pm_conf;
  2592. memset(pmConf, 0, sizeof(*pmConf));
  2593. if (adapter->wol & WAKE_UCAST) {
  2594. pmConf->filters[i].patternSize = ETH_ALEN;
  2595. pmConf->filters[i].maskSize = 1;
  2596. memcpy(pmConf->filters[i].pattern, netdev->dev_addr, ETH_ALEN);
  2597. pmConf->filters[i].mask[0] = 0x3F; /* LSB ETH_ALEN bits */
  2598. pmConf->wakeUpEvents |= VMXNET3_PM_WAKEUP_FILTER;
  2599. i++;
  2600. }
  2601. if (adapter->wol & WAKE_ARP) {
  2602. in_dev = in_dev_get(netdev);
  2603. if (!in_dev)
  2604. goto skip_arp;
  2605. ifa = (struct in_ifaddr *)in_dev->ifa_list;
  2606. if (!ifa)
  2607. goto skip_arp;
  2608. pmConf->filters[i].patternSize = ETH_HLEN + /* Ethernet header*/
  2609. sizeof(struct arphdr) + /* ARP header */
  2610. 2 * ETH_ALEN + /* 2 Ethernet addresses*/
  2611. 2 * sizeof(u32); /*2 IPv4 addresses */
  2612. pmConf->filters[i].maskSize =
  2613. (pmConf->filters[i].patternSize - 1) / 8 + 1;
  2614. /* ETH_P_ARP in Ethernet header. */
  2615. ehdr = (struct ethhdr *)pmConf->filters[i].pattern;
  2616. ehdr->h_proto = htons(ETH_P_ARP);
  2617. /* ARPOP_REQUEST in ARP header. */
  2618. ahdr = (struct arphdr *)&pmConf->filters[i].pattern[ETH_HLEN];
  2619. ahdr->ar_op = htons(ARPOP_REQUEST);
  2620. arpreq = (u8 *)(ahdr + 1);
  2621. /* The Unicast IPv4 address in 'tip' field. */
  2622. arpreq += 2 * ETH_ALEN + sizeof(u32);
  2623. *(u32 *)arpreq = ifa->ifa_address;
  2624. /* The mask for the relevant bits. */
  2625. pmConf->filters[i].mask[0] = 0x00;
  2626. pmConf->filters[i].mask[1] = 0x30; /* ETH_P_ARP */
  2627. pmConf->filters[i].mask[2] = 0x30; /* ARPOP_REQUEST */
  2628. pmConf->filters[i].mask[3] = 0x00;
  2629. pmConf->filters[i].mask[4] = 0xC0; /* IPv4 TIP */
  2630. pmConf->filters[i].mask[5] = 0x03; /* IPv4 TIP */
  2631. in_dev_put(in_dev);
  2632. pmConf->wakeUpEvents |= VMXNET3_PM_WAKEUP_FILTER;
  2633. i++;
  2634. }
  2635. skip_arp:
  2636. if (adapter->wol & WAKE_MAGIC)
  2637. pmConf->wakeUpEvents |= VMXNET3_PM_WAKEUP_MAGIC;
  2638. pmConf->numFilters = i;
  2639. adapter->shared->devRead.pmConfDesc.confVer = cpu_to_le32(1);
  2640. adapter->shared->devRead.pmConfDesc.confLen = cpu_to_le32(sizeof(
  2641. *pmConf));
  2642. adapter->shared->devRead.pmConfDesc.confPA = cpu_to_le64(virt_to_phys(
  2643. pmConf));
  2644. VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
  2645. VMXNET3_CMD_UPDATE_PMCFG);
  2646. pci_save_state(pdev);
  2647. pci_enable_wake(pdev, pci_choose_state(pdev, PMSG_SUSPEND),
  2648. adapter->wol);
  2649. pci_disable_device(pdev);
  2650. pci_set_power_state(pdev, pci_choose_state(pdev, PMSG_SUSPEND));
  2651. return 0;
  2652. }
  2653. static int
  2654. vmxnet3_resume(struct device *device)
  2655. {
  2656. int err;
  2657. struct pci_dev *pdev = to_pci_dev(device);
  2658. struct net_device *netdev = pci_get_drvdata(pdev);
  2659. struct vmxnet3_adapter *adapter = netdev_priv(netdev);
  2660. struct Vmxnet3_PMConf *pmConf;
  2661. if (!netif_running(netdev))
  2662. return 0;
  2663. /* Destroy wake-up filters. */
  2664. pmConf = adapter->pm_conf;
  2665. memset(pmConf, 0, sizeof(*pmConf));
  2666. adapter->shared->devRead.pmConfDesc.confVer = cpu_to_le32(1);
  2667. adapter->shared->devRead.pmConfDesc.confLen = cpu_to_le32(sizeof(
  2668. *pmConf));
  2669. adapter->shared->devRead.pmConfDesc.confPA = cpu_to_le64(virt_to_phys(
  2670. pmConf));
  2671. netif_device_attach(netdev);
  2672. pci_set_power_state(pdev, PCI_D0);
  2673. pci_restore_state(pdev);
  2674. err = pci_enable_device_mem(pdev);
  2675. if (err != 0)
  2676. return err;
  2677. pci_enable_wake(pdev, PCI_D0, 0);
  2678. VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
  2679. VMXNET3_CMD_UPDATE_PMCFG);
  2680. vmxnet3_alloc_intr_resources(adapter);
  2681. vmxnet3_request_irqs(adapter);
  2682. vmxnet3_enable_all_intrs(adapter);
  2683. return 0;
  2684. }
  2685. static const struct dev_pm_ops vmxnet3_pm_ops = {
  2686. .suspend = vmxnet3_suspend,
  2687. .resume = vmxnet3_resume,
  2688. };
  2689. #endif
  2690. static struct pci_driver vmxnet3_driver = {
  2691. .name = vmxnet3_driver_name,
  2692. .id_table = vmxnet3_pciid_table,
  2693. .probe = vmxnet3_probe_device,
  2694. .remove = __devexit_p(vmxnet3_remove_device),
  2695. #ifdef CONFIG_PM
  2696. .driver.pm = &vmxnet3_pm_ops,
  2697. #endif
  2698. };
  2699. static int __init
  2700. vmxnet3_init_module(void)
  2701. {
  2702. printk(KERN_INFO "%s - version %s\n", VMXNET3_DRIVER_DESC,
  2703. VMXNET3_DRIVER_VERSION_REPORT);
  2704. return pci_register_driver(&vmxnet3_driver);
  2705. }
  2706. module_init(vmxnet3_init_module);
  2707. static void
  2708. vmxnet3_exit_module(void)
  2709. {
  2710. pci_unregister_driver(&vmxnet3_driver);
  2711. }
  2712. module_exit(vmxnet3_exit_module);
  2713. MODULE_AUTHOR("VMware, Inc.");
  2714. MODULE_DESCRIPTION(VMXNET3_DRIVER_DESC);
  2715. MODULE_LICENSE("GPL v2");
  2716. MODULE_VERSION(VMXNET3_DRIVER_VERSION_STRING);