efx.c 81 KB

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