efx.c 79 KB

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