vmxnet3_drv.c 86 KB

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