efx.c 94 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693
  1. /****************************************************************************
  2. * Driver for Solarflare network controllers and boards
  3. * Copyright 2005-2006 Fen Systems Ltd.
  4. * Copyright 2005-2013 Solarflare Communications Inc.
  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 version 2 as published
  8. * by the Free Software Foundation, incorporated herein by reference.
  9. */
  10. #include <linux/module.h>
  11. #include <linux/pci.h>
  12. #include <linux/netdevice.h>
  13. #include <linux/etherdevice.h>
  14. #include <linux/delay.h>
  15. #include <linux/notifier.h>
  16. #include <linux/ip.h>
  17. #include <linux/tcp.h>
  18. #include <linux/in.h>
  19. #include <linux/ethtool.h>
  20. #include <linux/topology.h>
  21. #include <linux/gfp.h>
  22. #include <linux/aer.h>
  23. #include <linux/interrupt.h>
  24. #include "net_driver.h"
  25. #include <net/gre.h>
  26. #include <net/udp_tunnel.h>
  27. #include "efx.h"
  28. #include "nic.h"
  29. #include "selftest.h"
  30. #include "sriov.h"
  31. #include "mcdi.h"
  32. #include "mcdi_pcol.h"
  33. #include "workarounds.h"
  34. /**************************************************************************
  35. *
  36. * Type name strings
  37. *
  38. **************************************************************************
  39. */
  40. /* Loopback mode names (see LOOPBACK_MODE()) */
  41. const unsigned int efx_loopback_mode_max = LOOPBACK_MAX;
  42. const char *const efx_loopback_mode_names[] = {
  43. [LOOPBACK_NONE] = "NONE",
  44. [LOOPBACK_DATA] = "DATAPATH",
  45. [LOOPBACK_GMAC] = "GMAC",
  46. [LOOPBACK_XGMII] = "XGMII",
  47. [LOOPBACK_XGXS] = "XGXS",
  48. [LOOPBACK_XAUI] = "XAUI",
  49. [LOOPBACK_GMII] = "GMII",
  50. [LOOPBACK_SGMII] = "SGMII",
  51. [LOOPBACK_XGBR] = "XGBR",
  52. [LOOPBACK_XFI] = "XFI",
  53. [LOOPBACK_XAUI_FAR] = "XAUI_FAR",
  54. [LOOPBACK_GMII_FAR] = "GMII_FAR",
  55. [LOOPBACK_SGMII_FAR] = "SGMII_FAR",
  56. [LOOPBACK_XFI_FAR] = "XFI_FAR",
  57. [LOOPBACK_GPHY] = "GPHY",
  58. [LOOPBACK_PHYXS] = "PHYXS",
  59. [LOOPBACK_PCS] = "PCS",
  60. [LOOPBACK_PMAPMD] = "PMA/PMD",
  61. [LOOPBACK_XPORT] = "XPORT",
  62. [LOOPBACK_XGMII_WS] = "XGMII_WS",
  63. [LOOPBACK_XAUI_WS] = "XAUI_WS",
  64. [LOOPBACK_XAUI_WS_FAR] = "XAUI_WS_FAR",
  65. [LOOPBACK_XAUI_WS_NEAR] = "XAUI_WS_NEAR",
  66. [LOOPBACK_GMII_WS] = "GMII_WS",
  67. [LOOPBACK_XFI_WS] = "XFI_WS",
  68. [LOOPBACK_XFI_WS_FAR] = "XFI_WS_FAR",
  69. [LOOPBACK_PHYXS_WS] = "PHYXS_WS",
  70. };
  71. const unsigned int efx_reset_type_max = RESET_TYPE_MAX;
  72. const char *const efx_reset_type_names[] = {
  73. [RESET_TYPE_INVISIBLE] = "INVISIBLE",
  74. [RESET_TYPE_ALL] = "ALL",
  75. [RESET_TYPE_RECOVER_OR_ALL] = "RECOVER_OR_ALL",
  76. [RESET_TYPE_WORLD] = "WORLD",
  77. [RESET_TYPE_RECOVER_OR_DISABLE] = "RECOVER_OR_DISABLE",
  78. [RESET_TYPE_DATAPATH] = "DATAPATH",
  79. [RESET_TYPE_MC_BIST] = "MC_BIST",
  80. [RESET_TYPE_DISABLE] = "DISABLE",
  81. [RESET_TYPE_TX_WATCHDOG] = "TX_WATCHDOG",
  82. [RESET_TYPE_INT_ERROR] = "INT_ERROR",
  83. [RESET_TYPE_DMA_ERROR] = "DMA_ERROR",
  84. [RESET_TYPE_TX_SKIP] = "TX_SKIP",
  85. [RESET_TYPE_MC_FAILURE] = "MC_FAILURE",
  86. [RESET_TYPE_MCDI_TIMEOUT] = "MCDI_TIMEOUT (FLR)",
  87. };
  88. /* UDP tunnel type names */
  89. static const char *const efx_udp_tunnel_type_names[] = {
  90. [TUNNEL_ENCAP_UDP_PORT_ENTRY_VXLAN] = "vxlan",
  91. [TUNNEL_ENCAP_UDP_PORT_ENTRY_GENEVE] = "geneve",
  92. };
  93. void efx_get_udp_tunnel_type_name(u16 type, char *buf, size_t buflen)
  94. {
  95. if (type < ARRAY_SIZE(efx_udp_tunnel_type_names) &&
  96. efx_udp_tunnel_type_names[type] != NULL)
  97. snprintf(buf, buflen, "%s", efx_udp_tunnel_type_names[type]);
  98. else
  99. snprintf(buf, buflen, "type %d", type);
  100. }
  101. /* Reset workqueue. If any NIC has a hardware failure then a reset will be
  102. * queued onto this work queue. This is not a per-nic work queue, because
  103. * efx_reset_work() acquires the rtnl lock, so resets are naturally serialised.
  104. */
  105. static struct workqueue_struct *reset_workqueue;
  106. /* How often and how many times to poll for a reset while waiting for a
  107. * BIST that another function started to complete.
  108. */
  109. #define BIST_WAIT_DELAY_MS 100
  110. #define BIST_WAIT_DELAY_COUNT 100
  111. /**************************************************************************
  112. *
  113. * Configurable values
  114. *
  115. *************************************************************************/
  116. /*
  117. * Use separate channels for TX and RX events
  118. *
  119. * Set this to 1 to use separate channels for TX and RX. It allows us
  120. * to control interrupt affinity separately for TX and RX.
  121. *
  122. * This is only used in MSI-X interrupt mode
  123. */
  124. bool efx_separate_tx_channels;
  125. module_param(efx_separate_tx_channels, bool, 0444);
  126. MODULE_PARM_DESC(efx_separate_tx_channels,
  127. "Use separate channels for TX and RX");
  128. /* This is the weight assigned to each of the (per-channel) virtual
  129. * NAPI devices.
  130. */
  131. static int napi_weight = 64;
  132. /* This is the time (in jiffies) between invocations of the hardware
  133. * monitor.
  134. * On Falcon-based NICs, this will:
  135. * - Check the on-board hardware monitor;
  136. * - Poll the link state and reconfigure the hardware as necessary.
  137. * On Siena-based NICs for power systems with EEH support, this will give EEH a
  138. * chance to start.
  139. */
  140. static unsigned int efx_monitor_interval = 1 * HZ;
  141. /* Initial interrupt moderation settings. They can be modified after
  142. * module load with ethtool.
  143. *
  144. * The default for RX should strike a balance between increasing the
  145. * round-trip latency and reducing overhead.
  146. */
  147. static unsigned int rx_irq_mod_usec = 60;
  148. /* Initial interrupt moderation settings. They can be modified after
  149. * module load with ethtool.
  150. *
  151. * This default is chosen to ensure that a 10G link does not go idle
  152. * while a TX queue is stopped after it has become full. A queue is
  153. * restarted when it drops below half full. The time this takes (assuming
  154. * worst case 3 descriptors per packet and 1024 descriptors) is
  155. * 512 / 3 * 1.2 = 205 usec.
  156. */
  157. static unsigned int tx_irq_mod_usec = 150;
  158. /* This is the first interrupt mode to try out of:
  159. * 0 => MSI-X
  160. * 1 => MSI
  161. * 2 => legacy
  162. */
  163. static unsigned int interrupt_mode;
  164. /* This is the requested number of CPUs to use for Receive-Side Scaling (RSS),
  165. * i.e. the number of CPUs among which we may distribute simultaneous
  166. * interrupt handling.
  167. *
  168. * Cards without MSI-X will only target one CPU via legacy or MSI interrupt.
  169. * The default (0) means to assign an interrupt to each core.
  170. */
  171. static unsigned int rss_cpus;
  172. module_param(rss_cpus, uint, 0444);
  173. MODULE_PARM_DESC(rss_cpus, "Number of CPUs to use for Receive-Side Scaling");
  174. static bool phy_flash_cfg;
  175. module_param(phy_flash_cfg, bool, 0644);
  176. MODULE_PARM_DESC(phy_flash_cfg, "Set PHYs into reflash mode initially");
  177. static unsigned irq_adapt_low_thresh = 8000;
  178. module_param(irq_adapt_low_thresh, uint, 0644);
  179. MODULE_PARM_DESC(irq_adapt_low_thresh,
  180. "Threshold score for reducing IRQ moderation");
  181. static unsigned irq_adapt_high_thresh = 16000;
  182. module_param(irq_adapt_high_thresh, uint, 0644);
  183. MODULE_PARM_DESC(irq_adapt_high_thresh,
  184. "Threshold score for increasing IRQ moderation");
  185. static unsigned debug = (NETIF_MSG_DRV | NETIF_MSG_PROBE |
  186. NETIF_MSG_LINK | NETIF_MSG_IFDOWN |
  187. NETIF_MSG_IFUP | NETIF_MSG_RX_ERR |
  188. NETIF_MSG_TX_ERR | NETIF_MSG_HW);
  189. module_param(debug, uint, 0);
  190. MODULE_PARM_DESC(debug, "Bitmapped debugging message enable value");
  191. /**************************************************************************
  192. *
  193. * Utility functions and prototypes
  194. *
  195. *************************************************************************/
  196. static int efx_soft_enable_interrupts(struct efx_nic *efx);
  197. static void efx_soft_disable_interrupts(struct efx_nic *efx);
  198. static void efx_remove_channel(struct efx_channel *channel);
  199. static void efx_remove_channels(struct efx_nic *efx);
  200. static const struct efx_channel_type efx_default_channel_type;
  201. static void efx_remove_port(struct efx_nic *efx);
  202. static void efx_init_napi_channel(struct efx_channel *channel);
  203. static void efx_fini_napi(struct efx_nic *efx);
  204. static void efx_fini_napi_channel(struct efx_channel *channel);
  205. static void efx_fini_struct(struct efx_nic *efx);
  206. static void efx_start_all(struct efx_nic *efx);
  207. static void efx_stop_all(struct efx_nic *efx);
  208. #define EFX_ASSERT_RESET_SERIALISED(efx) \
  209. do { \
  210. if ((efx->state == STATE_READY) || \
  211. (efx->state == STATE_RECOVERY) || \
  212. (efx->state == STATE_DISABLED)) \
  213. ASSERT_RTNL(); \
  214. } while (0)
  215. static int efx_check_disabled(struct efx_nic *efx)
  216. {
  217. if (efx->state == STATE_DISABLED || efx->state == STATE_RECOVERY) {
  218. netif_err(efx, drv, efx->net_dev,
  219. "device is disabled due to earlier errors\n");
  220. return -EIO;
  221. }
  222. return 0;
  223. }
  224. /**************************************************************************
  225. *
  226. * Event queue processing
  227. *
  228. *************************************************************************/
  229. /* Process channel's event queue
  230. *
  231. * This function is responsible for processing the event queue of a
  232. * single channel. The caller must guarantee that this function will
  233. * never be concurrently called more than once on the same channel,
  234. * though different channels may be being processed concurrently.
  235. */
  236. static int efx_process_channel(struct efx_channel *channel, int budget)
  237. {
  238. struct efx_tx_queue *tx_queue;
  239. int spent;
  240. if (unlikely(!channel->enabled))
  241. return 0;
  242. efx_for_each_channel_tx_queue(tx_queue, channel) {
  243. tx_queue->pkts_compl = 0;
  244. tx_queue->bytes_compl = 0;
  245. }
  246. spent = efx_nic_process_eventq(channel, budget);
  247. if (spent && efx_channel_has_rx_queue(channel)) {
  248. struct efx_rx_queue *rx_queue =
  249. efx_channel_get_rx_queue(channel);
  250. efx_rx_flush_packet(channel);
  251. efx_fast_push_rx_descriptors(rx_queue, true);
  252. }
  253. /* Update BQL */
  254. efx_for_each_channel_tx_queue(tx_queue, channel) {
  255. if (tx_queue->bytes_compl) {
  256. netdev_tx_completed_queue(tx_queue->core_txq,
  257. tx_queue->pkts_compl, tx_queue->bytes_compl);
  258. }
  259. }
  260. return spent;
  261. }
  262. /* NAPI poll handler
  263. *
  264. * NAPI guarantees serialisation of polls of the same device, which
  265. * provides the guarantee required by efx_process_channel().
  266. */
  267. static void efx_update_irq_mod(struct efx_nic *efx, struct efx_channel *channel)
  268. {
  269. int step = efx->irq_mod_step_us;
  270. if (channel->irq_mod_score < irq_adapt_low_thresh) {
  271. if (channel->irq_moderation_us > step) {
  272. channel->irq_moderation_us -= step;
  273. efx->type->push_irq_moderation(channel);
  274. }
  275. } else if (channel->irq_mod_score > irq_adapt_high_thresh) {
  276. if (channel->irq_moderation_us <
  277. efx->irq_rx_moderation_us) {
  278. channel->irq_moderation_us += step;
  279. efx->type->push_irq_moderation(channel);
  280. }
  281. }
  282. channel->irq_count = 0;
  283. channel->irq_mod_score = 0;
  284. }
  285. static int efx_poll(struct napi_struct *napi, int budget)
  286. {
  287. struct efx_channel *channel =
  288. container_of(napi, struct efx_channel, napi_str);
  289. struct efx_nic *efx = channel->efx;
  290. int spent;
  291. netif_vdbg(efx, intr, efx->net_dev,
  292. "channel %d NAPI poll executing on CPU %d\n",
  293. channel->channel, raw_smp_processor_id());
  294. spent = efx_process_channel(channel, budget);
  295. if (spent < budget) {
  296. if (efx_channel_has_rx_queue(channel) &&
  297. efx->irq_rx_adaptive &&
  298. unlikely(++channel->irq_count == 1000)) {
  299. efx_update_irq_mod(efx, channel);
  300. }
  301. efx_filter_rfs_expire(channel);
  302. /* There is no race here; although napi_disable() will
  303. * only wait for napi_complete(), this isn't a problem
  304. * since efx_nic_eventq_read_ack() will have no effect if
  305. * interrupts have already been disabled.
  306. */
  307. if (napi_complete_done(napi, spent))
  308. efx_nic_eventq_read_ack(channel);
  309. }
  310. return spent;
  311. }
  312. /* Create event queue
  313. * Event queue memory allocations are done only once. If the channel
  314. * is reset, the memory buffer will be reused; this guards against
  315. * errors during channel reset and also simplifies interrupt handling.
  316. */
  317. static int efx_probe_eventq(struct efx_channel *channel)
  318. {
  319. struct efx_nic *efx = channel->efx;
  320. unsigned long entries;
  321. netif_dbg(efx, probe, efx->net_dev,
  322. "chan %d create event queue\n", channel->channel);
  323. /* Build an event queue with room for one event per tx and rx buffer,
  324. * plus some extra for link state events and MCDI completions. */
  325. entries = roundup_pow_of_two(efx->rxq_entries + efx->txq_entries + 128);
  326. EFX_WARN_ON_PARANOID(entries > EFX_MAX_EVQ_SIZE);
  327. channel->eventq_mask = max(entries, EFX_MIN_EVQ_SIZE) - 1;
  328. return efx_nic_probe_eventq(channel);
  329. }
  330. /* Prepare channel's event queue */
  331. static int efx_init_eventq(struct efx_channel *channel)
  332. {
  333. struct efx_nic *efx = channel->efx;
  334. int rc;
  335. EFX_WARN_ON_PARANOID(channel->eventq_init);
  336. netif_dbg(efx, drv, efx->net_dev,
  337. "chan %d init event queue\n", channel->channel);
  338. rc = efx_nic_init_eventq(channel);
  339. if (rc == 0) {
  340. efx->type->push_irq_moderation(channel);
  341. channel->eventq_read_ptr = 0;
  342. channel->eventq_init = true;
  343. }
  344. return rc;
  345. }
  346. /* Enable event queue processing and NAPI */
  347. void efx_start_eventq(struct efx_channel *channel)
  348. {
  349. netif_dbg(channel->efx, ifup, channel->efx->net_dev,
  350. "chan %d start event queue\n", channel->channel);
  351. /* Make sure the NAPI handler sees the enabled flag set */
  352. channel->enabled = true;
  353. smp_wmb();
  354. napi_enable(&channel->napi_str);
  355. efx_nic_eventq_read_ack(channel);
  356. }
  357. /* Disable event queue processing and NAPI */
  358. void efx_stop_eventq(struct efx_channel *channel)
  359. {
  360. if (!channel->enabled)
  361. return;
  362. napi_disable(&channel->napi_str);
  363. channel->enabled = false;
  364. }
  365. static void efx_fini_eventq(struct efx_channel *channel)
  366. {
  367. if (!channel->eventq_init)
  368. return;
  369. netif_dbg(channel->efx, drv, channel->efx->net_dev,
  370. "chan %d fini event queue\n", channel->channel);
  371. efx_nic_fini_eventq(channel);
  372. channel->eventq_init = false;
  373. }
  374. static void efx_remove_eventq(struct efx_channel *channel)
  375. {
  376. netif_dbg(channel->efx, drv, channel->efx->net_dev,
  377. "chan %d remove event queue\n", channel->channel);
  378. efx_nic_remove_eventq(channel);
  379. }
  380. /**************************************************************************
  381. *
  382. * Channel handling
  383. *
  384. *************************************************************************/
  385. /* Allocate and initialise a channel structure. */
  386. static struct efx_channel *
  387. efx_alloc_channel(struct efx_nic *efx, int i, struct efx_channel *old_channel)
  388. {
  389. struct efx_channel *channel;
  390. struct efx_rx_queue *rx_queue;
  391. struct efx_tx_queue *tx_queue;
  392. int j;
  393. channel = kzalloc(sizeof(*channel), GFP_KERNEL);
  394. if (!channel)
  395. return NULL;
  396. channel->efx = efx;
  397. channel->channel = i;
  398. channel->type = &efx_default_channel_type;
  399. for (j = 0; j < EFX_TXQ_TYPES; j++) {
  400. tx_queue = &channel->tx_queue[j];
  401. tx_queue->efx = efx;
  402. tx_queue->queue = i * EFX_TXQ_TYPES + j;
  403. tx_queue->channel = channel;
  404. }
  405. rx_queue = &channel->rx_queue;
  406. rx_queue->efx = efx;
  407. timer_setup(&rx_queue->slow_fill, efx_rx_slow_fill, 0);
  408. return channel;
  409. }
  410. /* Allocate and initialise a channel structure, copying parameters
  411. * (but not resources) from an old channel structure.
  412. */
  413. static struct efx_channel *
  414. efx_copy_channel(const struct efx_channel *old_channel)
  415. {
  416. struct efx_channel *channel;
  417. struct efx_rx_queue *rx_queue;
  418. struct efx_tx_queue *tx_queue;
  419. int j;
  420. channel = kmalloc(sizeof(*channel), GFP_KERNEL);
  421. if (!channel)
  422. return NULL;
  423. *channel = *old_channel;
  424. channel->napi_dev = NULL;
  425. INIT_HLIST_NODE(&channel->napi_str.napi_hash_node);
  426. channel->napi_str.napi_id = 0;
  427. channel->napi_str.state = 0;
  428. memset(&channel->eventq, 0, sizeof(channel->eventq));
  429. for (j = 0; j < EFX_TXQ_TYPES; j++) {
  430. tx_queue = &channel->tx_queue[j];
  431. if (tx_queue->channel)
  432. tx_queue->channel = channel;
  433. tx_queue->buffer = NULL;
  434. memset(&tx_queue->txd, 0, sizeof(tx_queue->txd));
  435. }
  436. rx_queue = &channel->rx_queue;
  437. rx_queue->buffer = NULL;
  438. memset(&rx_queue->rxd, 0, sizeof(rx_queue->rxd));
  439. timer_setup(&rx_queue->slow_fill, efx_rx_slow_fill, 0);
  440. return channel;
  441. }
  442. static int efx_probe_channel(struct efx_channel *channel)
  443. {
  444. struct efx_tx_queue *tx_queue;
  445. struct efx_rx_queue *rx_queue;
  446. int rc;
  447. netif_dbg(channel->efx, probe, channel->efx->net_dev,
  448. "creating channel %d\n", channel->channel);
  449. rc = channel->type->pre_probe(channel);
  450. if (rc)
  451. goto fail;
  452. rc = efx_probe_eventq(channel);
  453. if (rc)
  454. goto fail;
  455. efx_for_each_channel_tx_queue(tx_queue, channel) {
  456. rc = efx_probe_tx_queue(tx_queue);
  457. if (rc)
  458. goto fail;
  459. }
  460. efx_for_each_channel_rx_queue(rx_queue, channel) {
  461. rc = efx_probe_rx_queue(rx_queue);
  462. if (rc)
  463. goto fail;
  464. }
  465. return 0;
  466. fail:
  467. efx_remove_channel(channel);
  468. return rc;
  469. }
  470. static void
  471. efx_get_channel_name(struct efx_channel *channel, char *buf, size_t len)
  472. {
  473. struct efx_nic *efx = channel->efx;
  474. const char *type;
  475. int number;
  476. number = channel->channel;
  477. if (efx->tx_channel_offset == 0) {
  478. type = "";
  479. } else if (channel->channel < efx->tx_channel_offset) {
  480. type = "-rx";
  481. } else {
  482. type = "-tx";
  483. number -= efx->tx_channel_offset;
  484. }
  485. snprintf(buf, len, "%s%s-%d", efx->name, type, number);
  486. }
  487. static void efx_set_channel_names(struct efx_nic *efx)
  488. {
  489. struct efx_channel *channel;
  490. efx_for_each_channel(channel, efx)
  491. channel->type->get_name(channel,
  492. efx->msi_context[channel->channel].name,
  493. sizeof(efx->msi_context[0].name));
  494. }
  495. static int efx_probe_channels(struct efx_nic *efx)
  496. {
  497. struct efx_channel *channel;
  498. int rc;
  499. /* Restart special buffer allocation */
  500. efx->next_buffer_table = 0;
  501. /* Probe channels in reverse, so that any 'extra' channels
  502. * use the start of the buffer table. This allows the traffic
  503. * channels to be resized without moving them or wasting the
  504. * entries before them.
  505. */
  506. efx_for_each_channel_rev(channel, efx) {
  507. rc = efx_probe_channel(channel);
  508. if (rc) {
  509. netif_err(efx, probe, efx->net_dev,
  510. "failed to create channel %d\n",
  511. channel->channel);
  512. goto fail;
  513. }
  514. }
  515. efx_set_channel_names(efx);
  516. return 0;
  517. fail:
  518. efx_remove_channels(efx);
  519. return rc;
  520. }
  521. /* Channels are shutdown and reinitialised whilst the NIC is running
  522. * to propagate configuration changes (mtu, checksum offload), or
  523. * to clear hardware error conditions
  524. */
  525. static void efx_start_datapath(struct efx_nic *efx)
  526. {
  527. netdev_features_t old_features = efx->net_dev->features;
  528. bool old_rx_scatter = efx->rx_scatter;
  529. struct efx_tx_queue *tx_queue;
  530. struct efx_rx_queue *rx_queue;
  531. struct efx_channel *channel;
  532. size_t rx_buf_len;
  533. /* Calculate the rx buffer allocation parameters required to
  534. * support the current MTU, including padding for header
  535. * alignment and overruns.
  536. */
  537. efx->rx_dma_len = (efx->rx_prefix_size +
  538. EFX_MAX_FRAME_LEN(efx->net_dev->mtu) +
  539. efx->type->rx_buffer_padding);
  540. rx_buf_len = (sizeof(struct efx_rx_page_state) +
  541. efx->rx_ip_align + efx->rx_dma_len);
  542. if (rx_buf_len <= PAGE_SIZE) {
  543. efx->rx_scatter = efx->type->always_rx_scatter;
  544. efx->rx_buffer_order = 0;
  545. } else if (efx->type->can_rx_scatter) {
  546. BUILD_BUG_ON(EFX_RX_USR_BUF_SIZE % L1_CACHE_BYTES);
  547. BUILD_BUG_ON(sizeof(struct efx_rx_page_state) +
  548. 2 * ALIGN(NET_IP_ALIGN + EFX_RX_USR_BUF_SIZE,
  549. EFX_RX_BUF_ALIGNMENT) >
  550. PAGE_SIZE);
  551. efx->rx_scatter = true;
  552. efx->rx_dma_len = EFX_RX_USR_BUF_SIZE;
  553. efx->rx_buffer_order = 0;
  554. } else {
  555. efx->rx_scatter = false;
  556. efx->rx_buffer_order = get_order(rx_buf_len);
  557. }
  558. efx_rx_config_page_split(efx);
  559. if (efx->rx_buffer_order)
  560. netif_dbg(efx, drv, efx->net_dev,
  561. "RX buf len=%u; page order=%u batch=%u\n",
  562. efx->rx_dma_len, efx->rx_buffer_order,
  563. efx->rx_pages_per_batch);
  564. else
  565. netif_dbg(efx, drv, efx->net_dev,
  566. "RX buf len=%u step=%u bpp=%u; page batch=%u\n",
  567. efx->rx_dma_len, efx->rx_page_buf_step,
  568. efx->rx_bufs_per_page, efx->rx_pages_per_batch);
  569. /* Restore previously fixed features in hw_features and remove
  570. * features which are fixed now
  571. */
  572. efx->net_dev->hw_features |= efx->net_dev->features;
  573. efx->net_dev->hw_features &= ~efx->fixed_features;
  574. efx->net_dev->features |= efx->fixed_features;
  575. if (efx->net_dev->features != old_features)
  576. netdev_features_change(efx->net_dev);
  577. /* RX filters may also have scatter-enabled flags */
  578. if (efx->rx_scatter != old_rx_scatter)
  579. efx->type->filter_update_rx_scatter(efx);
  580. /* We must keep at least one descriptor in a TX ring empty.
  581. * We could avoid this when the queue size does not exactly
  582. * match the hardware ring size, but it's not that important.
  583. * Therefore we stop the queue when one more skb might fill
  584. * the ring completely. We wake it when half way back to
  585. * empty.
  586. */
  587. efx->txq_stop_thresh = efx->txq_entries - efx_tx_max_skb_descs(efx);
  588. efx->txq_wake_thresh = efx->txq_stop_thresh / 2;
  589. /* Initialise the channels */
  590. efx_for_each_channel(channel, efx) {
  591. efx_for_each_channel_tx_queue(tx_queue, channel) {
  592. efx_init_tx_queue(tx_queue);
  593. atomic_inc(&efx->active_queues);
  594. }
  595. efx_for_each_channel_rx_queue(rx_queue, channel) {
  596. efx_init_rx_queue(rx_queue);
  597. atomic_inc(&efx->active_queues);
  598. efx_stop_eventq(channel);
  599. efx_fast_push_rx_descriptors(rx_queue, false);
  600. efx_start_eventq(channel);
  601. }
  602. WARN_ON(channel->rx_pkt_n_frags);
  603. }
  604. efx_ptp_start_datapath(efx);
  605. if (netif_device_present(efx->net_dev))
  606. netif_tx_wake_all_queues(efx->net_dev);
  607. }
  608. static void efx_stop_datapath(struct efx_nic *efx)
  609. {
  610. struct efx_channel *channel;
  611. struct efx_tx_queue *tx_queue;
  612. struct efx_rx_queue *rx_queue;
  613. int rc;
  614. EFX_ASSERT_RESET_SERIALISED(efx);
  615. BUG_ON(efx->port_enabled);
  616. efx_ptp_stop_datapath(efx);
  617. /* Stop RX refill */
  618. efx_for_each_channel(channel, efx) {
  619. efx_for_each_channel_rx_queue(rx_queue, channel)
  620. rx_queue->refill_enabled = false;
  621. }
  622. efx_for_each_channel(channel, efx) {
  623. /* RX packet processing is pipelined, so wait for the
  624. * NAPI handler to complete. At least event queue 0
  625. * might be kept active by non-data events, so don't
  626. * use napi_synchronize() but actually disable NAPI
  627. * temporarily.
  628. */
  629. if (efx_channel_has_rx_queue(channel)) {
  630. efx_stop_eventq(channel);
  631. efx_start_eventq(channel);
  632. }
  633. }
  634. rc = efx->type->fini_dmaq(efx);
  635. if (rc) {
  636. netif_err(efx, drv, efx->net_dev, "failed to flush queues\n");
  637. } else {
  638. netif_dbg(efx, drv, efx->net_dev,
  639. "successfully flushed all queues\n");
  640. }
  641. efx_for_each_channel(channel, efx) {
  642. efx_for_each_channel_rx_queue(rx_queue, channel)
  643. efx_fini_rx_queue(rx_queue);
  644. efx_for_each_possible_channel_tx_queue(tx_queue, channel)
  645. efx_fini_tx_queue(tx_queue);
  646. }
  647. }
  648. static void efx_remove_channel(struct efx_channel *channel)
  649. {
  650. struct efx_tx_queue *tx_queue;
  651. struct efx_rx_queue *rx_queue;
  652. netif_dbg(channel->efx, drv, channel->efx->net_dev,
  653. "destroy chan %d\n", channel->channel);
  654. efx_for_each_channel_rx_queue(rx_queue, channel)
  655. efx_remove_rx_queue(rx_queue);
  656. efx_for_each_possible_channel_tx_queue(tx_queue, channel)
  657. efx_remove_tx_queue(tx_queue);
  658. efx_remove_eventq(channel);
  659. channel->type->post_remove(channel);
  660. }
  661. static void efx_remove_channels(struct efx_nic *efx)
  662. {
  663. struct efx_channel *channel;
  664. efx_for_each_channel(channel, efx)
  665. efx_remove_channel(channel);
  666. }
  667. int
  668. efx_realloc_channels(struct efx_nic *efx, u32 rxq_entries, u32 txq_entries)
  669. {
  670. struct efx_channel *other_channel[EFX_MAX_CHANNELS], *channel;
  671. u32 old_rxq_entries, old_txq_entries;
  672. unsigned i, next_buffer_table = 0;
  673. int rc, rc2;
  674. rc = efx_check_disabled(efx);
  675. if (rc)
  676. return rc;
  677. /* Not all channels should be reallocated. We must avoid
  678. * reallocating their buffer table entries.
  679. */
  680. efx_for_each_channel(channel, efx) {
  681. struct efx_rx_queue *rx_queue;
  682. struct efx_tx_queue *tx_queue;
  683. if (channel->type->copy)
  684. continue;
  685. next_buffer_table = max(next_buffer_table,
  686. channel->eventq.index +
  687. channel->eventq.entries);
  688. efx_for_each_channel_rx_queue(rx_queue, channel)
  689. next_buffer_table = max(next_buffer_table,
  690. rx_queue->rxd.index +
  691. rx_queue->rxd.entries);
  692. efx_for_each_channel_tx_queue(tx_queue, channel)
  693. next_buffer_table = max(next_buffer_table,
  694. tx_queue->txd.index +
  695. tx_queue->txd.entries);
  696. }
  697. efx_device_detach_sync(efx);
  698. efx_stop_all(efx);
  699. efx_soft_disable_interrupts(efx);
  700. /* Clone channels (where possible) */
  701. memset(other_channel, 0, sizeof(other_channel));
  702. for (i = 0; i < efx->n_channels; i++) {
  703. channel = efx->channel[i];
  704. if (channel->type->copy)
  705. channel = channel->type->copy(channel);
  706. if (!channel) {
  707. rc = -ENOMEM;
  708. goto out;
  709. }
  710. other_channel[i] = channel;
  711. }
  712. /* Swap entry counts and channel pointers */
  713. old_rxq_entries = efx->rxq_entries;
  714. old_txq_entries = efx->txq_entries;
  715. efx->rxq_entries = rxq_entries;
  716. efx->txq_entries = txq_entries;
  717. for (i = 0; i < efx->n_channels; i++) {
  718. channel = efx->channel[i];
  719. efx->channel[i] = other_channel[i];
  720. other_channel[i] = channel;
  721. }
  722. /* Restart buffer table allocation */
  723. efx->next_buffer_table = next_buffer_table;
  724. for (i = 0; i < efx->n_channels; i++) {
  725. channel = efx->channel[i];
  726. if (!channel->type->copy)
  727. continue;
  728. rc = efx_probe_channel(channel);
  729. if (rc)
  730. goto rollback;
  731. efx_init_napi_channel(efx->channel[i]);
  732. }
  733. out:
  734. /* Destroy unused channel structures */
  735. for (i = 0; i < efx->n_channels; i++) {
  736. channel = other_channel[i];
  737. if (channel && channel->type->copy) {
  738. efx_fini_napi_channel(channel);
  739. efx_remove_channel(channel);
  740. kfree(channel);
  741. }
  742. }
  743. rc2 = efx_soft_enable_interrupts(efx);
  744. if (rc2) {
  745. rc = rc ? rc : rc2;
  746. netif_err(efx, drv, efx->net_dev,
  747. "unable to restart interrupts on channel reallocation\n");
  748. efx_schedule_reset(efx, RESET_TYPE_DISABLE);
  749. } else {
  750. efx_start_all(efx);
  751. efx_device_attach_if_not_resetting(efx);
  752. }
  753. return rc;
  754. rollback:
  755. /* Swap back */
  756. efx->rxq_entries = old_rxq_entries;
  757. efx->txq_entries = old_txq_entries;
  758. for (i = 0; i < efx->n_channels; i++) {
  759. channel = efx->channel[i];
  760. efx->channel[i] = other_channel[i];
  761. other_channel[i] = channel;
  762. }
  763. goto out;
  764. }
  765. void efx_schedule_slow_fill(struct efx_rx_queue *rx_queue)
  766. {
  767. mod_timer(&rx_queue->slow_fill, jiffies + msecs_to_jiffies(100));
  768. }
  769. static const struct efx_channel_type efx_default_channel_type = {
  770. .pre_probe = efx_channel_dummy_op_int,
  771. .post_remove = efx_channel_dummy_op_void,
  772. .get_name = efx_get_channel_name,
  773. .copy = efx_copy_channel,
  774. .keep_eventq = false,
  775. };
  776. int efx_channel_dummy_op_int(struct efx_channel *channel)
  777. {
  778. return 0;
  779. }
  780. void efx_channel_dummy_op_void(struct efx_channel *channel)
  781. {
  782. }
  783. /**************************************************************************
  784. *
  785. * Port handling
  786. *
  787. **************************************************************************/
  788. /* This ensures that the kernel is kept informed (via
  789. * netif_carrier_on/off) of the link status, and also maintains the
  790. * link status's stop on the port's TX queue.
  791. */
  792. void efx_link_status_changed(struct efx_nic *efx)
  793. {
  794. struct efx_link_state *link_state = &efx->link_state;
  795. /* SFC Bug 5356: A net_dev notifier is registered, so we must ensure
  796. * that no events are triggered between unregister_netdev() and the
  797. * driver unloading. A more general condition is that NETDEV_CHANGE
  798. * can only be generated between NETDEV_UP and NETDEV_DOWN */
  799. if (!netif_running(efx->net_dev))
  800. return;
  801. if (link_state->up != netif_carrier_ok(efx->net_dev)) {
  802. efx->n_link_state_changes++;
  803. if (link_state->up)
  804. netif_carrier_on(efx->net_dev);
  805. else
  806. netif_carrier_off(efx->net_dev);
  807. }
  808. /* Status message for kernel log */
  809. if (link_state->up)
  810. netif_info(efx, link, efx->net_dev,
  811. "link up at %uMbps %s-duplex (MTU %d)\n",
  812. link_state->speed, link_state->fd ? "full" : "half",
  813. efx->net_dev->mtu);
  814. else
  815. netif_info(efx, link, efx->net_dev, "link down\n");
  816. }
  817. void efx_link_set_advertising(struct efx_nic *efx, u32 advertising)
  818. {
  819. efx->link_advertising = advertising;
  820. if (advertising) {
  821. if (advertising & ADVERTISED_Pause)
  822. efx->wanted_fc |= (EFX_FC_TX | EFX_FC_RX);
  823. else
  824. efx->wanted_fc &= ~(EFX_FC_TX | EFX_FC_RX);
  825. if (advertising & ADVERTISED_Asym_Pause)
  826. efx->wanted_fc ^= EFX_FC_TX;
  827. }
  828. }
  829. void efx_link_set_wanted_fc(struct efx_nic *efx, u8 wanted_fc)
  830. {
  831. efx->wanted_fc = wanted_fc;
  832. if (efx->link_advertising) {
  833. if (wanted_fc & EFX_FC_RX)
  834. efx->link_advertising |= (ADVERTISED_Pause |
  835. ADVERTISED_Asym_Pause);
  836. else
  837. efx->link_advertising &= ~(ADVERTISED_Pause |
  838. ADVERTISED_Asym_Pause);
  839. if (wanted_fc & EFX_FC_TX)
  840. efx->link_advertising ^= ADVERTISED_Asym_Pause;
  841. }
  842. }
  843. static void efx_fini_port(struct efx_nic *efx);
  844. /* We assume that efx->type->reconfigure_mac will always try to sync RX
  845. * filters and therefore needs to read-lock the filter table against freeing
  846. */
  847. void efx_mac_reconfigure(struct efx_nic *efx)
  848. {
  849. down_read(&efx->filter_sem);
  850. efx->type->reconfigure_mac(efx);
  851. up_read(&efx->filter_sem);
  852. }
  853. /* Push loopback/power/transmit disable settings to the PHY, and reconfigure
  854. * the MAC appropriately. All other PHY configuration changes are pushed
  855. * through phy_op->set_settings(), and pushed asynchronously to the MAC
  856. * through efx_monitor().
  857. *
  858. * Callers must hold the mac_lock
  859. */
  860. int __efx_reconfigure_port(struct efx_nic *efx)
  861. {
  862. enum efx_phy_mode phy_mode;
  863. int rc;
  864. WARN_ON(!mutex_is_locked(&efx->mac_lock));
  865. /* Disable PHY transmit in mac level loopbacks */
  866. phy_mode = efx->phy_mode;
  867. if (LOOPBACK_INTERNAL(efx))
  868. efx->phy_mode |= PHY_MODE_TX_DISABLED;
  869. else
  870. efx->phy_mode &= ~PHY_MODE_TX_DISABLED;
  871. rc = efx->type->reconfigure_port(efx);
  872. if (rc)
  873. efx->phy_mode = phy_mode;
  874. return rc;
  875. }
  876. /* Reinitialise the MAC to pick up new PHY settings, even if the port is
  877. * disabled. */
  878. int efx_reconfigure_port(struct efx_nic *efx)
  879. {
  880. int rc;
  881. EFX_ASSERT_RESET_SERIALISED(efx);
  882. mutex_lock(&efx->mac_lock);
  883. rc = __efx_reconfigure_port(efx);
  884. mutex_unlock(&efx->mac_lock);
  885. return rc;
  886. }
  887. /* Asynchronous work item for changing MAC promiscuity and multicast
  888. * hash. Avoid a drain/rx_ingress enable by reconfiguring the current
  889. * MAC directly. */
  890. static void efx_mac_work(struct work_struct *data)
  891. {
  892. struct efx_nic *efx = container_of(data, struct efx_nic, mac_work);
  893. mutex_lock(&efx->mac_lock);
  894. if (efx->port_enabled)
  895. efx_mac_reconfigure(efx);
  896. mutex_unlock(&efx->mac_lock);
  897. }
  898. static int efx_probe_port(struct efx_nic *efx)
  899. {
  900. int rc;
  901. netif_dbg(efx, probe, efx->net_dev, "create port\n");
  902. if (phy_flash_cfg)
  903. efx->phy_mode = PHY_MODE_SPECIAL;
  904. /* Connect up MAC/PHY operations table */
  905. rc = efx->type->probe_port(efx);
  906. if (rc)
  907. return rc;
  908. /* Initialise MAC address to permanent address */
  909. ether_addr_copy(efx->net_dev->dev_addr, efx->net_dev->perm_addr);
  910. return 0;
  911. }
  912. static int efx_init_port(struct efx_nic *efx)
  913. {
  914. int rc;
  915. netif_dbg(efx, drv, efx->net_dev, "init port\n");
  916. mutex_lock(&efx->mac_lock);
  917. rc = efx->phy_op->init(efx);
  918. if (rc)
  919. goto fail1;
  920. efx->port_initialized = true;
  921. /* Reconfigure the MAC before creating dma queues (required for
  922. * Falcon/A1 where RX_INGR_EN/TX_DRAIN_EN isn't supported) */
  923. efx_mac_reconfigure(efx);
  924. /* Ensure the PHY advertises the correct flow control settings */
  925. rc = efx->phy_op->reconfigure(efx);
  926. if (rc && rc != -EPERM)
  927. goto fail2;
  928. mutex_unlock(&efx->mac_lock);
  929. return 0;
  930. fail2:
  931. efx->phy_op->fini(efx);
  932. fail1:
  933. mutex_unlock(&efx->mac_lock);
  934. return rc;
  935. }
  936. static void efx_start_port(struct efx_nic *efx)
  937. {
  938. netif_dbg(efx, ifup, efx->net_dev, "start port\n");
  939. BUG_ON(efx->port_enabled);
  940. mutex_lock(&efx->mac_lock);
  941. efx->port_enabled = true;
  942. /* Ensure MAC ingress/egress is enabled */
  943. efx_mac_reconfigure(efx);
  944. mutex_unlock(&efx->mac_lock);
  945. }
  946. /* Cancel work for MAC reconfiguration, periodic hardware monitoring
  947. * and the async self-test, wait for them to finish and prevent them
  948. * being scheduled again. This doesn't cover online resets, which
  949. * should only be cancelled when removing the device.
  950. */
  951. static void efx_stop_port(struct efx_nic *efx)
  952. {
  953. netif_dbg(efx, ifdown, efx->net_dev, "stop port\n");
  954. EFX_ASSERT_RESET_SERIALISED(efx);
  955. mutex_lock(&efx->mac_lock);
  956. efx->port_enabled = false;
  957. mutex_unlock(&efx->mac_lock);
  958. /* Serialise against efx_set_multicast_list() */
  959. netif_addr_lock_bh(efx->net_dev);
  960. netif_addr_unlock_bh(efx->net_dev);
  961. cancel_delayed_work_sync(&efx->monitor_work);
  962. efx_selftest_async_cancel(efx);
  963. cancel_work_sync(&efx->mac_work);
  964. }
  965. static void efx_fini_port(struct efx_nic *efx)
  966. {
  967. netif_dbg(efx, drv, efx->net_dev, "shut down port\n");
  968. if (!efx->port_initialized)
  969. return;
  970. efx->phy_op->fini(efx);
  971. efx->port_initialized = false;
  972. efx->link_state.up = false;
  973. efx_link_status_changed(efx);
  974. }
  975. static void efx_remove_port(struct efx_nic *efx)
  976. {
  977. netif_dbg(efx, drv, efx->net_dev, "destroying port\n");
  978. efx->type->remove_port(efx);
  979. }
  980. /**************************************************************************
  981. *
  982. * NIC handling
  983. *
  984. **************************************************************************/
  985. static LIST_HEAD(efx_primary_list);
  986. static LIST_HEAD(efx_unassociated_list);
  987. static bool efx_same_controller(struct efx_nic *left, struct efx_nic *right)
  988. {
  989. return left->type == right->type &&
  990. left->vpd_sn && right->vpd_sn &&
  991. !strcmp(left->vpd_sn, right->vpd_sn);
  992. }
  993. static void efx_associate(struct efx_nic *efx)
  994. {
  995. struct efx_nic *other, *next;
  996. if (efx->primary == efx) {
  997. /* Adding primary function; look for secondaries */
  998. netif_dbg(efx, probe, efx->net_dev, "adding to primary list\n");
  999. list_add_tail(&efx->node, &efx_primary_list);
  1000. list_for_each_entry_safe(other, next, &efx_unassociated_list,
  1001. node) {
  1002. if (efx_same_controller(efx, other)) {
  1003. list_del(&other->node);
  1004. netif_dbg(other, probe, other->net_dev,
  1005. "moving to secondary list of %s %s\n",
  1006. pci_name(efx->pci_dev),
  1007. efx->net_dev->name);
  1008. list_add_tail(&other->node,
  1009. &efx->secondary_list);
  1010. other->primary = efx;
  1011. }
  1012. }
  1013. } else {
  1014. /* Adding secondary function; look for primary */
  1015. list_for_each_entry(other, &efx_primary_list, node) {
  1016. if (efx_same_controller(efx, other)) {
  1017. netif_dbg(efx, probe, efx->net_dev,
  1018. "adding to secondary list of %s %s\n",
  1019. pci_name(other->pci_dev),
  1020. other->net_dev->name);
  1021. list_add_tail(&efx->node,
  1022. &other->secondary_list);
  1023. efx->primary = other;
  1024. return;
  1025. }
  1026. }
  1027. netif_dbg(efx, probe, efx->net_dev,
  1028. "adding to unassociated list\n");
  1029. list_add_tail(&efx->node, &efx_unassociated_list);
  1030. }
  1031. }
  1032. static void efx_dissociate(struct efx_nic *efx)
  1033. {
  1034. struct efx_nic *other, *next;
  1035. list_del(&efx->node);
  1036. efx->primary = NULL;
  1037. list_for_each_entry_safe(other, next, &efx->secondary_list, node) {
  1038. list_del(&other->node);
  1039. netif_dbg(other, probe, other->net_dev,
  1040. "moving to unassociated list\n");
  1041. list_add_tail(&other->node, &efx_unassociated_list);
  1042. other->primary = NULL;
  1043. }
  1044. }
  1045. /* This configures the PCI device to enable I/O and DMA. */
  1046. static int efx_init_io(struct efx_nic *efx)
  1047. {
  1048. struct pci_dev *pci_dev = efx->pci_dev;
  1049. dma_addr_t dma_mask = efx->type->max_dma_mask;
  1050. unsigned int mem_map_size = efx->type->mem_map_size(efx);
  1051. int rc, bar;
  1052. netif_dbg(efx, probe, efx->net_dev, "initialising I/O\n");
  1053. bar = efx->type->mem_bar;
  1054. rc = pci_enable_device(pci_dev);
  1055. if (rc) {
  1056. netif_err(efx, probe, efx->net_dev,
  1057. "failed to enable PCI device\n");
  1058. goto fail1;
  1059. }
  1060. pci_set_master(pci_dev);
  1061. /* Set the PCI DMA mask. Try all possibilities from our
  1062. * genuine mask down to 32 bits, because some architectures
  1063. * (e.g. x86_64 with iommu_sac_force set) will allow 40 bit
  1064. * masks event though they reject 46 bit masks.
  1065. */
  1066. while (dma_mask > 0x7fffffffUL) {
  1067. rc = dma_set_mask_and_coherent(&pci_dev->dev, dma_mask);
  1068. if (rc == 0)
  1069. break;
  1070. dma_mask >>= 1;
  1071. }
  1072. if (rc) {
  1073. netif_err(efx, probe, efx->net_dev,
  1074. "could not find a suitable DMA mask\n");
  1075. goto fail2;
  1076. }
  1077. netif_dbg(efx, probe, efx->net_dev,
  1078. "using DMA mask %llx\n", (unsigned long long) dma_mask);
  1079. efx->membase_phys = pci_resource_start(efx->pci_dev, bar);
  1080. rc = pci_request_region(pci_dev, bar, "sfc");
  1081. if (rc) {
  1082. netif_err(efx, probe, efx->net_dev,
  1083. "request for memory BAR failed\n");
  1084. rc = -EIO;
  1085. goto fail3;
  1086. }
  1087. efx->membase = ioremap_nocache(efx->membase_phys, mem_map_size);
  1088. if (!efx->membase) {
  1089. netif_err(efx, probe, efx->net_dev,
  1090. "could not map memory BAR at %llx+%x\n",
  1091. (unsigned long long)efx->membase_phys, mem_map_size);
  1092. rc = -ENOMEM;
  1093. goto fail4;
  1094. }
  1095. netif_dbg(efx, probe, efx->net_dev,
  1096. "memory BAR at %llx+%x (virtual %p)\n",
  1097. (unsigned long long)efx->membase_phys, mem_map_size,
  1098. efx->membase);
  1099. return 0;
  1100. fail4:
  1101. pci_release_region(efx->pci_dev, bar);
  1102. fail3:
  1103. efx->membase_phys = 0;
  1104. fail2:
  1105. pci_disable_device(efx->pci_dev);
  1106. fail1:
  1107. return rc;
  1108. }
  1109. static void efx_fini_io(struct efx_nic *efx)
  1110. {
  1111. int bar;
  1112. netif_dbg(efx, drv, efx->net_dev, "shutting down I/O\n");
  1113. if (efx->membase) {
  1114. iounmap(efx->membase);
  1115. efx->membase = NULL;
  1116. }
  1117. if (efx->membase_phys) {
  1118. bar = efx->type->mem_bar;
  1119. pci_release_region(efx->pci_dev, bar);
  1120. efx->membase_phys = 0;
  1121. }
  1122. /* Don't disable bus-mastering if VFs are assigned */
  1123. if (!pci_vfs_assigned(efx->pci_dev))
  1124. pci_disable_device(efx->pci_dev);
  1125. }
  1126. void efx_set_default_rx_indir_table(struct efx_nic *efx)
  1127. {
  1128. size_t i;
  1129. for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); i++)
  1130. efx->rx_indir_table[i] =
  1131. ethtool_rxfh_indir_default(i, efx->rss_spread);
  1132. }
  1133. static unsigned int efx_wanted_parallelism(struct efx_nic *efx)
  1134. {
  1135. cpumask_var_t thread_mask;
  1136. unsigned int count;
  1137. int cpu;
  1138. if (rss_cpus) {
  1139. count = rss_cpus;
  1140. } else {
  1141. if (unlikely(!zalloc_cpumask_var(&thread_mask, GFP_KERNEL))) {
  1142. netif_warn(efx, probe, efx->net_dev,
  1143. "RSS disabled due to allocation failure\n");
  1144. return 1;
  1145. }
  1146. count = 0;
  1147. for_each_online_cpu(cpu) {
  1148. if (!cpumask_test_cpu(cpu, thread_mask)) {
  1149. ++count;
  1150. cpumask_or(thread_mask, thread_mask,
  1151. topology_sibling_cpumask(cpu));
  1152. }
  1153. }
  1154. free_cpumask_var(thread_mask);
  1155. }
  1156. if (count > EFX_MAX_RX_QUEUES) {
  1157. netif_cond_dbg(efx, probe, efx->net_dev, !rss_cpus, warn,
  1158. "Reducing number of rx queues from %u to %u.\n",
  1159. count, EFX_MAX_RX_QUEUES);
  1160. count = EFX_MAX_RX_QUEUES;
  1161. }
  1162. /* If RSS is requested for the PF *and* VFs then we can't write RSS
  1163. * table entries that are inaccessible to VFs
  1164. */
  1165. #ifdef CONFIG_SFC_SRIOV
  1166. if (efx->type->sriov_wanted) {
  1167. if (efx->type->sriov_wanted(efx) && efx_vf_size(efx) > 1 &&
  1168. count > efx_vf_size(efx)) {
  1169. netif_warn(efx, probe, efx->net_dev,
  1170. "Reducing number of RSS channels from %u to %u for "
  1171. "VF support. Increase vf-msix-limit to use more "
  1172. "channels on the PF.\n",
  1173. count, efx_vf_size(efx));
  1174. count = efx_vf_size(efx);
  1175. }
  1176. }
  1177. #endif
  1178. return count;
  1179. }
  1180. /* Probe the number and type of interrupts we are able to obtain, and
  1181. * the resulting numbers of channels and RX queues.
  1182. */
  1183. static int efx_probe_interrupts(struct efx_nic *efx)
  1184. {
  1185. unsigned int extra_channels = 0;
  1186. unsigned int i, j;
  1187. int rc;
  1188. for (i = 0; i < EFX_MAX_EXTRA_CHANNELS; i++)
  1189. if (efx->extra_channel_type[i])
  1190. ++extra_channels;
  1191. if (efx->interrupt_mode == EFX_INT_MODE_MSIX) {
  1192. struct msix_entry xentries[EFX_MAX_CHANNELS];
  1193. unsigned int n_channels;
  1194. n_channels = efx_wanted_parallelism(efx);
  1195. if (efx_separate_tx_channels)
  1196. n_channels *= 2;
  1197. n_channels += extra_channels;
  1198. n_channels = min(n_channels, efx->max_channels);
  1199. for (i = 0; i < n_channels; i++)
  1200. xentries[i].entry = i;
  1201. rc = pci_enable_msix_range(efx->pci_dev,
  1202. xentries, 1, n_channels);
  1203. if (rc < 0) {
  1204. /* Fall back to single channel MSI */
  1205. netif_err(efx, drv, efx->net_dev,
  1206. "could not enable MSI-X\n");
  1207. if (efx->type->min_interrupt_mode >= EFX_INT_MODE_MSI)
  1208. efx->interrupt_mode = EFX_INT_MODE_MSI;
  1209. else
  1210. return rc;
  1211. } else if (rc < n_channels) {
  1212. netif_err(efx, drv, efx->net_dev,
  1213. "WARNING: Insufficient MSI-X vectors"
  1214. " available (%d < %u).\n", rc, n_channels);
  1215. netif_err(efx, drv, efx->net_dev,
  1216. "WARNING: Performance may be reduced.\n");
  1217. n_channels = rc;
  1218. }
  1219. if (rc > 0) {
  1220. efx->n_channels = n_channels;
  1221. if (n_channels > extra_channels)
  1222. n_channels -= extra_channels;
  1223. if (efx_separate_tx_channels) {
  1224. efx->n_tx_channels = min(max(n_channels / 2,
  1225. 1U),
  1226. efx->max_tx_channels);
  1227. efx->n_rx_channels = max(n_channels -
  1228. efx->n_tx_channels,
  1229. 1U);
  1230. } else {
  1231. efx->n_tx_channels = min(n_channels,
  1232. efx->max_tx_channels);
  1233. efx->n_rx_channels = n_channels;
  1234. }
  1235. for (i = 0; i < efx->n_channels; i++)
  1236. efx_get_channel(efx, i)->irq =
  1237. xentries[i].vector;
  1238. }
  1239. }
  1240. /* Try single interrupt MSI */
  1241. if (efx->interrupt_mode == EFX_INT_MODE_MSI) {
  1242. efx->n_channels = 1;
  1243. efx->n_rx_channels = 1;
  1244. efx->n_tx_channels = 1;
  1245. rc = pci_enable_msi(efx->pci_dev);
  1246. if (rc == 0) {
  1247. efx_get_channel(efx, 0)->irq = efx->pci_dev->irq;
  1248. } else {
  1249. netif_err(efx, drv, efx->net_dev,
  1250. "could not enable MSI\n");
  1251. if (efx->type->min_interrupt_mode >= EFX_INT_MODE_LEGACY)
  1252. efx->interrupt_mode = EFX_INT_MODE_LEGACY;
  1253. else
  1254. return rc;
  1255. }
  1256. }
  1257. /* Assume legacy interrupts */
  1258. if (efx->interrupt_mode == EFX_INT_MODE_LEGACY) {
  1259. efx->n_channels = 1 + (efx_separate_tx_channels ? 1 : 0);
  1260. efx->n_rx_channels = 1;
  1261. efx->n_tx_channels = 1;
  1262. efx->legacy_irq = efx->pci_dev->irq;
  1263. }
  1264. /* Assign extra channels if possible */
  1265. j = efx->n_channels;
  1266. for (i = 0; i < EFX_MAX_EXTRA_CHANNELS; i++) {
  1267. if (!efx->extra_channel_type[i])
  1268. continue;
  1269. if (efx->interrupt_mode != EFX_INT_MODE_MSIX ||
  1270. efx->n_channels <= extra_channels) {
  1271. efx->extra_channel_type[i]->handle_no_channel(efx);
  1272. } else {
  1273. --j;
  1274. efx_get_channel(efx, j)->type =
  1275. efx->extra_channel_type[i];
  1276. }
  1277. }
  1278. /* RSS might be usable on VFs even if it is disabled on the PF */
  1279. #ifdef CONFIG_SFC_SRIOV
  1280. if (efx->type->sriov_wanted) {
  1281. efx->rss_spread = ((efx->n_rx_channels > 1 ||
  1282. !efx->type->sriov_wanted(efx)) ?
  1283. efx->n_rx_channels : efx_vf_size(efx));
  1284. return 0;
  1285. }
  1286. #endif
  1287. efx->rss_spread = efx->n_rx_channels;
  1288. return 0;
  1289. }
  1290. static int efx_soft_enable_interrupts(struct efx_nic *efx)
  1291. {
  1292. struct efx_channel *channel, *end_channel;
  1293. int rc;
  1294. BUG_ON(efx->state == STATE_DISABLED);
  1295. efx->irq_soft_enabled = true;
  1296. smp_wmb();
  1297. efx_for_each_channel(channel, efx) {
  1298. if (!channel->type->keep_eventq) {
  1299. rc = efx_init_eventq(channel);
  1300. if (rc)
  1301. goto fail;
  1302. }
  1303. efx_start_eventq(channel);
  1304. }
  1305. efx_mcdi_mode_event(efx);
  1306. return 0;
  1307. fail:
  1308. end_channel = channel;
  1309. efx_for_each_channel(channel, efx) {
  1310. if (channel == end_channel)
  1311. break;
  1312. efx_stop_eventq(channel);
  1313. if (!channel->type->keep_eventq)
  1314. efx_fini_eventq(channel);
  1315. }
  1316. return rc;
  1317. }
  1318. static void efx_soft_disable_interrupts(struct efx_nic *efx)
  1319. {
  1320. struct efx_channel *channel;
  1321. if (efx->state == STATE_DISABLED)
  1322. return;
  1323. efx_mcdi_mode_poll(efx);
  1324. efx->irq_soft_enabled = false;
  1325. smp_wmb();
  1326. if (efx->legacy_irq)
  1327. synchronize_irq(efx->legacy_irq);
  1328. efx_for_each_channel(channel, efx) {
  1329. if (channel->irq)
  1330. synchronize_irq(channel->irq);
  1331. efx_stop_eventq(channel);
  1332. if (!channel->type->keep_eventq)
  1333. efx_fini_eventq(channel);
  1334. }
  1335. /* Flush the asynchronous MCDI request queue */
  1336. efx_mcdi_flush_async(efx);
  1337. }
  1338. static int efx_enable_interrupts(struct efx_nic *efx)
  1339. {
  1340. struct efx_channel *channel, *end_channel;
  1341. int rc;
  1342. BUG_ON(efx->state == STATE_DISABLED);
  1343. if (efx->eeh_disabled_legacy_irq) {
  1344. enable_irq(efx->legacy_irq);
  1345. efx->eeh_disabled_legacy_irq = false;
  1346. }
  1347. efx->type->irq_enable_master(efx);
  1348. efx_for_each_channel(channel, efx) {
  1349. if (channel->type->keep_eventq) {
  1350. rc = efx_init_eventq(channel);
  1351. if (rc)
  1352. goto fail;
  1353. }
  1354. }
  1355. rc = efx_soft_enable_interrupts(efx);
  1356. if (rc)
  1357. goto fail;
  1358. return 0;
  1359. fail:
  1360. end_channel = channel;
  1361. efx_for_each_channel(channel, efx) {
  1362. if (channel == end_channel)
  1363. break;
  1364. if (channel->type->keep_eventq)
  1365. efx_fini_eventq(channel);
  1366. }
  1367. efx->type->irq_disable_non_ev(efx);
  1368. return rc;
  1369. }
  1370. static void efx_disable_interrupts(struct efx_nic *efx)
  1371. {
  1372. struct efx_channel *channel;
  1373. efx_soft_disable_interrupts(efx);
  1374. efx_for_each_channel(channel, efx) {
  1375. if (channel->type->keep_eventq)
  1376. efx_fini_eventq(channel);
  1377. }
  1378. efx->type->irq_disable_non_ev(efx);
  1379. }
  1380. static void efx_remove_interrupts(struct efx_nic *efx)
  1381. {
  1382. struct efx_channel *channel;
  1383. /* Remove MSI/MSI-X interrupts */
  1384. efx_for_each_channel(channel, efx)
  1385. channel->irq = 0;
  1386. pci_disable_msi(efx->pci_dev);
  1387. pci_disable_msix(efx->pci_dev);
  1388. /* Remove legacy interrupt */
  1389. efx->legacy_irq = 0;
  1390. }
  1391. static void efx_set_channels(struct efx_nic *efx)
  1392. {
  1393. struct efx_channel *channel;
  1394. struct efx_tx_queue *tx_queue;
  1395. efx->tx_channel_offset =
  1396. efx_separate_tx_channels ?
  1397. efx->n_channels - efx->n_tx_channels : 0;
  1398. /* We need to mark which channels really have RX and TX
  1399. * queues, and adjust the TX queue numbers if we have separate
  1400. * RX-only and TX-only channels.
  1401. */
  1402. efx_for_each_channel(channel, efx) {
  1403. if (channel->channel < efx->n_rx_channels)
  1404. channel->rx_queue.core_index = channel->channel;
  1405. else
  1406. channel->rx_queue.core_index = -1;
  1407. efx_for_each_channel_tx_queue(tx_queue, channel)
  1408. tx_queue->queue -= (efx->tx_channel_offset *
  1409. EFX_TXQ_TYPES);
  1410. }
  1411. }
  1412. static int efx_probe_nic(struct efx_nic *efx)
  1413. {
  1414. int rc;
  1415. netif_dbg(efx, probe, efx->net_dev, "creating NIC\n");
  1416. /* Carry out hardware-type specific initialisation */
  1417. rc = efx->type->probe(efx);
  1418. if (rc)
  1419. return rc;
  1420. do {
  1421. if (!efx->max_channels || !efx->max_tx_channels) {
  1422. netif_err(efx, drv, efx->net_dev,
  1423. "Insufficient resources to allocate"
  1424. " any channels\n");
  1425. rc = -ENOSPC;
  1426. goto fail1;
  1427. }
  1428. /* Determine the number of channels and queues by trying
  1429. * to hook in MSI-X interrupts.
  1430. */
  1431. rc = efx_probe_interrupts(efx);
  1432. if (rc)
  1433. goto fail1;
  1434. efx_set_channels(efx);
  1435. /* dimension_resources can fail with EAGAIN */
  1436. rc = efx->type->dimension_resources(efx);
  1437. if (rc != 0 && rc != -EAGAIN)
  1438. goto fail2;
  1439. if (rc == -EAGAIN)
  1440. /* try again with new max_channels */
  1441. efx_remove_interrupts(efx);
  1442. } while (rc == -EAGAIN);
  1443. if (efx->n_channels > 1)
  1444. netdev_rss_key_fill(&efx->rx_hash_key,
  1445. sizeof(efx->rx_hash_key));
  1446. efx_set_default_rx_indir_table(efx);
  1447. netif_set_real_num_tx_queues(efx->net_dev, efx->n_tx_channels);
  1448. netif_set_real_num_rx_queues(efx->net_dev, efx->n_rx_channels);
  1449. /* Initialise the interrupt moderation settings */
  1450. efx->irq_mod_step_us = DIV_ROUND_UP(efx->timer_quantum_ns, 1000);
  1451. efx_init_irq_moderation(efx, tx_irq_mod_usec, rx_irq_mod_usec, true,
  1452. true);
  1453. return 0;
  1454. fail2:
  1455. efx_remove_interrupts(efx);
  1456. fail1:
  1457. efx->type->remove(efx);
  1458. return rc;
  1459. }
  1460. static void efx_remove_nic(struct efx_nic *efx)
  1461. {
  1462. netif_dbg(efx, drv, efx->net_dev, "destroying NIC\n");
  1463. efx_remove_interrupts(efx);
  1464. efx->type->remove(efx);
  1465. }
  1466. static int efx_probe_filters(struct efx_nic *efx)
  1467. {
  1468. int rc;
  1469. spin_lock_init(&efx->filter_lock);
  1470. init_rwsem(&efx->filter_sem);
  1471. mutex_lock(&efx->mac_lock);
  1472. down_write(&efx->filter_sem);
  1473. rc = efx->type->filter_table_probe(efx);
  1474. if (rc)
  1475. goto out_unlock;
  1476. #ifdef CONFIG_RFS_ACCEL
  1477. if (efx->type->offload_features & NETIF_F_NTUPLE) {
  1478. struct efx_channel *channel;
  1479. int i, success = 1;
  1480. efx_for_each_channel(channel, efx) {
  1481. channel->rps_flow_id =
  1482. kcalloc(efx->type->max_rx_ip_filters,
  1483. sizeof(*channel->rps_flow_id),
  1484. GFP_KERNEL);
  1485. if (!channel->rps_flow_id)
  1486. success = 0;
  1487. else
  1488. for (i = 0;
  1489. i < efx->type->max_rx_ip_filters;
  1490. ++i)
  1491. channel->rps_flow_id[i] =
  1492. RPS_FLOW_ID_INVALID;
  1493. }
  1494. if (!success) {
  1495. efx_for_each_channel(channel, efx)
  1496. kfree(channel->rps_flow_id);
  1497. efx->type->filter_table_remove(efx);
  1498. rc = -ENOMEM;
  1499. goto out_unlock;
  1500. }
  1501. efx->rps_expire_index = efx->rps_expire_channel = 0;
  1502. }
  1503. #endif
  1504. out_unlock:
  1505. up_write(&efx->filter_sem);
  1506. mutex_unlock(&efx->mac_lock);
  1507. return rc;
  1508. }
  1509. static void efx_remove_filters(struct efx_nic *efx)
  1510. {
  1511. #ifdef CONFIG_RFS_ACCEL
  1512. struct efx_channel *channel;
  1513. efx_for_each_channel(channel, efx)
  1514. kfree(channel->rps_flow_id);
  1515. #endif
  1516. down_write(&efx->filter_sem);
  1517. efx->type->filter_table_remove(efx);
  1518. up_write(&efx->filter_sem);
  1519. }
  1520. static void efx_restore_filters(struct efx_nic *efx)
  1521. {
  1522. down_read(&efx->filter_sem);
  1523. efx->type->filter_table_restore(efx);
  1524. up_read(&efx->filter_sem);
  1525. }
  1526. /**************************************************************************
  1527. *
  1528. * NIC startup/shutdown
  1529. *
  1530. *************************************************************************/
  1531. static int efx_probe_all(struct efx_nic *efx)
  1532. {
  1533. int rc;
  1534. rc = efx_probe_nic(efx);
  1535. if (rc) {
  1536. netif_err(efx, probe, efx->net_dev, "failed to create NIC\n");
  1537. goto fail1;
  1538. }
  1539. rc = efx_probe_port(efx);
  1540. if (rc) {
  1541. netif_err(efx, probe, efx->net_dev, "failed to create port\n");
  1542. goto fail2;
  1543. }
  1544. BUILD_BUG_ON(EFX_DEFAULT_DMAQ_SIZE < EFX_RXQ_MIN_ENT);
  1545. if (WARN_ON(EFX_DEFAULT_DMAQ_SIZE < EFX_TXQ_MIN_ENT(efx))) {
  1546. rc = -EINVAL;
  1547. goto fail3;
  1548. }
  1549. efx->rxq_entries = efx->txq_entries = EFX_DEFAULT_DMAQ_SIZE;
  1550. #ifdef CONFIG_SFC_SRIOV
  1551. rc = efx->type->vswitching_probe(efx);
  1552. if (rc) /* not fatal; the PF will still work fine */
  1553. netif_warn(efx, probe, efx->net_dev,
  1554. "failed to setup vswitching rc=%d;"
  1555. " VFs may not function\n", rc);
  1556. #endif
  1557. rc = efx_probe_filters(efx);
  1558. if (rc) {
  1559. netif_err(efx, probe, efx->net_dev,
  1560. "failed to create filter tables\n");
  1561. goto fail4;
  1562. }
  1563. rc = efx_probe_channels(efx);
  1564. if (rc)
  1565. goto fail5;
  1566. return 0;
  1567. fail5:
  1568. efx_remove_filters(efx);
  1569. fail4:
  1570. #ifdef CONFIG_SFC_SRIOV
  1571. efx->type->vswitching_remove(efx);
  1572. #endif
  1573. fail3:
  1574. efx_remove_port(efx);
  1575. fail2:
  1576. efx_remove_nic(efx);
  1577. fail1:
  1578. return rc;
  1579. }
  1580. /* If the interface is supposed to be running but is not, start
  1581. * the hardware and software data path, regular activity for the port
  1582. * (MAC statistics, link polling, etc.) and schedule the port to be
  1583. * reconfigured. Interrupts must already be enabled. This function
  1584. * is safe to call multiple times, so long as the NIC is not disabled.
  1585. * Requires the RTNL lock.
  1586. */
  1587. static void efx_start_all(struct efx_nic *efx)
  1588. {
  1589. EFX_ASSERT_RESET_SERIALISED(efx);
  1590. BUG_ON(efx->state == STATE_DISABLED);
  1591. /* Check that it is appropriate to restart the interface. All
  1592. * of these flags are safe to read under just the rtnl lock */
  1593. if (efx->port_enabled || !netif_running(efx->net_dev) ||
  1594. efx->reset_pending)
  1595. return;
  1596. efx_start_port(efx);
  1597. efx_start_datapath(efx);
  1598. /* Start the hardware monitor if there is one */
  1599. if (efx->type->monitor != NULL)
  1600. queue_delayed_work(efx->workqueue, &efx->monitor_work,
  1601. efx_monitor_interval);
  1602. /* Link state detection is normally event-driven; we have
  1603. * to poll now because we could have missed a change
  1604. */
  1605. mutex_lock(&efx->mac_lock);
  1606. if (efx->phy_op->poll(efx))
  1607. efx_link_status_changed(efx);
  1608. mutex_unlock(&efx->mac_lock);
  1609. efx->type->start_stats(efx);
  1610. efx->type->pull_stats(efx);
  1611. spin_lock_bh(&efx->stats_lock);
  1612. efx->type->update_stats(efx, NULL, NULL);
  1613. spin_unlock_bh(&efx->stats_lock);
  1614. }
  1615. /* Quiesce the hardware and software data path, and regular activity
  1616. * for the port without bringing the link down. Safe to call multiple
  1617. * times with the NIC in almost any state, but interrupts should be
  1618. * enabled. Requires the RTNL lock.
  1619. */
  1620. static void efx_stop_all(struct efx_nic *efx)
  1621. {
  1622. EFX_ASSERT_RESET_SERIALISED(efx);
  1623. /* port_enabled can be read safely under the rtnl lock */
  1624. if (!efx->port_enabled)
  1625. return;
  1626. /* update stats before we go down so we can accurately count
  1627. * rx_nodesc_drops
  1628. */
  1629. efx->type->pull_stats(efx);
  1630. spin_lock_bh(&efx->stats_lock);
  1631. efx->type->update_stats(efx, NULL, NULL);
  1632. spin_unlock_bh(&efx->stats_lock);
  1633. efx->type->stop_stats(efx);
  1634. efx_stop_port(efx);
  1635. /* Stop the kernel transmit interface. This is only valid if
  1636. * the device is stopped or detached; otherwise the watchdog
  1637. * may fire immediately.
  1638. */
  1639. WARN_ON(netif_running(efx->net_dev) &&
  1640. netif_device_present(efx->net_dev));
  1641. netif_tx_disable(efx->net_dev);
  1642. efx_stop_datapath(efx);
  1643. }
  1644. static void efx_remove_all(struct efx_nic *efx)
  1645. {
  1646. efx_remove_channels(efx);
  1647. efx_remove_filters(efx);
  1648. #ifdef CONFIG_SFC_SRIOV
  1649. efx->type->vswitching_remove(efx);
  1650. #endif
  1651. efx_remove_port(efx);
  1652. efx_remove_nic(efx);
  1653. }
  1654. /**************************************************************************
  1655. *
  1656. * Interrupt moderation
  1657. *
  1658. **************************************************************************/
  1659. unsigned int efx_usecs_to_ticks(struct efx_nic *efx, unsigned int usecs)
  1660. {
  1661. if (usecs == 0)
  1662. return 0;
  1663. if (usecs * 1000 < efx->timer_quantum_ns)
  1664. return 1; /* never round down to 0 */
  1665. return usecs * 1000 / efx->timer_quantum_ns;
  1666. }
  1667. unsigned int efx_ticks_to_usecs(struct efx_nic *efx, unsigned int ticks)
  1668. {
  1669. /* We must round up when converting ticks to microseconds
  1670. * because we round down when converting the other way.
  1671. */
  1672. return DIV_ROUND_UP(ticks * efx->timer_quantum_ns, 1000);
  1673. }
  1674. /* Set interrupt moderation parameters */
  1675. int efx_init_irq_moderation(struct efx_nic *efx, unsigned int tx_usecs,
  1676. unsigned int rx_usecs, bool rx_adaptive,
  1677. bool rx_may_override_tx)
  1678. {
  1679. struct efx_channel *channel;
  1680. unsigned int timer_max_us;
  1681. EFX_ASSERT_RESET_SERIALISED(efx);
  1682. timer_max_us = efx->timer_max_ns / 1000;
  1683. if (tx_usecs > timer_max_us || rx_usecs > timer_max_us)
  1684. return -EINVAL;
  1685. if (tx_usecs != rx_usecs && efx->tx_channel_offset == 0 &&
  1686. !rx_may_override_tx) {
  1687. netif_err(efx, drv, efx->net_dev, "Channels are shared. "
  1688. "RX and TX IRQ moderation must be equal\n");
  1689. return -EINVAL;
  1690. }
  1691. efx->irq_rx_adaptive = rx_adaptive;
  1692. efx->irq_rx_moderation_us = rx_usecs;
  1693. efx_for_each_channel(channel, efx) {
  1694. if (efx_channel_has_rx_queue(channel))
  1695. channel->irq_moderation_us = rx_usecs;
  1696. else if (efx_channel_has_tx_queues(channel))
  1697. channel->irq_moderation_us = tx_usecs;
  1698. }
  1699. return 0;
  1700. }
  1701. void efx_get_irq_moderation(struct efx_nic *efx, unsigned int *tx_usecs,
  1702. unsigned int *rx_usecs, bool *rx_adaptive)
  1703. {
  1704. *rx_adaptive = efx->irq_rx_adaptive;
  1705. *rx_usecs = efx->irq_rx_moderation_us;
  1706. /* If channels are shared between RX and TX, so is IRQ
  1707. * moderation. Otherwise, IRQ moderation is the same for all
  1708. * TX channels and is not adaptive.
  1709. */
  1710. if (efx->tx_channel_offset == 0) {
  1711. *tx_usecs = *rx_usecs;
  1712. } else {
  1713. struct efx_channel *tx_channel;
  1714. tx_channel = efx->channel[efx->tx_channel_offset];
  1715. *tx_usecs = tx_channel->irq_moderation_us;
  1716. }
  1717. }
  1718. /**************************************************************************
  1719. *
  1720. * Hardware monitor
  1721. *
  1722. **************************************************************************/
  1723. /* Run periodically off the general workqueue */
  1724. static void efx_monitor(struct work_struct *data)
  1725. {
  1726. struct efx_nic *efx = container_of(data, struct efx_nic,
  1727. monitor_work.work);
  1728. netif_vdbg(efx, timer, efx->net_dev,
  1729. "hardware monitor executing on CPU %d\n",
  1730. raw_smp_processor_id());
  1731. BUG_ON(efx->type->monitor == NULL);
  1732. /* If the mac_lock is already held then it is likely a port
  1733. * reconfiguration is already in place, which will likely do
  1734. * most of the work of monitor() anyway. */
  1735. if (mutex_trylock(&efx->mac_lock)) {
  1736. if (efx->port_enabled)
  1737. efx->type->monitor(efx);
  1738. mutex_unlock(&efx->mac_lock);
  1739. }
  1740. queue_delayed_work(efx->workqueue, &efx->monitor_work,
  1741. efx_monitor_interval);
  1742. }
  1743. /**************************************************************************
  1744. *
  1745. * ioctls
  1746. *
  1747. *************************************************************************/
  1748. /* Net device ioctl
  1749. * Context: process, rtnl_lock() held.
  1750. */
  1751. static int efx_ioctl(struct net_device *net_dev, struct ifreq *ifr, int cmd)
  1752. {
  1753. struct efx_nic *efx = netdev_priv(net_dev);
  1754. struct mii_ioctl_data *data = if_mii(ifr);
  1755. if (cmd == SIOCSHWTSTAMP)
  1756. return efx_ptp_set_ts_config(efx, ifr);
  1757. if (cmd == SIOCGHWTSTAMP)
  1758. return efx_ptp_get_ts_config(efx, ifr);
  1759. /* Convert phy_id from older PRTAD/DEVAD format */
  1760. if ((cmd == SIOCGMIIREG || cmd == SIOCSMIIREG) &&
  1761. (data->phy_id & 0xfc00) == 0x0400)
  1762. data->phy_id ^= MDIO_PHY_ID_C45 | 0x0400;
  1763. return mdio_mii_ioctl(&efx->mdio, data, cmd);
  1764. }
  1765. /**************************************************************************
  1766. *
  1767. * NAPI interface
  1768. *
  1769. **************************************************************************/
  1770. static void efx_init_napi_channel(struct efx_channel *channel)
  1771. {
  1772. struct efx_nic *efx = channel->efx;
  1773. channel->napi_dev = efx->net_dev;
  1774. netif_napi_add(channel->napi_dev, &channel->napi_str,
  1775. efx_poll, napi_weight);
  1776. }
  1777. static void efx_init_napi(struct efx_nic *efx)
  1778. {
  1779. struct efx_channel *channel;
  1780. efx_for_each_channel(channel, efx)
  1781. efx_init_napi_channel(channel);
  1782. }
  1783. static void efx_fini_napi_channel(struct efx_channel *channel)
  1784. {
  1785. if (channel->napi_dev)
  1786. netif_napi_del(&channel->napi_str);
  1787. channel->napi_dev = NULL;
  1788. }
  1789. static void efx_fini_napi(struct efx_nic *efx)
  1790. {
  1791. struct efx_channel *channel;
  1792. efx_for_each_channel(channel, efx)
  1793. efx_fini_napi_channel(channel);
  1794. }
  1795. /**************************************************************************
  1796. *
  1797. * Kernel netpoll interface
  1798. *
  1799. *************************************************************************/
  1800. #ifdef CONFIG_NET_POLL_CONTROLLER
  1801. /* Although in the common case interrupts will be disabled, this is not
  1802. * guaranteed. However, all our work happens inside the NAPI callback,
  1803. * so no locking is required.
  1804. */
  1805. static void efx_netpoll(struct net_device *net_dev)
  1806. {
  1807. struct efx_nic *efx = netdev_priv(net_dev);
  1808. struct efx_channel *channel;
  1809. efx_for_each_channel(channel, efx)
  1810. efx_schedule_channel(channel);
  1811. }
  1812. #endif
  1813. /**************************************************************************
  1814. *
  1815. * Kernel net device interface
  1816. *
  1817. *************************************************************************/
  1818. /* Context: process, rtnl_lock() held. */
  1819. int efx_net_open(struct net_device *net_dev)
  1820. {
  1821. struct efx_nic *efx = netdev_priv(net_dev);
  1822. int rc;
  1823. netif_dbg(efx, ifup, efx->net_dev, "opening device on CPU %d\n",
  1824. raw_smp_processor_id());
  1825. rc = efx_check_disabled(efx);
  1826. if (rc)
  1827. return rc;
  1828. if (efx->phy_mode & PHY_MODE_SPECIAL)
  1829. return -EBUSY;
  1830. if (efx_mcdi_poll_reboot(efx) && efx_reset(efx, RESET_TYPE_ALL))
  1831. return -EIO;
  1832. /* Notify the kernel of the link state polled during driver load,
  1833. * before the monitor starts running */
  1834. efx_link_status_changed(efx);
  1835. efx_start_all(efx);
  1836. if (efx->state == STATE_DISABLED || efx->reset_pending)
  1837. netif_device_detach(efx->net_dev);
  1838. efx_selftest_async_start(efx);
  1839. return 0;
  1840. }
  1841. /* Context: process, rtnl_lock() held.
  1842. * Note that the kernel will ignore our return code; this method
  1843. * should really be a void.
  1844. */
  1845. int efx_net_stop(struct net_device *net_dev)
  1846. {
  1847. struct efx_nic *efx = netdev_priv(net_dev);
  1848. netif_dbg(efx, ifdown, efx->net_dev, "closing on CPU %d\n",
  1849. raw_smp_processor_id());
  1850. /* Stop the device and flush all the channels */
  1851. efx_stop_all(efx);
  1852. return 0;
  1853. }
  1854. /* Context: process, dev_base_lock or RTNL held, non-blocking. */
  1855. static void efx_net_stats(struct net_device *net_dev,
  1856. struct rtnl_link_stats64 *stats)
  1857. {
  1858. struct efx_nic *efx = netdev_priv(net_dev);
  1859. spin_lock_bh(&efx->stats_lock);
  1860. efx->type->update_stats(efx, NULL, stats);
  1861. spin_unlock_bh(&efx->stats_lock);
  1862. }
  1863. /* Context: netif_tx_lock held, BHs disabled. */
  1864. static void efx_watchdog(struct net_device *net_dev)
  1865. {
  1866. struct efx_nic *efx = netdev_priv(net_dev);
  1867. netif_err(efx, tx_err, efx->net_dev,
  1868. "TX stuck with port_enabled=%d: resetting channels\n",
  1869. efx->port_enabled);
  1870. efx_schedule_reset(efx, RESET_TYPE_TX_WATCHDOG);
  1871. }
  1872. /* Context: process, rtnl_lock() held. */
  1873. static int efx_change_mtu(struct net_device *net_dev, int new_mtu)
  1874. {
  1875. struct efx_nic *efx = netdev_priv(net_dev);
  1876. int rc;
  1877. rc = efx_check_disabled(efx);
  1878. if (rc)
  1879. return rc;
  1880. netif_dbg(efx, drv, efx->net_dev, "changing MTU to %d\n", new_mtu);
  1881. efx_device_detach_sync(efx);
  1882. efx_stop_all(efx);
  1883. mutex_lock(&efx->mac_lock);
  1884. net_dev->mtu = new_mtu;
  1885. efx_mac_reconfigure(efx);
  1886. mutex_unlock(&efx->mac_lock);
  1887. efx_start_all(efx);
  1888. efx_device_attach_if_not_resetting(efx);
  1889. return 0;
  1890. }
  1891. static int efx_set_mac_address(struct net_device *net_dev, void *data)
  1892. {
  1893. struct efx_nic *efx = netdev_priv(net_dev);
  1894. struct sockaddr *addr = data;
  1895. u8 *new_addr = addr->sa_data;
  1896. u8 old_addr[6];
  1897. int rc;
  1898. if (!is_valid_ether_addr(new_addr)) {
  1899. netif_err(efx, drv, efx->net_dev,
  1900. "invalid ethernet MAC address requested: %pM\n",
  1901. new_addr);
  1902. return -EADDRNOTAVAIL;
  1903. }
  1904. /* save old address */
  1905. ether_addr_copy(old_addr, net_dev->dev_addr);
  1906. ether_addr_copy(net_dev->dev_addr, new_addr);
  1907. if (efx->type->set_mac_address) {
  1908. rc = efx->type->set_mac_address(efx);
  1909. if (rc) {
  1910. ether_addr_copy(net_dev->dev_addr, old_addr);
  1911. return rc;
  1912. }
  1913. }
  1914. /* Reconfigure the MAC */
  1915. mutex_lock(&efx->mac_lock);
  1916. efx_mac_reconfigure(efx);
  1917. mutex_unlock(&efx->mac_lock);
  1918. return 0;
  1919. }
  1920. /* Context: netif_addr_lock held, BHs disabled. */
  1921. static void efx_set_rx_mode(struct net_device *net_dev)
  1922. {
  1923. struct efx_nic *efx = netdev_priv(net_dev);
  1924. if (efx->port_enabled)
  1925. queue_work(efx->workqueue, &efx->mac_work);
  1926. /* Otherwise efx_start_port() will do this */
  1927. }
  1928. static int efx_set_features(struct net_device *net_dev, netdev_features_t data)
  1929. {
  1930. struct efx_nic *efx = netdev_priv(net_dev);
  1931. int rc;
  1932. /* If disabling RX n-tuple filtering, clear existing filters */
  1933. if (net_dev->features & ~data & NETIF_F_NTUPLE) {
  1934. rc = efx->type->filter_clear_rx(efx, EFX_FILTER_PRI_MANUAL);
  1935. if (rc)
  1936. return rc;
  1937. }
  1938. /* If Rx VLAN filter is changed, update filters via mac_reconfigure.
  1939. * If rx-fcs is changed, mac_reconfigure updates that too.
  1940. */
  1941. if ((net_dev->features ^ data) & (NETIF_F_HW_VLAN_CTAG_FILTER |
  1942. NETIF_F_RXFCS)) {
  1943. /* efx_set_rx_mode() will schedule MAC work to update filters
  1944. * when a new features are finally set in net_dev.
  1945. */
  1946. efx_set_rx_mode(net_dev);
  1947. }
  1948. return 0;
  1949. }
  1950. static int efx_get_phys_port_id(struct net_device *net_dev,
  1951. struct netdev_phys_item_id *ppid)
  1952. {
  1953. struct efx_nic *efx = netdev_priv(net_dev);
  1954. if (efx->type->get_phys_port_id)
  1955. return efx->type->get_phys_port_id(efx, ppid);
  1956. else
  1957. return -EOPNOTSUPP;
  1958. }
  1959. static int efx_get_phys_port_name(struct net_device *net_dev,
  1960. char *name, size_t len)
  1961. {
  1962. struct efx_nic *efx = netdev_priv(net_dev);
  1963. if (snprintf(name, len, "p%u", efx->port_num) >= len)
  1964. return -EINVAL;
  1965. return 0;
  1966. }
  1967. static int efx_vlan_rx_add_vid(struct net_device *net_dev, __be16 proto, u16 vid)
  1968. {
  1969. struct efx_nic *efx = netdev_priv(net_dev);
  1970. if (efx->type->vlan_rx_add_vid)
  1971. return efx->type->vlan_rx_add_vid(efx, proto, vid);
  1972. else
  1973. return -EOPNOTSUPP;
  1974. }
  1975. static int efx_vlan_rx_kill_vid(struct net_device *net_dev, __be16 proto, u16 vid)
  1976. {
  1977. struct efx_nic *efx = netdev_priv(net_dev);
  1978. if (efx->type->vlan_rx_kill_vid)
  1979. return efx->type->vlan_rx_kill_vid(efx, proto, vid);
  1980. else
  1981. return -EOPNOTSUPP;
  1982. }
  1983. static int efx_udp_tunnel_type_map(enum udp_parsable_tunnel_type in)
  1984. {
  1985. switch (in) {
  1986. case UDP_TUNNEL_TYPE_VXLAN:
  1987. return TUNNEL_ENCAP_UDP_PORT_ENTRY_VXLAN;
  1988. case UDP_TUNNEL_TYPE_GENEVE:
  1989. return TUNNEL_ENCAP_UDP_PORT_ENTRY_GENEVE;
  1990. default:
  1991. return -1;
  1992. }
  1993. }
  1994. static void efx_udp_tunnel_add(struct net_device *dev, struct udp_tunnel_info *ti)
  1995. {
  1996. struct efx_nic *efx = netdev_priv(dev);
  1997. struct efx_udp_tunnel tnl;
  1998. int efx_tunnel_type;
  1999. efx_tunnel_type = efx_udp_tunnel_type_map(ti->type);
  2000. if (efx_tunnel_type < 0)
  2001. return;
  2002. tnl.type = (u16)efx_tunnel_type;
  2003. tnl.port = ti->port;
  2004. if (efx->type->udp_tnl_add_port)
  2005. (void)efx->type->udp_tnl_add_port(efx, tnl);
  2006. }
  2007. static void efx_udp_tunnel_del(struct net_device *dev, struct udp_tunnel_info *ti)
  2008. {
  2009. struct efx_nic *efx = netdev_priv(dev);
  2010. struct efx_udp_tunnel tnl;
  2011. int efx_tunnel_type;
  2012. efx_tunnel_type = efx_udp_tunnel_type_map(ti->type);
  2013. if (efx_tunnel_type < 0)
  2014. return;
  2015. tnl.type = (u16)efx_tunnel_type;
  2016. tnl.port = ti->port;
  2017. if (efx->type->udp_tnl_del_port)
  2018. (void)efx->type->udp_tnl_del_port(efx, tnl);
  2019. }
  2020. static const struct net_device_ops efx_netdev_ops = {
  2021. .ndo_open = efx_net_open,
  2022. .ndo_stop = efx_net_stop,
  2023. .ndo_get_stats64 = efx_net_stats,
  2024. .ndo_tx_timeout = efx_watchdog,
  2025. .ndo_start_xmit = efx_hard_start_xmit,
  2026. .ndo_validate_addr = eth_validate_addr,
  2027. .ndo_do_ioctl = efx_ioctl,
  2028. .ndo_change_mtu = efx_change_mtu,
  2029. .ndo_set_mac_address = efx_set_mac_address,
  2030. .ndo_set_rx_mode = efx_set_rx_mode,
  2031. .ndo_set_features = efx_set_features,
  2032. .ndo_vlan_rx_add_vid = efx_vlan_rx_add_vid,
  2033. .ndo_vlan_rx_kill_vid = efx_vlan_rx_kill_vid,
  2034. #ifdef CONFIG_SFC_SRIOV
  2035. .ndo_set_vf_mac = efx_sriov_set_vf_mac,
  2036. .ndo_set_vf_vlan = efx_sriov_set_vf_vlan,
  2037. .ndo_set_vf_spoofchk = efx_sriov_set_vf_spoofchk,
  2038. .ndo_get_vf_config = efx_sriov_get_vf_config,
  2039. .ndo_set_vf_link_state = efx_sriov_set_vf_link_state,
  2040. #endif
  2041. .ndo_get_phys_port_id = efx_get_phys_port_id,
  2042. .ndo_get_phys_port_name = efx_get_phys_port_name,
  2043. #ifdef CONFIG_NET_POLL_CONTROLLER
  2044. .ndo_poll_controller = efx_netpoll,
  2045. #endif
  2046. .ndo_setup_tc = efx_setup_tc,
  2047. #ifdef CONFIG_RFS_ACCEL
  2048. .ndo_rx_flow_steer = efx_filter_rfs,
  2049. #endif
  2050. .ndo_udp_tunnel_add = efx_udp_tunnel_add,
  2051. .ndo_udp_tunnel_del = efx_udp_tunnel_del,
  2052. };
  2053. static void efx_update_name(struct efx_nic *efx)
  2054. {
  2055. strcpy(efx->name, efx->net_dev->name);
  2056. efx_mtd_rename(efx);
  2057. efx_set_channel_names(efx);
  2058. }
  2059. static int efx_netdev_event(struct notifier_block *this,
  2060. unsigned long event, void *ptr)
  2061. {
  2062. struct net_device *net_dev = netdev_notifier_info_to_dev(ptr);
  2063. if ((net_dev->netdev_ops == &efx_netdev_ops) &&
  2064. event == NETDEV_CHANGENAME)
  2065. efx_update_name(netdev_priv(net_dev));
  2066. return NOTIFY_DONE;
  2067. }
  2068. static struct notifier_block efx_netdev_notifier = {
  2069. .notifier_call = efx_netdev_event,
  2070. };
  2071. static ssize_t
  2072. show_phy_type(struct device *dev, struct device_attribute *attr, char *buf)
  2073. {
  2074. struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
  2075. return sprintf(buf, "%d\n", efx->phy_type);
  2076. }
  2077. static DEVICE_ATTR(phy_type, 0444, show_phy_type, NULL);
  2078. #ifdef CONFIG_SFC_MCDI_LOGGING
  2079. static ssize_t show_mcdi_log(struct device *dev, struct device_attribute *attr,
  2080. char *buf)
  2081. {
  2082. struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
  2083. struct efx_mcdi_iface *mcdi = efx_mcdi(efx);
  2084. return scnprintf(buf, PAGE_SIZE, "%d\n", mcdi->logging_enabled);
  2085. }
  2086. static ssize_t set_mcdi_log(struct device *dev, struct device_attribute *attr,
  2087. const char *buf, size_t count)
  2088. {
  2089. struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
  2090. struct efx_mcdi_iface *mcdi = efx_mcdi(efx);
  2091. bool enable = count > 0 && *buf != '0';
  2092. mcdi->logging_enabled = enable;
  2093. return count;
  2094. }
  2095. static DEVICE_ATTR(mcdi_logging, 0644, show_mcdi_log, set_mcdi_log);
  2096. #endif
  2097. static int efx_register_netdev(struct efx_nic *efx)
  2098. {
  2099. struct net_device *net_dev = efx->net_dev;
  2100. struct efx_channel *channel;
  2101. int rc;
  2102. net_dev->watchdog_timeo = 5 * HZ;
  2103. net_dev->irq = efx->pci_dev->irq;
  2104. net_dev->netdev_ops = &efx_netdev_ops;
  2105. if (efx_nic_rev(efx) >= EFX_REV_HUNT_A0)
  2106. net_dev->priv_flags |= IFF_UNICAST_FLT;
  2107. net_dev->ethtool_ops = &efx_ethtool_ops;
  2108. net_dev->gso_max_segs = EFX_TSO_MAX_SEGS;
  2109. net_dev->min_mtu = EFX_MIN_MTU;
  2110. net_dev->max_mtu = EFX_MAX_MTU;
  2111. rtnl_lock();
  2112. /* Enable resets to be scheduled and check whether any were
  2113. * already requested. If so, the NIC is probably hosed so we
  2114. * abort.
  2115. */
  2116. efx->state = STATE_READY;
  2117. smp_mb(); /* ensure we change state before checking reset_pending */
  2118. if (efx->reset_pending) {
  2119. netif_err(efx, probe, efx->net_dev,
  2120. "aborting probe due to scheduled reset\n");
  2121. rc = -EIO;
  2122. goto fail_locked;
  2123. }
  2124. rc = dev_alloc_name(net_dev, net_dev->name);
  2125. if (rc < 0)
  2126. goto fail_locked;
  2127. efx_update_name(efx);
  2128. /* Always start with carrier off; PHY events will detect the link */
  2129. netif_carrier_off(net_dev);
  2130. rc = register_netdevice(net_dev);
  2131. if (rc)
  2132. goto fail_locked;
  2133. efx_for_each_channel(channel, efx) {
  2134. struct efx_tx_queue *tx_queue;
  2135. efx_for_each_channel_tx_queue(tx_queue, channel)
  2136. efx_init_tx_queue_core_txq(tx_queue);
  2137. }
  2138. efx_associate(efx);
  2139. rtnl_unlock();
  2140. rc = device_create_file(&efx->pci_dev->dev, &dev_attr_phy_type);
  2141. if (rc) {
  2142. netif_err(efx, drv, efx->net_dev,
  2143. "failed to init net dev attributes\n");
  2144. goto fail_registered;
  2145. }
  2146. #ifdef CONFIG_SFC_MCDI_LOGGING
  2147. rc = device_create_file(&efx->pci_dev->dev, &dev_attr_mcdi_logging);
  2148. if (rc) {
  2149. netif_err(efx, drv, efx->net_dev,
  2150. "failed to init net dev attributes\n");
  2151. goto fail_attr_mcdi_logging;
  2152. }
  2153. #endif
  2154. return 0;
  2155. #ifdef CONFIG_SFC_MCDI_LOGGING
  2156. fail_attr_mcdi_logging:
  2157. device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_type);
  2158. #endif
  2159. fail_registered:
  2160. rtnl_lock();
  2161. efx_dissociate(efx);
  2162. unregister_netdevice(net_dev);
  2163. fail_locked:
  2164. efx->state = STATE_UNINIT;
  2165. rtnl_unlock();
  2166. netif_err(efx, drv, efx->net_dev, "could not register net dev\n");
  2167. return rc;
  2168. }
  2169. static void efx_unregister_netdev(struct efx_nic *efx)
  2170. {
  2171. if (!efx->net_dev)
  2172. return;
  2173. BUG_ON(netdev_priv(efx->net_dev) != efx);
  2174. if (efx_dev_registered(efx)) {
  2175. strlcpy(efx->name, pci_name(efx->pci_dev), sizeof(efx->name));
  2176. #ifdef CONFIG_SFC_MCDI_LOGGING
  2177. device_remove_file(&efx->pci_dev->dev, &dev_attr_mcdi_logging);
  2178. #endif
  2179. device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_type);
  2180. unregister_netdev(efx->net_dev);
  2181. }
  2182. }
  2183. /**************************************************************************
  2184. *
  2185. * Device reset and suspend
  2186. *
  2187. **************************************************************************/
  2188. /* Tears down the entire software state and most of the hardware state
  2189. * before reset. */
  2190. void efx_reset_down(struct efx_nic *efx, enum reset_type method)
  2191. {
  2192. EFX_ASSERT_RESET_SERIALISED(efx);
  2193. if (method == RESET_TYPE_MCDI_TIMEOUT)
  2194. efx->type->prepare_flr(efx);
  2195. efx_stop_all(efx);
  2196. efx_disable_interrupts(efx);
  2197. mutex_lock(&efx->mac_lock);
  2198. if (efx->port_initialized && method != RESET_TYPE_INVISIBLE &&
  2199. method != RESET_TYPE_DATAPATH)
  2200. efx->phy_op->fini(efx);
  2201. efx->type->fini(efx);
  2202. }
  2203. /* This function will always ensure that the locks acquired in
  2204. * efx_reset_down() are released. A failure return code indicates
  2205. * that we were unable to reinitialise the hardware, and the
  2206. * driver should be disabled. If ok is false, then the rx and tx
  2207. * engines are not restarted, pending a RESET_DISABLE. */
  2208. int efx_reset_up(struct efx_nic *efx, enum reset_type method, bool ok)
  2209. {
  2210. int rc;
  2211. EFX_ASSERT_RESET_SERIALISED(efx);
  2212. if (method == RESET_TYPE_MCDI_TIMEOUT)
  2213. efx->type->finish_flr(efx);
  2214. /* Ensure that SRAM is initialised even if we're disabling the device */
  2215. rc = efx->type->init(efx);
  2216. if (rc) {
  2217. netif_err(efx, drv, efx->net_dev, "failed to initialise NIC\n");
  2218. goto fail;
  2219. }
  2220. if (!ok)
  2221. goto fail;
  2222. if (efx->port_initialized && method != RESET_TYPE_INVISIBLE &&
  2223. method != RESET_TYPE_DATAPATH) {
  2224. rc = efx->phy_op->init(efx);
  2225. if (rc)
  2226. goto fail;
  2227. rc = efx->phy_op->reconfigure(efx);
  2228. if (rc && rc != -EPERM)
  2229. netif_err(efx, drv, efx->net_dev,
  2230. "could not restore PHY settings\n");
  2231. }
  2232. rc = efx_enable_interrupts(efx);
  2233. if (rc)
  2234. goto fail;
  2235. #ifdef CONFIG_SFC_SRIOV
  2236. rc = efx->type->vswitching_restore(efx);
  2237. if (rc) /* not fatal; the PF will still work fine */
  2238. netif_warn(efx, probe, efx->net_dev,
  2239. "failed to restore vswitching rc=%d;"
  2240. " VFs may not function\n", rc);
  2241. #endif
  2242. down_read(&efx->filter_sem);
  2243. efx_restore_filters(efx);
  2244. up_read(&efx->filter_sem);
  2245. if (efx->type->sriov_reset)
  2246. efx->type->sriov_reset(efx);
  2247. mutex_unlock(&efx->mac_lock);
  2248. efx_start_all(efx);
  2249. if (efx->type->udp_tnl_push_ports)
  2250. efx->type->udp_tnl_push_ports(efx);
  2251. return 0;
  2252. fail:
  2253. efx->port_initialized = false;
  2254. mutex_unlock(&efx->mac_lock);
  2255. return rc;
  2256. }
  2257. /* Reset the NIC using the specified method. Note that the reset may
  2258. * fail, in which case the card will be left in an unusable state.
  2259. *
  2260. * Caller must hold the rtnl_lock.
  2261. */
  2262. int efx_reset(struct efx_nic *efx, enum reset_type method)
  2263. {
  2264. int rc, rc2;
  2265. bool disabled;
  2266. netif_info(efx, drv, efx->net_dev, "resetting (%s)\n",
  2267. RESET_TYPE(method));
  2268. efx_device_detach_sync(efx);
  2269. efx_reset_down(efx, method);
  2270. rc = efx->type->reset(efx, method);
  2271. if (rc) {
  2272. netif_err(efx, drv, efx->net_dev, "failed to reset hardware\n");
  2273. goto out;
  2274. }
  2275. /* Clear flags for the scopes we covered. We assume the NIC and
  2276. * driver are now quiescent so that there is no race here.
  2277. */
  2278. if (method < RESET_TYPE_MAX_METHOD)
  2279. efx->reset_pending &= -(1 << (method + 1));
  2280. else /* it doesn't fit into the well-ordered scope hierarchy */
  2281. __clear_bit(method, &efx->reset_pending);
  2282. /* Reinitialise bus-mastering, which may have been turned off before
  2283. * the reset was scheduled. This is still appropriate, even in the
  2284. * RESET_TYPE_DISABLE since this driver generally assumes the hardware
  2285. * can respond to requests. */
  2286. pci_set_master(efx->pci_dev);
  2287. out:
  2288. /* Leave device stopped if necessary */
  2289. disabled = rc ||
  2290. method == RESET_TYPE_DISABLE ||
  2291. method == RESET_TYPE_RECOVER_OR_DISABLE;
  2292. rc2 = efx_reset_up(efx, method, !disabled);
  2293. if (rc2) {
  2294. disabled = true;
  2295. if (!rc)
  2296. rc = rc2;
  2297. }
  2298. if (disabled) {
  2299. dev_close(efx->net_dev);
  2300. netif_err(efx, drv, efx->net_dev, "has been disabled\n");
  2301. efx->state = STATE_DISABLED;
  2302. } else {
  2303. netif_dbg(efx, drv, efx->net_dev, "reset complete\n");
  2304. efx_device_attach_if_not_resetting(efx);
  2305. }
  2306. return rc;
  2307. }
  2308. /* Try recovery mechanisms.
  2309. * For now only EEH is supported.
  2310. * Returns 0 if the recovery mechanisms are unsuccessful.
  2311. * Returns a non-zero value otherwise.
  2312. */
  2313. int efx_try_recovery(struct efx_nic *efx)
  2314. {
  2315. #ifdef CONFIG_EEH
  2316. /* A PCI error can occur and not be seen by EEH because nothing
  2317. * happens on the PCI bus. In this case the driver may fail and
  2318. * schedule a 'recover or reset', leading to this recovery handler.
  2319. * Manually call the eeh failure check function.
  2320. */
  2321. struct eeh_dev *eehdev = pci_dev_to_eeh_dev(efx->pci_dev);
  2322. if (eeh_dev_check_failure(eehdev)) {
  2323. /* The EEH mechanisms will handle the error and reset the
  2324. * device if necessary.
  2325. */
  2326. return 1;
  2327. }
  2328. #endif
  2329. return 0;
  2330. }
  2331. static void efx_wait_for_bist_end(struct efx_nic *efx)
  2332. {
  2333. int i;
  2334. for (i = 0; i < BIST_WAIT_DELAY_COUNT; ++i) {
  2335. if (efx_mcdi_poll_reboot(efx))
  2336. goto out;
  2337. msleep(BIST_WAIT_DELAY_MS);
  2338. }
  2339. netif_err(efx, drv, efx->net_dev, "Warning: No MC reboot after BIST mode\n");
  2340. out:
  2341. /* Either way unset the BIST flag. If we found no reboot we probably
  2342. * won't recover, but we should try.
  2343. */
  2344. efx->mc_bist_for_other_fn = false;
  2345. }
  2346. /* The worker thread exists so that code that cannot sleep can
  2347. * schedule a reset for later.
  2348. */
  2349. static void efx_reset_work(struct work_struct *data)
  2350. {
  2351. struct efx_nic *efx = container_of(data, struct efx_nic, reset_work);
  2352. unsigned long pending;
  2353. enum reset_type method;
  2354. pending = ACCESS_ONCE(efx->reset_pending);
  2355. method = fls(pending) - 1;
  2356. if (method == RESET_TYPE_MC_BIST)
  2357. efx_wait_for_bist_end(efx);
  2358. if ((method == RESET_TYPE_RECOVER_OR_DISABLE ||
  2359. method == RESET_TYPE_RECOVER_OR_ALL) &&
  2360. efx_try_recovery(efx))
  2361. return;
  2362. if (!pending)
  2363. return;
  2364. rtnl_lock();
  2365. /* We checked the state in efx_schedule_reset() but it may
  2366. * have changed by now. Now that we have the RTNL lock,
  2367. * it cannot change again.
  2368. */
  2369. if (efx->state == STATE_READY)
  2370. (void)efx_reset(efx, method);
  2371. rtnl_unlock();
  2372. }
  2373. void efx_schedule_reset(struct efx_nic *efx, enum reset_type type)
  2374. {
  2375. enum reset_type method;
  2376. if (efx->state == STATE_RECOVERY) {
  2377. netif_dbg(efx, drv, efx->net_dev,
  2378. "recovering: skip scheduling %s reset\n",
  2379. RESET_TYPE(type));
  2380. return;
  2381. }
  2382. switch (type) {
  2383. case RESET_TYPE_INVISIBLE:
  2384. case RESET_TYPE_ALL:
  2385. case RESET_TYPE_RECOVER_OR_ALL:
  2386. case RESET_TYPE_WORLD:
  2387. case RESET_TYPE_DISABLE:
  2388. case RESET_TYPE_RECOVER_OR_DISABLE:
  2389. case RESET_TYPE_DATAPATH:
  2390. case RESET_TYPE_MC_BIST:
  2391. case RESET_TYPE_MCDI_TIMEOUT:
  2392. method = type;
  2393. netif_dbg(efx, drv, efx->net_dev, "scheduling %s reset\n",
  2394. RESET_TYPE(method));
  2395. break;
  2396. default:
  2397. method = efx->type->map_reset_reason(type);
  2398. netif_dbg(efx, drv, efx->net_dev,
  2399. "scheduling %s reset for %s\n",
  2400. RESET_TYPE(method), RESET_TYPE(type));
  2401. break;
  2402. }
  2403. set_bit(method, &efx->reset_pending);
  2404. smp_mb(); /* ensure we change reset_pending before checking state */
  2405. /* If we're not READY then just leave the flags set as the cue
  2406. * to abort probing or reschedule the reset later.
  2407. */
  2408. if (ACCESS_ONCE(efx->state) != STATE_READY)
  2409. return;
  2410. /* efx_process_channel() will no longer read events once a
  2411. * reset is scheduled. So switch back to poll'd MCDI completions. */
  2412. efx_mcdi_mode_poll(efx);
  2413. queue_work(reset_workqueue, &efx->reset_work);
  2414. }
  2415. /**************************************************************************
  2416. *
  2417. * List of NICs we support
  2418. *
  2419. **************************************************************************/
  2420. /* PCI device ID table */
  2421. static const struct pci_device_id efx_pci_table[] = {
  2422. {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0803), /* SFC9020 */
  2423. .driver_data = (unsigned long) &siena_a0_nic_type},
  2424. {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0813), /* SFL9021 */
  2425. .driver_data = (unsigned long) &siena_a0_nic_type},
  2426. {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0903), /* SFC9120 PF */
  2427. .driver_data = (unsigned long) &efx_hunt_a0_nic_type},
  2428. {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1903), /* SFC9120 VF */
  2429. .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type},
  2430. {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0923), /* SFC9140 PF */
  2431. .driver_data = (unsigned long) &efx_hunt_a0_nic_type},
  2432. {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1923), /* SFC9140 VF */
  2433. .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type},
  2434. {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0a03), /* SFC9220 PF */
  2435. .driver_data = (unsigned long) &efx_hunt_a0_nic_type},
  2436. {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1a03), /* SFC9220 VF */
  2437. .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type},
  2438. {0} /* end of list */
  2439. };
  2440. /**************************************************************************
  2441. *
  2442. * Dummy PHY/MAC operations
  2443. *
  2444. * Can be used for some unimplemented operations
  2445. * Needed so all function pointers are valid and do not have to be tested
  2446. * before use
  2447. *
  2448. **************************************************************************/
  2449. int efx_port_dummy_op_int(struct efx_nic *efx)
  2450. {
  2451. return 0;
  2452. }
  2453. void efx_port_dummy_op_void(struct efx_nic *efx) {}
  2454. static bool efx_port_dummy_op_poll(struct efx_nic *efx)
  2455. {
  2456. return false;
  2457. }
  2458. static const struct efx_phy_operations efx_dummy_phy_operations = {
  2459. .init = efx_port_dummy_op_int,
  2460. .reconfigure = efx_port_dummy_op_int,
  2461. .poll = efx_port_dummy_op_poll,
  2462. .fini = efx_port_dummy_op_void,
  2463. };
  2464. /**************************************************************************
  2465. *
  2466. * Data housekeeping
  2467. *
  2468. **************************************************************************/
  2469. /* This zeroes out and then fills in the invariants in a struct
  2470. * efx_nic (including all sub-structures).
  2471. */
  2472. static int efx_init_struct(struct efx_nic *efx,
  2473. struct pci_dev *pci_dev, struct net_device *net_dev)
  2474. {
  2475. int rc = -ENOMEM, i;
  2476. /* Initialise common structures */
  2477. INIT_LIST_HEAD(&efx->node);
  2478. INIT_LIST_HEAD(&efx->secondary_list);
  2479. spin_lock_init(&efx->biu_lock);
  2480. #ifdef CONFIG_SFC_MTD
  2481. INIT_LIST_HEAD(&efx->mtd_list);
  2482. #endif
  2483. INIT_WORK(&efx->reset_work, efx_reset_work);
  2484. INIT_DELAYED_WORK(&efx->monitor_work, efx_monitor);
  2485. INIT_DELAYED_WORK(&efx->selftest_work, efx_selftest_async_work);
  2486. efx->pci_dev = pci_dev;
  2487. efx->msg_enable = debug;
  2488. efx->state = STATE_UNINIT;
  2489. strlcpy(efx->name, pci_name(pci_dev), sizeof(efx->name));
  2490. efx->net_dev = net_dev;
  2491. efx->rx_prefix_size = efx->type->rx_prefix_size;
  2492. efx->rx_ip_align =
  2493. NET_IP_ALIGN ? (efx->rx_prefix_size + NET_IP_ALIGN) % 4 : 0;
  2494. efx->rx_packet_hash_offset =
  2495. efx->type->rx_hash_offset - efx->type->rx_prefix_size;
  2496. efx->rx_packet_ts_offset =
  2497. efx->type->rx_ts_offset - efx->type->rx_prefix_size;
  2498. spin_lock_init(&efx->stats_lock);
  2499. mutex_init(&efx->mac_lock);
  2500. efx->phy_op = &efx_dummy_phy_operations;
  2501. efx->mdio.dev = net_dev;
  2502. INIT_WORK(&efx->mac_work, efx_mac_work);
  2503. init_waitqueue_head(&efx->flush_wq);
  2504. for (i = 0; i < EFX_MAX_CHANNELS; i++) {
  2505. efx->channel[i] = efx_alloc_channel(efx, i, NULL);
  2506. if (!efx->channel[i])
  2507. goto fail;
  2508. efx->msi_context[i].efx = efx;
  2509. efx->msi_context[i].index = i;
  2510. }
  2511. /* Higher numbered interrupt modes are less capable! */
  2512. if (WARN_ON_ONCE(efx->type->max_interrupt_mode >
  2513. efx->type->min_interrupt_mode)) {
  2514. rc = -EIO;
  2515. goto fail;
  2516. }
  2517. efx->interrupt_mode = max(efx->type->max_interrupt_mode,
  2518. interrupt_mode);
  2519. efx->interrupt_mode = min(efx->type->min_interrupt_mode,
  2520. interrupt_mode);
  2521. /* Would be good to use the net_dev name, but we're too early */
  2522. snprintf(efx->workqueue_name, sizeof(efx->workqueue_name), "sfc%s",
  2523. pci_name(pci_dev));
  2524. efx->workqueue = create_singlethread_workqueue(efx->workqueue_name);
  2525. if (!efx->workqueue)
  2526. goto fail;
  2527. return 0;
  2528. fail:
  2529. efx_fini_struct(efx);
  2530. return rc;
  2531. }
  2532. static void efx_fini_struct(struct efx_nic *efx)
  2533. {
  2534. int i;
  2535. for (i = 0; i < EFX_MAX_CHANNELS; i++)
  2536. kfree(efx->channel[i]);
  2537. kfree(efx->vpd_sn);
  2538. if (efx->workqueue) {
  2539. destroy_workqueue(efx->workqueue);
  2540. efx->workqueue = NULL;
  2541. }
  2542. }
  2543. void efx_update_sw_stats(struct efx_nic *efx, u64 *stats)
  2544. {
  2545. u64 n_rx_nodesc_trunc = 0;
  2546. struct efx_channel *channel;
  2547. efx_for_each_channel(channel, efx)
  2548. n_rx_nodesc_trunc += channel->n_rx_nodesc_trunc;
  2549. stats[GENERIC_STAT_rx_nodesc_trunc] = n_rx_nodesc_trunc;
  2550. stats[GENERIC_STAT_rx_noskb_drops] = atomic_read(&efx->n_rx_noskb_drops);
  2551. }
  2552. /**************************************************************************
  2553. *
  2554. * PCI interface
  2555. *
  2556. **************************************************************************/
  2557. /* Main body of final NIC shutdown code
  2558. * This is called only at module unload (or hotplug removal).
  2559. */
  2560. static void efx_pci_remove_main(struct efx_nic *efx)
  2561. {
  2562. /* Flush reset_work. It can no longer be scheduled since we
  2563. * are not READY.
  2564. */
  2565. BUG_ON(efx->state == STATE_READY);
  2566. cancel_work_sync(&efx->reset_work);
  2567. efx_disable_interrupts(efx);
  2568. efx_nic_fini_interrupt(efx);
  2569. efx_fini_port(efx);
  2570. efx->type->fini(efx);
  2571. efx_fini_napi(efx);
  2572. efx_remove_all(efx);
  2573. }
  2574. /* Final NIC shutdown
  2575. * This is called only at module unload (or hotplug removal). A PF can call
  2576. * this on its VFs to ensure they are unbound first.
  2577. */
  2578. static void efx_pci_remove(struct pci_dev *pci_dev)
  2579. {
  2580. struct efx_nic *efx;
  2581. efx = pci_get_drvdata(pci_dev);
  2582. if (!efx)
  2583. return;
  2584. /* Mark the NIC as fini, then stop the interface */
  2585. rtnl_lock();
  2586. efx_dissociate(efx);
  2587. dev_close(efx->net_dev);
  2588. efx_disable_interrupts(efx);
  2589. efx->state = STATE_UNINIT;
  2590. rtnl_unlock();
  2591. if (efx->type->sriov_fini)
  2592. efx->type->sriov_fini(efx);
  2593. efx_unregister_netdev(efx);
  2594. efx_mtd_remove(efx);
  2595. efx_pci_remove_main(efx);
  2596. efx_fini_io(efx);
  2597. netif_dbg(efx, drv, efx->net_dev, "shutdown successful\n");
  2598. efx_fini_struct(efx);
  2599. free_netdev(efx->net_dev);
  2600. pci_disable_pcie_error_reporting(pci_dev);
  2601. };
  2602. /* NIC VPD information
  2603. * Called during probe to display the part number of the
  2604. * installed NIC. VPD is potentially very large but this should
  2605. * always appear within the first 512 bytes.
  2606. */
  2607. #define SFC_VPD_LEN 512
  2608. static void efx_probe_vpd_strings(struct efx_nic *efx)
  2609. {
  2610. struct pci_dev *dev = efx->pci_dev;
  2611. char vpd_data[SFC_VPD_LEN];
  2612. ssize_t vpd_size;
  2613. int ro_start, ro_size, i, j;
  2614. /* Get the vpd data from the device */
  2615. vpd_size = pci_read_vpd(dev, 0, sizeof(vpd_data), vpd_data);
  2616. if (vpd_size <= 0) {
  2617. netif_err(efx, drv, efx->net_dev, "Unable to read VPD\n");
  2618. return;
  2619. }
  2620. /* Get the Read only section */
  2621. ro_start = pci_vpd_find_tag(vpd_data, 0, vpd_size, PCI_VPD_LRDT_RO_DATA);
  2622. if (ro_start < 0) {
  2623. netif_err(efx, drv, efx->net_dev, "VPD Read-only not found\n");
  2624. return;
  2625. }
  2626. ro_size = pci_vpd_lrdt_size(&vpd_data[ro_start]);
  2627. j = ro_size;
  2628. i = ro_start + PCI_VPD_LRDT_TAG_SIZE;
  2629. if (i + j > vpd_size)
  2630. j = vpd_size - i;
  2631. /* Get the Part number */
  2632. i = pci_vpd_find_info_keyword(vpd_data, i, j, "PN");
  2633. if (i < 0) {
  2634. netif_err(efx, drv, efx->net_dev, "Part number not found\n");
  2635. return;
  2636. }
  2637. j = pci_vpd_info_field_size(&vpd_data[i]);
  2638. i += PCI_VPD_INFO_FLD_HDR_SIZE;
  2639. if (i + j > vpd_size) {
  2640. netif_err(efx, drv, efx->net_dev, "Incomplete part number\n");
  2641. return;
  2642. }
  2643. netif_info(efx, drv, efx->net_dev,
  2644. "Part Number : %.*s\n", j, &vpd_data[i]);
  2645. i = ro_start + PCI_VPD_LRDT_TAG_SIZE;
  2646. j = ro_size;
  2647. i = pci_vpd_find_info_keyword(vpd_data, i, j, "SN");
  2648. if (i < 0) {
  2649. netif_err(efx, drv, efx->net_dev, "Serial number not found\n");
  2650. return;
  2651. }
  2652. j = pci_vpd_info_field_size(&vpd_data[i]);
  2653. i += PCI_VPD_INFO_FLD_HDR_SIZE;
  2654. if (i + j > vpd_size) {
  2655. netif_err(efx, drv, efx->net_dev, "Incomplete serial number\n");
  2656. return;
  2657. }
  2658. efx->vpd_sn = kmalloc(j + 1, GFP_KERNEL);
  2659. if (!efx->vpd_sn)
  2660. return;
  2661. snprintf(efx->vpd_sn, j + 1, "%s", &vpd_data[i]);
  2662. }
  2663. /* Main body of NIC initialisation
  2664. * This is called at module load (or hotplug insertion, theoretically).
  2665. */
  2666. static int efx_pci_probe_main(struct efx_nic *efx)
  2667. {
  2668. int rc;
  2669. /* Do start-of-day initialisation */
  2670. rc = efx_probe_all(efx);
  2671. if (rc)
  2672. goto fail1;
  2673. efx_init_napi(efx);
  2674. rc = efx->type->init(efx);
  2675. if (rc) {
  2676. netif_err(efx, probe, efx->net_dev,
  2677. "failed to initialise NIC\n");
  2678. goto fail3;
  2679. }
  2680. rc = efx_init_port(efx);
  2681. if (rc) {
  2682. netif_err(efx, probe, efx->net_dev,
  2683. "failed to initialise port\n");
  2684. goto fail4;
  2685. }
  2686. rc = efx_nic_init_interrupt(efx);
  2687. if (rc)
  2688. goto fail5;
  2689. rc = efx_enable_interrupts(efx);
  2690. if (rc)
  2691. goto fail6;
  2692. return 0;
  2693. fail6:
  2694. efx_nic_fini_interrupt(efx);
  2695. fail5:
  2696. efx_fini_port(efx);
  2697. fail4:
  2698. efx->type->fini(efx);
  2699. fail3:
  2700. efx_fini_napi(efx);
  2701. efx_remove_all(efx);
  2702. fail1:
  2703. return rc;
  2704. }
  2705. static int efx_pci_probe_post_io(struct efx_nic *efx)
  2706. {
  2707. struct net_device *net_dev = efx->net_dev;
  2708. int rc = efx_pci_probe_main(efx);
  2709. if (rc)
  2710. return rc;
  2711. if (efx->type->sriov_init) {
  2712. rc = efx->type->sriov_init(efx);
  2713. if (rc)
  2714. netif_err(efx, probe, efx->net_dev,
  2715. "SR-IOV can't be enabled rc %d\n", rc);
  2716. }
  2717. /* Determine netdevice features */
  2718. net_dev->features |= (efx->type->offload_features | NETIF_F_SG |
  2719. NETIF_F_TSO | NETIF_F_RXCSUM | NETIF_F_RXALL);
  2720. if (efx->type->offload_features & (NETIF_F_IPV6_CSUM | NETIF_F_HW_CSUM))
  2721. net_dev->features |= NETIF_F_TSO6;
  2722. /* Check whether device supports TSO */
  2723. if (!efx->type->tso_versions || !efx->type->tso_versions(efx))
  2724. net_dev->features &= ~NETIF_F_ALL_TSO;
  2725. /* Mask for features that also apply to VLAN devices */
  2726. net_dev->vlan_features |= (NETIF_F_HW_CSUM | NETIF_F_SG |
  2727. NETIF_F_HIGHDMA | NETIF_F_ALL_TSO |
  2728. NETIF_F_RXCSUM);
  2729. net_dev->hw_features |= net_dev->features & ~efx->fixed_features;
  2730. /* Disable receiving frames with bad FCS, by default. */
  2731. net_dev->features &= ~NETIF_F_RXALL;
  2732. /* Disable VLAN filtering by default. It may be enforced if
  2733. * the feature is fixed (i.e. VLAN filters are required to
  2734. * receive VLAN tagged packets due to vPort restrictions).
  2735. */
  2736. net_dev->features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
  2737. net_dev->features |= efx->fixed_features;
  2738. rc = efx_register_netdev(efx);
  2739. if (!rc)
  2740. return 0;
  2741. efx_pci_remove_main(efx);
  2742. return rc;
  2743. }
  2744. /* NIC initialisation
  2745. *
  2746. * This is called at module load (or hotplug insertion,
  2747. * theoretically). It sets up PCI mappings, resets the NIC,
  2748. * sets up and registers the network devices with the kernel and hooks
  2749. * the interrupt service routine. It does not prepare the device for
  2750. * transmission; this is left to the first time one of the network
  2751. * interfaces is brought up (i.e. efx_net_open).
  2752. */
  2753. static int efx_pci_probe(struct pci_dev *pci_dev,
  2754. const struct pci_device_id *entry)
  2755. {
  2756. struct net_device *net_dev;
  2757. struct efx_nic *efx;
  2758. int rc;
  2759. /* Allocate and initialise a struct net_device and struct efx_nic */
  2760. net_dev = alloc_etherdev_mqs(sizeof(*efx), EFX_MAX_CORE_TX_QUEUES,
  2761. EFX_MAX_RX_QUEUES);
  2762. if (!net_dev)
  2763. return -ENOMEM;
  2764. efx = netdev_priv(net_dev);
  2765. efx->type = (const struct efx_nic_type *) entry->driver_data;
  2766. efx->fixed_features |= NETIF_F_HIGHDMA;
  2767. pci_set_drvdata(pci_dev, efx);
  2768. SET_NETDEV_DEV(net_dev, &pci_dev->dev);
  2769. rc = efx_init_struct(efx, pci_dev, net_dev);
  2770. if (rc)
  2771. goto fail1;
  2772. netif_info(efx, probe, efx->net_dev,
  2773. "Solarflare NIC detected\n");
  2774. if (!efx->type->is_vf)
  2775. efx_probe_vpd_strings(efx);
  2776. /* Set up basic I/O (BAR mappings etc) */
  2777. rc = efx_init_io(efx);
  2778. if (rc)
  2779. goto fail2;
  2780. rc = efx_pci_probe_post_io(efx);
  2781. if (rc) {
  2782. /* On failure, retry once immediately.
  2783. * If we aborted probe due to a scheduled reset, dismiss it.
  2784. */
  2785. efx->reset_pending = 0;
  2786. rc = efx_pci_probe_post_io(efx);
  2787. if (rc) {
  2788. /* On another failure, retry once more
  2789. * after a 50-305ms delay.
  2790. */
  2791. unsigned char r;
  2792. get_random_bytes(&r, 1);
  2793. msleep((unsigned int)r + 50);
  2794. efx->reset_pending = 0;
  2795. rc = efx_pci_probe_post_io(efx);
  2796. }
  2797. }
  2798. if (rc)
  2799. goto fail3;
  2800. netif_dbg(efx, probe, efx->net_dev, "initialisation successful\n");
  2801. /* Try to create MTDs, but allow this to fail */
  2802. rtnl_lock();
  2803. rc = efx_mtd_probe(efx);
  2804. rtnl_unlock();
  2805. if (rc && rc != -EPERM)
  2806. netif_warn(efx, probe, efx->net_dev,
  2807. "failed to create MTDs (%d)\n", rc);
  2808. rc = pci_enable_pcie_error_reporting(pci_dev);
  2809. if (rc && rc != -EINVAL)
  2810. netif_notice(efx, probe, efx->net_dev,
  2811. "PCIE error reporting unavailable (%d).\n",
  2812. rc);
  2813. if (efx->type->udp_tnl_push_ports)
  2814. efx->type->udp_tnl_push_ports(efx);
  2815. return 0;
  2816. fail3:
  2817. efx_fini_io(efx);
  2818. fail2:
  2819. efx_fini_struct(efx);
  2820. fail1:
  2821. WARN_ON(rc > 0);
  2822. netif_dbg(efx, drv, efx->net_dev, "initialisation failed. rc=%d\n", rc);
  2823. free_netdev(net_dev);
  2824. return rc;
  2825. }
  2826. /* efx_pci_sriov_configure returns the actual number of Virtual Functions
  2827. * enabled on success
  2828. */
  2829. #ifdef CONFIG_SFC_SRIOV
  2830. static int efx_pci_sriov_configure(struct pci_dev *dev, int num_vfs)
  2831. {
  2832. int rc;
  2833. struct efx_nic *efx = pci_get_drvdata(dev);
  2834. if (efx->type->sriov_configure) {
  2835. rc = efx->type->sriov_configure(efx, num_vfs);
  2836. if (rc)
  2837. return rc;
  2838. else
  2839. return num_vfs;
  2840. } else
  2841. return -EOPNOTSUPP;
  2842. }
  2843. #endif
  2844. static int efx_pm_freeze(struct device *dev)
  2845. {
  2846. struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
  2847. rtnl_lock();
  2848. if (efx->state != STATE_DISABLED) {
  2849. efx->state = STATE_UNINIT;
  2850. efx_device_detach_sync(efx);
  2851. efx_stop_all(efx);
  2852. efx_disable_interrupts(efx);
  2853. }
  2854. rtnl_unlock();
  2855. return 0;
  2856. }
  2857. static int efx_pm_thaw(struct device *dev)
  2858. {
  2859. int rc;
  2860. struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
  2861. rtnl_lock();
  2862. if (efx->state != STATE_DISABLED) {
  2863. rc = efx_enable_interrupts(efx);
  2864. if (rc)
  2865. goto fail;
  2866. mutex_lock(&efx->mac_lock);
  2867. efx->phy_op->reconfigure(efx);
  2868. mutex_unlock(&efx->mac_lock);
  2869. efx_start_all(efx);
  2870. efx_device_attach_if_not_resetting(efx);
  2871. efx->state = STATE_READY;
  2872. efx->type->resume_wol(efx);
  2873. }
  2874. rtnl_unlock();
  2875. /* Reschedule any quenched resets scheduled during efx_pm_freeze() */
  2876. queue_work(reset_workqueue, &efx->reset_work);
  2877. return 0;
  2878. fail:
  2879. rtnl_unlock();
  2880. return rc;
  2881. }
  2882. static int efx_pm_poweroff(struct device *dev)
  2883. {
  2884. struct pci_dev *pci_dev = to_pci_dev(dev);
  2885. struct efx_nic *efx = pci_get_drvdata(pci_dev);
  2886. efx->type->fini(efx);
  2887. efx->reset_pending = 0;
  2888. pci_save_state(pci_dev);
  2889. return pci_set_power_state(pci_dev, PCI_D3hot);
  2890. }
  2891. /* Used for both resume and restore */
  2892. static int efx_pm_resume(struct device *dev)
  2893. {
  2894. struct pci_dev *pci_dev = to_pci_dev(dev);
  2895. struct efx_nic *efx = pci_get_drvdata(pci_dev);
  2896. int rc;
  2897. rc = pci_set_power_state(pci_dev, PCI_D0);
  2898. if (rc)
  2899. return rc;
  2900. pci_restore_state(pci_dev);
  2901. rc = pci_enable_device(pci_dev);
  2902. if (rc)
  2903. return rc;
  2904. pci_set_master(efx->pci_dev);
  2905. rc = efx->type->reset(efx, RESET_TYPE_ALL);
  2906. if (rc)
  2907. return rc;
  2908. rc = efx->type->init(efx);
  2909. if (rc)
  2910. return rc;
  2911. rc = efx_pm_thaw(dev);
  2912. return rc;
  2913. }
  2914. static int efx_pm_suspend(struct device *dev)
  2915. {
  2916. int rc;
  2917. efx_pm_freeze(dev);
  2918. rc = efx_pm_poweroff(dev);
  2919. if (rc)
  2920. efx_pm_resume(dev);
  2921. return rc;
  2922. }
  2923. static const struct dev_pm_ops efx_pm_ops = {
  2924. .suspend = efx_pm_suspend,
  2925. .resume = efx_pm_resume,
  2926. .freeze = efx_pm_freeze,
  2927. .thaw = efx_pm_thaw,
  2928. .poweroff = efx_pm_poweroff,
  2929. .restore = efx_pm_resume,
  2930. };
  2931. /* A PCI error affecting this device was detected.
  2932. * At this point MMIO and DMA may be disabled.
  2933. * Stop the software path and request a slot reset.
  2934. */
  2935. static pci_ers_result_t efx_io_error_detected(struct pci_dev *pdev,
  2936. enum pci_channel_state state)
  2937. {
  2938. pci_ers_result_t status = PCI_ERS_RESULT_RECOVERED;
  2939. struct efx_nic *efx = pci_get_drvdata(pdev);
  2940. if (state == pci_channel_io_perm_failure)
  2941. return PCI_ERS_RESULT_DISCONNECT;
  2942. rtnl_lock();
  2943. if (efx->state != STATE_DISABLED) {
  2944. efx->state = STATE_RECOVERY;
  2945. efx->reset_pending = 0;
  2946. efx_device_detach_sync(efx);
  2947. efx_stop_all(efx);
  2948. efx_disable_interrupts(efx);
  2949. status = PCI_ERS_RESULT_NEED_RESET;
  2950. } else {
  2951. /* If the interface is disabled we don't want to do anything
  2952. * with it.
  2953. */
  2954. status = PCI_ERS_RESULT_RECOVERED;
  2955. }
  2956. rtnl_unlock();
  2957. pci_disable_device(pdev);
  2958. return status;
  2959. }
  2960. /* Fake a successful reset, which will be performed later in efx_io_resume. */
  2961. static pci_ers_result_t efx_io_slot_reset(struct pci_dev *pdev)
  2962. {
  2963. struct efx_nic *efx = pci_get_drvdata(pdev);
  2964. pci_ers_result_t status = PCI_ERS_RESULT_RECOVERED;
  2965. int rc;
  2966. if (pci_enable_device(pdev)) {
  2967. netif_err(efx, hw, efx->net_dev,
  2968. "Cannot re-enable PCI device after reset.\n");
  2969. status = PCI_ERS_RESULT_DISCONNECT;
  2970. }
  2971. rc = pci_cleanup_aer_uncorrect_error_status(pdev);
  2972. if (rc) {
  2973. netif_err(efx, hw, efx->net_dev,
  2974. "pci_cleanup_aer_uncorrect_error_status failed (%d)\n", rc);
  2975. /* Non-fatal error. Continue. */
  2976. }
  2977. return status;
  2978. }
  2979. /* Perform the actual reset and resume I/O operations. */
  2980. static void efx_io_resume(struct pci_dev *pdev)
  2981. {
  2982. struct efx_nic *efx = pci_get_drvdata(pdev);
  2983. int rc;
  2984. rtnl_lock();
  2985. if (efx->state == STATE_DISABLED)
  2986. goto out;
  2987. rc = efx_reset(efx, RESET_TYPE_ALL);
  2988. if (rc) {
  2989. netif_err(efx, hw, efx->net_dev,
  2990. "efx_reset failed after PCI error (%d)\n", rc);
  2991. } else {
  2992. efx->state = STATE_READY;
  2993. netif_dbg(efx, hw, efx->net_dev,
  2994. "Done resetting and resuming IO after PCI error.\n");
  2995. }
  2996. out:
  2997. rtnl_unlock();
  2998. }
  2999. /* For simplicity and reliability, we always require a slot reset and try to
  3000. * reset the hardware when a pci error affecting the device is detected.
  3001. * We leave both the link_reset and mmio_enabled callback unimplemented:
  3002. * with our request for slot reset the mmio_enabled callback will never be
  3003. * called, and the link_reset callback is not used by AER or EEH mechanisms.
  3004. */
  3005. static const struct pci_error_handlers efx_err_handlers = {
  3006. .error_detected = efx_io_error_detected,
  3007. .slot_reset = efx_io_slot_reset,
  3008. .resume = efx_io_resume,
  3009. };
  3010. static struct pci_driver efx_pci_driver = {
  3011. .name = KBUILD_MODNAME,
  3012. .id_table = efx_pci_table,
  3013. .probe = efx_pci_probe,
  3014. .remove = efx_pci_remove,
  3015. .driver.pm = &efx_pm_ops,
  3016. .err_handler = &efx_err_handlers,
  3017. #ifdef CONFIG_SFC_SRIOV
  3018. .sriov_configure = efx_pci_sriov_configure,
  3019. #endif
  3020. };
  3021. /**************************************************************************
  3022. *
  3023. * Kernel module interface
  3024. *
  3025. *************************************************************************/
  3026. module_param(interrupt_mode, uint, 0444);
  3027. MODULE_PARM_DESC(interrupt_mode,
  3028. "Interrupt mode (0=>MSIX 1=>MSI 2=>legacy)");
  3029. static int __init efx_init_module(void)
  3030. {
  3031. int rc;
  3032. printk(KERN_INFO "Solarflare NET driver v" EFX_DRIVER_VERSION "\n");
  3033. rc = register_netdevice_notifier(&efx_netdev_notifier);
  3034. if (rc)
  3035. goto err_notifier;
  3036. #ifdef CONFIG_SFC_SRIOV
  3037. rc = efx_init_sriov();
  3038. if (rc)
  3039. goto err_sriov;
  3040. #endif
  3041. reset_workqueue = create_singlethread_workqueue("sfc_reset");
  3042. if (!reset_workqueue) {
  3043. rc = -ENOMEM;
  3044. goto err_reset;
  3045. }
  3046. rc = pci_register_driver(&efx_pci_driver);
  3047. if (rc < 0)
  3048. goto err_pci;
  3049. return 0;
  3050. err_pci:
  3051. destroy_workqueue(reset_workqueue);
  3052. err_reset:
  3053. #ifdef CONFIG_SFC_SRIOV
  3054. efx_fini_sriov();
  3055. err_sriov:
  3056. #endif
  3057. unregister_netdevice_notifier(&efx_netdev_notifier);
  3058. err_notifier:
  3059. return rc;
  3060. }
  3061. static void __exit efx_exit_module(void)
  3062. {
  3063. printk(KERN_INFO "Solarflare NET driver unloading\n");
  3064. pci_unregister_driver(&efx_pci_driver);
  3065. destroy_workqueue(reset_workqueue);
  3066. #ifdef CONFIG_SFC_SRIOV
  3067. efx_fini_sriov();
  3068. #endif
  3069. unregister_netdevice_notifier(&efx_netdev_notifier);
  3070. }
  3071. module_init(efx_init_module);
  3072. module_exit(efx_exit_module);
  3073. MODULE_AUTHOR("Solarflare Communications and "
  3074. "Michael Brown <mbrown@fensystems.co.uk>");
  3075. MODULE_DESCRIPTION("Solarflare network driver");
  3076. MODULE_LICENSE("GPL");
  3077. MODULE_DEVICE_TABLE(pci, efx_pci_table);
  3078. MODULE_VERSION(EFX_DRIVER_VERSION);