efx.c 80 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095
  1. /****************************************************************************
  2. * Driver for Solarflare Solarstorm network controllers and boards
  3. * Copyright 2005-2006 Fen Systems Ltd.
  4. * Copyright 2005-2011 Solarflare Communications Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published
  8. * by the Free Software Foundation, incorporated herein by reference.
  9. */
  10. #include <linux/module.h>
  11. #include <linux/pci.h>
  12. #include <linux/netdevice.h>
  13. #include <linux/etherdevice.h>
  14. #include <linux/delay.h>
  15. #include <linux/notifier.h>
  16. #include <linux/ip.h>
  17. #include <linux/tcp.h>
  18. #include <linux/in.h>
  19. #include <linux/crc32.h>
  20. #include <linux/ethtool.h>
  21. #include <linux/topology.h>
  22. #include <linux/gfp.h>
  23. #include <linux/aer.h>
  24. #include <linux/interrupt.h>
  25. #include "net_driver.h"
  26. #include "efx.h"
  27. #include "nic.h"
  28. #include "selftest.h"
  29. #include "mcdi.h"
  30. #include "workarounds.h"
  31. /**************************************************************************
  32. *
  33. * Type name strings
  34. *
  35. **************************************************************************
  36. */
  37. /* Loopback mode names (see LOOPBACK_MODE()) */
  38. const unsigned int efx_loopback_mode_max = LOOPBACK_MAX;
  39. const char *const efx_loopback_mode_names[] = {
  40. [LOOPBACK_NONE] = "NONE",
  41. [LOOPBACK_DATA] = "DATAPATH",
  42. [LOOPBACK_GMAC] = "GMAC",
  43. [LOOPBACK_XGMII] = "XGMII",
  44. [LOOPBACK_XGXS] = "XGXS",
  45. [LOOPBACK_XAUI] = "XAUI",
  46. [LOOPBACK_GMII] = "GMII",
  47. [LOOPBACK_SGMII] = "SGMII",
  48. [LOOPBACK_XGBR] = "XGBR",
  49. [LOOPBACK_XFI] = "XFI",
  50. [LOOPBACK_XAUI_FAR] = "XAUI_FAR",
  51. [LOOPBACK_GMII_FAR] = "GMII_FAR",
  52. [LOOPBACK_SGMII_FAR] = "SGMII_FAR",
  53. [LOOPBACK_XFI_FAR] = "XFI_FAR",
  54. [LOOPBACK_GPHY] = "GPHY",
  55. [LOOPBACK_PHYXS] = "PHYXS",
  56. [LOOPBACK_PCS] = "PCS",
  57. [LOOPBACK_PMAPMD] = "PMA/PMD",
  58. [LOOPBACK_XPORT] = "XPORT",
  59. [LOOPBACK_XGMII_WS] = "XGMII_WS",
  60. [LOOPBACK_XAUI_WS] = "XAUI_WS",
  61. [LOOPBACK_XAUI_WS_FAR] = "XAUI_WS_FAR",
  62. [LOOPBACK_XAUI_WS_NEAR] = "XAUI_WS_NEAR",
  63. [LOOPBACK_GMII_WS] = "GMII_WS",
  64. [LOOPBACK_XFI_WS] = "XFI_WS",
  65. [LOOPBACK_XFI_WS_FAR] = "XFI_WS_FAR",
  66. [LOOPBACK_PHYXS_WS] = "PHYXS_WS",
  67. };
  68. const unsigned int efx_reset_type_max = RESET_TYPE_MAX;
  69. const char *const efx_reset_type_names[] = {
  70. [RESET_TYPE_INVISIBLE] = "INVISIBLE",
  71. [RESET_TYPE_ALL] = "ALL",
  72. [RESET_TYPE_RECOVER_OR_ALL] = "RECOVER_OR_ALL",
  73. [RESET_TYPE_WORLD] = "WORLD",
  74. [RESET_TYPE_RECOVER_OR_DISABLE] = "RECOVER_OR_DISABLE",
  75. [RESET_TYPE_DISABLE] = "DISABLE",
  76. [RESET_TYPE_TX_WATCHDOG] = "TX_WATCHDOG",
  77. [RESET_TYPE_INT_ERROR] = "INT_ERROR",
  78. [RESET_TYPE_RX_RECOVERY] = "RX_RECOVERY",
  79. [RESET_TYPE_RX_DESC_FETCH] = "RX_DESC_FETCH",
  80. [RESET_TYPE_TX_DESC_FETCH] = "TX_DESC_FETCH",
  81. [RESET_TYPE_TX_SKIP] = "TX_SKIP",
  82. [RESET_TYPE_MC_FAILURE] = "MC_FAILURE",
  83. };
  84. /* Reset workqueue. If any NIC has a hardware failure then a reset will be
  85. * queued onto this work queue. This is not a per-nic work queue, because
  86. * efx_reset_work() acquires the rtnl lock, so resets are naturally serialised.
  87. */
  88. static struct workqueue_struct *reset_workqueue;
  89. /**************************************************************************
  90. *
  91. * Configurable values
  92. *
  93. *************************************************************************/
  94. /*
  95. * Use separate channels for TX and RX events
  96. *
  97. * Set this to 1 to use separate channels for TX and RX. It allows us
  98. * to control interrupt affinity separately for TX and RX.
  99. *
  100. * This is only used in MSI-X interrupt mode
  101. */
  102. static bool separate_tx_channels;
  103. module_param(separate_tx_channels, bool, 0444);
  104. MODULE_PARM_DESC(separate_tx_channels,
  105. "Use separate channels for TX and RX");
  106. /* This is the weight assigned to each of the (per-channel) virtual
  107. * NAPI devices.
  108. */
  109. static int napi_weight = 64;
  110. /* This is the time (in jiffies) between invocations of the hardware
  111. * monitor.
  112. * On Falcon-based NICs, this will:
  113. * - Check the on-board hardware monitor;
  114. * - Poll the link state and reconfigure the hardware as necessary.
  115. * On Siena-based NICs for power systems with EEH support, this will give EEH a
  116. * chance to start.
  117. */
  118. static unsigned int efx_monitor_interval = 1 * HZ;
  119. /* Initial interrupt moderation settings. They can be modified after
  120. * module load with ethtool.
  121. *
  122. * The default for RX should strike a balance between increasing the
  123. * round-trip latency and reducing overhead.
  124. */
  125. static unsigned int rx_irq_mod_usec = 60;
  126. /* Initial interrupt moderation settings. They can be modified after
  127. * module load with ethtool.
  128. *
  129. * This default is chosen to ensure that a 10G link does not go idle
  130. * while a TX queue is stopped after it has become full. A queue is
  131. * restarted when it drops below half full. The time this takes (assuming
  132. * worst case 3 descriptors per packet and 1024 descriptors) is
  133. * 512 / 3 * 1.2 = 205 usec.
  134. */
  135. static unsigned int tx_irq_mod_usec = 150;
  136. /* This is the first interrupt mode to try out of:
  137. * 0 => MSI-X
  138. * 1 => MSI
  139. * 2 => legacy
  140. */
  141. static unsigned int interrupt_mode;
  142. /* This is the requested number of CPUs to use for Receive-Side Scaling (RSS),
  143. * i.e. the number of CPUs among which we may distribute simultaneous
  144. * interrupt handling.
  145. *
  146. * Cards without MSI-X will only target one CPU via legacy or MSI interrupt.
  147. * The default (0) means to assign an interrupt to each core.
  148. */
  149. static unsigned int rss_cpus;
  150. module_param(rss_cpus, uint, 0444);
  151. MODULE_PARM_DESC(rss_cpus, "Number of CPUs to use for Receive-Side Scaling");
  152. static bool phy_flash_cfg;
  153. module_param(phy_flash_cfg, bool, 0644);
  154. MODULE_PARM_DESC(phy_flash_cfg, "Set PHYs into reflash mode initially");
  155. static unsigned irq_adapt_low_thresh = 8000;
  156. module_param(irq_adapt_low_thresh, uint, 0644);
  157. MODULE_PARM_DESC(irq_adapt_low_thresh,
  158. "Threshold score for reducing IRQ moderation");
  159. static unsigned irq_adapt_high_thresh = 16000;
  160. module_param(irq_adapt_high_thresh, uint, 0644);
  161. MODULE_PARM_DESC(irq_adapt_high_thresh,
  162. "Threshold score for increasing IRQ moderation");
  163. static unsigned debug = (NETIF_MSG_DRV | NETIF_MSG_PROBE |
  164. NETIF_MSG_LINK | NETIF_MSG_IFDOWN |
  165. NETIF_MSG_IFUP | NETIF_MSG_RX_ERR |
  166. NETIF_MSG_TX_ERR | NETIF_MSG_HW);
  167. module_param(debug, uint, 0);
  168. MODULE_PARM_DESC(debug, "Bitmapped debugging message enable value");
  169. /**************************************************************************
  170. *
  171. * Utility functions and prototypes
  172. *
  173. *************************************************************************/
  174. static void efx_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. /* Probe the number and type of interrupts we are able to obtain, and
  1089. * the resulting numbers of channels and RX queues.
  1090. */
  1091. static int efx_probe_interrupts(struct efx_nic *efx)
  1092. {
  1093. unsigned int max_channels =
  1094. min(efx->type->phys_addr_channels, EFX_MAX_CHANNELS);
  1095. unsigned int extra_channels = 0;
  1096. unsigned int i, j;
  1097. int rc;
  1098. for (i = 0; i < EFX_MAX_EXTRA_CHANNELS; i++)
  1099. if (efx->extra_channel_type[i])
  1100. ++extra_channels;
  1101. if (efx->interrupt_mode == EFX_INT_MODE_MSIX) {
  1102. struct msix_entry xentries[EFX_MAX_CHANNELS];
  1103. unsigned int n_channels;
  1104. n_channels = efx_wanted_parallelism(efx);
  1105. if (separate_tx_channels)
  1106. n_channels *= 2;
  1107. n_channels += extra_channels;
  1108. n_channels = min(n_channels, max_channels);
  1109. for (i = 0; i < n_channels; i++)
  1110. xentries[i].entry = i;
  1111. rc = pci_enable_msix(efx->pci_dev, xentries, n_channels);
  1112. if (rc > 0) {
  1113. netif_err(efx, drv, efx->net_dev,
  1114. "WARNING: Insufficient MSI-X vectors"
  1115. " available (%d < %u).\n", rc, n_channels);
  1116. netif_err(efx, drv, efx->net_dev,
  1117. "WARNING: Performance may be reduced.\n");
  1118. EFX_BUG_ON_PARANOID(rc >= n_channels);
  1119. n_channels = rc;
  1120. rc = pci_enable_msix(efx->pci_dev, xentries,
  1121. n_channels);
  1122. }
  1123. if (rc == 0) {
  1124. efx->n_channels = n_channels;
  1125. if (n_channels > extra_channels)
  1126. n_channels -= extra_channels;
  1127. if (separate_tx_channels) {
  1128. efx->n_tx_channels = max(n_channels / 2, 1U);
  1129. efx->n_rx_channels = max(n_channels -
  1130. efx->n_tx_channels,
  1131. 1U);
  1132. } else {
  1133. efx->n_tx_channels = n_channels;
  1134. efx->n_rx_channels = n_channels;
  1135. }
  1136. for (i = 0; i < efx->n_channels; i++)
  1137. efx_get_channel(efx, i)->irq =
  1138. xentries[i].vector;
  1139. } else {
  1140. /* Fall back to single channel MSI */
  1141. efx->interrupt_mode = EFX_INT_MODE_MSI;
  1142. netif_err(efx, drv, efx->net_dev,
  1143. "could not enable MSI-X\n");
  1144. }
  1145. }
  1146. /* Try single interrupt MSI */
  1147. if (efx->interrupt_mode == EFX_INT_MODE_MSI) {
  1148. efx->n_channels = 1;
  1149. efx->n_rx_channels = 1;
  1150. efx->n_tx_channels = 1;
  1151. rc = pci_enable_msi(efx->pci_dev);
  1152. if (rc == 0) {
  1153. efx_get_channel(efx, 0)->irq = efx->pci_dev->irq;
  1154. } else {
  1155. netif_err(efx, drv, efx->net_dev,
  1156. "could not enable MSI\n");
  1157. efx->interrupt_mode = EFX_INT_MODE_LEGACY;
  1158. }
  1159. }
  1160. /* Assume legacy interrupts */
  1161. if (efx->interrupt_mode == EFX_INT_MODE_LEGACY) {
  1162. efx->n_channels = 1 + (separate_tx_channels ? 1 : 0);
  1163. efx->n_rx_channels = 1;
  1164. efx->n_tx_channels = 1;
  1165. efx->legacy_irq = efx->pci_dev->irq;
  1166. }
  1167. /* Assign extra channels if possible */
  1168. j = efx->n_channels;
  1169. for (i = 0; i < EFX_MAX_EXTRA_CHANNELS; i++) {
  1170. if (!efx->extra_channel_type[i])
  1171. continue;
  1172. if (efx->interrupt_mode != EFX_INT_MODE_MSIX ||
  1173. efx->n_channels <= extra_channels) {
  1174. efx->extra_channel_type[i]->handle_no_channel(efx);
  1175. } else {
  1176. --j;
  1177. efx_get_channel(efx, j)->type =
  1178. efx->extra_channel_type[i];
  1179. }
  1180. }
  1181. /* RSS might be usable on VFs even if it is disabled on the PF */
  1182. efx->rss_spread = ((efx->n_rx_channels > 1 || !efx_sriov_wanted(efx)) ?
  1183. efx->n_rx_channels : efx_vf_size(efx));
  1184. return 0;
  1185. }
  1186. /* Enable interrupts, then probe and start the event queues */
  1187. static void efx_start_interrupts(struct efx_nic *efx, bool may_keep_eventq)
  1188. {
  1189. struct efx_channel *channel;
  1190. BUG_ON(efx->state == STATE_DISABLED);
  1191. if (efx->eeh_disabled_legacy_irq) {
  1192. enable_irq(efx->legacy_irq);
  1193. efx->eeh_disabled_legacy_irq = false;
  1194. }
  1195. if (efx->legacy_irq)
  1196. efx->legacy_irq_enabled = true;
  1197. efx_nic_enable_interrupts(efx);
  1198. efx_for_each_channel(channel, efx) {
  1199. if (!channel->type->keep_eventq || !may_keep_eventq)
  1200. efx_init_eventq(channel);
  1201. efx_start_eventq(channel);
  1202. }
  1203. efx_mcdi_mode_event(efx);
  1204. }
  1205. static void efx_stop_interrupts(struct efx_nic *efx, bool may_keep_eventq)
  1206. {
  1207. struct efx_channel *channel;
  1208. if (efx->state == STATE_DISABLED)
  1209. return;
  1210. efx_mcdi_mode_poll(efx);
  1211. efx_nic_disable_interrupts(efx);
  1212. if (efx->legacy_irq) {
  1213. synchronize_irq(efx->legacy_irq);
  1214. efx->legacy_irq_enabled = false;
  1215. }
  1216. efx_for_each_channel(channel, efx) {
  1217. if (channel->irq)
  1218. synchronize_irq(channel->irq);
  1219. efx_stop_eventq(channel);
  1220. if (!channel->type->keep_eventq || !may_keep_eventq)
  1221. efx_fini_eventq(channel);
  1222. }
  1223. }
  1224. static void efx_remove_interrupts(struct efx_nic *efx)
  1225. {
  1226. struct efx_channel *channel;
  1227. /* Remove MSI/MSI-X interrupts */
  1228. efx_for_each_channel(channel, efx)
  1229. channel->irq = 0;
  1230. pci_disable_msi(efx->pci_dev);
  1231. pci_disable_msix(efx->pci_dev);
  1232. /* Remove legacy interrupt */
  1233. efx->legacy_irq = 0;
  1234. }
  1235. static void efx_set_channels(struct efx_nic *efx)
  1236. {
  1237. struct efx_channel *channel;
  1238. struct efx_tx_queue *tx_queue;
  1239. efx->tx_channel_offset =
  1240. separate_tx_channels ? efx->n_channels - efx->n_tx_channels : 0;
  1241. /* We need to mark which channels really have RX and TX
  1242. * queues, and adjust the TX queue numbers if we have separate
  1243. * RX-only and TX-only channels.
  1244. */
  1245. efx_for_each_channel(channel, efx) {
  1246. if (channel->channel < efx->n_rx_channels)
  1247. channel->rx_queue.core_index = channel->channel;
  1248. else
  1249. channel->rx_queue.core_index = -1;
  1250. efx_for_each_channel_tx_queue(tx_queue, channel)
  1251. tx_queue->queue -= (efx->tx_channel_offset *
  1252. EFX_TXQ_TYPES);
  1253. }
  1254. }
  1255. static int efx_probe_nic(struct efx_nic *efx)
  1256. {
  1257. size_t i;
  1258. int rc;
  1259. netif_dbg(efx, probe, efx->net_dev, "creating NIC\n");
  1260. /* Carry out hardware-type specific initialisation */
  1261. rc = efx->type->probe(efx);
  1262. if (rc)
  1263. return rc;
  1264. /* Determine the number of channels and queues by trying to hook
  1265. * in MSI-X interrupts. */
  1266. rc = efx_probe_interrupts(efx);
  1267. if (rc)
  1268. goto fail;
  1269. efx->type->dimension_resources(efx);
  1270. if (efx->n_channels > 1)
  1271. get_random_bytes(&efx->rx_hash_key, sizeof(efx->rx_hash_key));
  1272. for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); i++)
  1273. efx->rx_indir_table[i] =
  1274. ethtool_rxfh_indir_default(i, efx->rss_spread);
  1275. efx_set_channels(efx);
  1276. netif_set_real_num_tx_queues(efx->net_dev, efx->n_tx_channels);
  1277. netif_set_real_num_rx_queues(efx->net_dev, efx->n_rx_channels);
  1278. /* Initialise the interrupt moderation settings */
  1279. efx_init_irq_moderation(efx, tx_irq_mod_usec, rx_irq_mod_usec, true,
  1280. true);
  1281. return 0;
  1282. fail:
  1283. efx->type->remove(efx);
  1284. return rc;
  1285. }
  1286. static void efx_remove_nic(struct efx_nic *efx)
  1287. {
  1288. netif_dbg(efx, drv, efx->net_dev, "destroying NIC\n");
  1289. efx_remove_interrupts(efx);
  1290. efx->type->remove(efx);
  1291. }
  1292. /**************************************************************************
  1293. *
  1294. * NIC startup/shutdown
  1295. *
  1296. *************************************************************************/
  1297. static int efx_probe_all(struct efx_nic *efx)
  1298. {
  1299. int rc;
  1300. rc = efx_probe_nic(efx);
  1301. if (rc) {
  1302. netif_err(efx, probe, efx->net_dev, "failed to create NIC\n");
  1303. goto fail1;
  1304. }
  1305. rc = efx_probe_port(efx);
  1306. if (rc) {
  1307. netif_err(efx, probe, efx->net_dev, "failed to create port\n");
  1308. goto fail2;
  1309. }
  1310. BUILD_BUG_ON(EFX_DEFAULT_DMAQ_SIZE < EFX_RXQ_MIN_ENT);
  1311. if (WARN_ON(EFX_DEFAULT_DMAQ_SIZE < EFX_TXQ_MIN_ENT(efx))) {
  1312. rc = -EINVAL;
  1313. goto fail3;
  1314. }
  1315. efx->rxq_entries = efx->txq_entries = EFX_DEFAULT_DMAQ_SIZE;
  1316. rc = efx_probe_filters(efx);
  1317. if (rc) {
  1318. netif_err(efx, probe, efx->net_dev,
  1319. "failed to create filter tables\n");
  1320. goto fail3;
  1321. }
  1322. rc = efx_probe_channels(efx);
  1323. if (rc)
  1324. goto fail4;
  1325. return 0;
  1326. fail4:
  1327. efx_remove_filters(efx);
  1328. fail3:
  1329. efx_remove_port(efx);
  1330. fail2:
  1331. efx_remove_nic(efx);
  1332. fail1:
  1333. return rc;
  1334. }
  1335. /* If the interface is supposed to be running but is not, start
  1336. * the hardware and software data path, regular activity for the port
  1337. * (MAC statistics, link polling, etc.) and schedule the port to be
  1338. * reconfigured. Interrupts must already be enabled. This function
  1339. * is safe to call multiple times, so long as the NIC is not disabled.
  1340. * Requires the RTNL lock.
  1341. */
  1342. static void efx_start_all(struct efx_nic *efx)
  1343. {
  1344. EFX_ASSERT_RESET_SERIALISED(efx);
  1345. BUG_ON(efx->state == STATE_DISABLED);
  1346. /* Check that it is appropriate to restart the interface. All
  1347. * of these flags are safe to read under just the rtnl lock */
  1348. if (efx->port_enabled || !netif_running(efx->net_dev))
  1349. return;
  1350. efx_start_port(efx);
  1351. efx_start_datapath(efx);
  1352. /* Start the hardware monitor if there is one */
  1353. if (efx->type->monitor != NULL)
  1354. queue_delayed_work(efx->workqueue, &efx->monitor_work,
  1355. efx_monitor_interval);
  1356. /* If link state detection is normally event-driven, we have
  1357. * to poll now because we could have missed a change
  1358. */
  1359. if (efx_nic_rev(efx) >= EFX_REV_SIENA_A0) {
  1360. mutex_lock(&efx->mac_lock);
  1361. if (efx->phy_op->poll(efx))
  1362. efx_link_status_changed(efx);
  1363. mutex_unlock(&efx->mac_lock);
  1364. }
  1365. efx->type->start_stats(efx);
  1366. }
  1367. /* Flush all delayed work. Should only be called when no more delayed work
  1368. * will be scheduled. This doesn't flush pending online resets (efx_reset),
  1369. * since we're holding the rtnl_lock at this point. */
  1370. static void efx_flush_all(struct efx_nic *efx)
  1371. {
  1372. /* Make sure the hardware monitor and event self-test are stopped */
  1373. cancel_delayed_work_sync(&efx->monitor_work);
  1374. efx_selftest_async_cancel(efx);
  1375. /* Stop scheduled port reconfigurations */
  1376. cancel_work_sync(&efx->mac_work);
  1377. }
  1378. /* Quiesce the hardware and software data path, and regular activity
  1379. * for the port without bringing the link down. Safe to call multiple
  1380. * times with the NIC in almost any state, but interrupts should be
  1381. * enabled. Requires the RTNL lock.
  1382. */
  1383. static void efx_stop_all(struct efx_nic *efx)
  1384. {
  1385. EFX_ASSERT_RESET_SERIALISED(efx);
  1386. /* port_enabled can be read safely under the rtnl lock */
  1387. if (!efx->port_enabled)
  1388. return;
  1389. efx->type->stop_stats(efx);
  1390. efx_stop_port(efx);
  1391. /* Flush efx_mac_work(), refill_workqueue, monitor_work */
  1392. efx_flush_all(efx);
  1393. /* Stop the kernel transmit interface. This is only valid if
  1394. * the device is stopped or detached; otherwise the watchdog
  1395. * may fire immediately.
  1396. */
  1397. WARN_ON(netif_running(efx->net_dev) &&
  1398. netif_device_present(efx->net_dev));
  1399. netif_tx_disable(efx->net_dev);
  1400. efx_stop_datapath(efx);
  1401. }
  1402. static void efx_remove_all(struct efx_nic *efx)
  1403. {
  1404. efx_remove_channels(efx);
  1405. efx_remove_filters(efx);
  1406. efx_remove_port(efx);
  1407. efx_remove_nic(efx);
  1408. }
  1409. /**************************************************************************
  1410. *
  1411. * Interrupt moderation
  1412. *
  1413. **************************************************************************/
  1414. static unsigned int irq_mod_ticks(unsigned int usecs, unsigned int quantum_ns)
  1415. {
  1416. if (usecs == 0)
  1417. return 0;
  1418. if (usecs * 1000 < quantum_ns)
  1419. return 1; /* never round down to 0 */
  1420. return usecs * 1000 / quantum_ns;
  1421. }
  1422. /* Set interrupt moderation parameters */
  1423. int efx_init_irq_moderation(struct efx_nic *efx, unsigned int tx_usecs,
  1424. unsigned int rx_usecs, bool rx_adaptive,
  1425. bool rx_may_override_tx)
  1426. {
  1427. struct efx_channel *channel;
  1428. unsigned int irq_mod_max = DIV_ROUND_UP(efx->type->timer_period_max *
  1429. efx->timer_quantum_ns,
  1430. 1000);
  1431. unsigned int tx_ticks;
  1432. unsigned int rx_ticks;
  1433. EFX_ASSERT_RESET_SERIALISED(efx);
  1434. if (tx_usecs > irq_mod_max || rx_usecs > irq_mod_max)
  1435. return -EINVAL;
  1436. tx_ticks = irq_mod_ticks(tx_usecs, efx->timer_quantum_ns);
  1437. rx_ticks = irq_mod_ticks(rx_usecs, efx->timer_quantum_ns);
  1438. if (tx_ticks != rx_ticks && efx->tx_channel_offset == 0 &&
  1439. !rx_may_override_tx) {
  1440. netif_err(efx, drv, efx->net_dev, "Channels are shared. "
  1441. "RX and TX IRQ moderation must be equal\n");
  1442. return -EINVAL;
  1443. }
  1444. efx->irq_rx_adaptive = rx_adaptive;
  1445. efx->irq_rx_moderation = rx_ticks;
  1446. efx_for_each_channel(channel, efx) {
  1447. if (efx_channel_has_rx_queue(channel))
  1448. channel->irq_moderation = rx_ticks;
  1449. else if (efx_channel_has_tx_queues(channel))
  1450. channel->irq_moderation = tx_ticks;
  1451. }
  1452. return 0;
  1453. }
  1454. void efx_get_irq_moderation(struct efx_nic *efx, unsigned int *tx_usecs,
  1455. unsigned int *rx_usecs, bool *rx_adaptive)
  1456. {
  1457. /* We must round up when converting ticks to microseconds
  1458. * because we round down when converting the other way.
  1459. */
  1460. *rx_adaptive = efx->irq_rx_adaptive;
  1461. *rx_usecs = DIV_ROUND_UP(efx->irq_rx_moderation *
  1462. efx->timer_quantum_ns,
  1463. 1000);
  1464. /* If channels are shared between RX and TX, so is IRQ
  1465. * moderation. Otherwise, IRQ moderation is the same for all
  1466. * TX channels and is not adaptive.
  1467. */
  1468. if (efx->tx_channel_offset == 0)
  1469. *tx_usecs = *rx_usecs;
  1470. else
  1471. *tx_usecs = DIV_ROUND_UP(
  1472. efx->channel[efx->tx_channel_offset]->irq_moderation *
  1473. efx->timer_quantum_ns,
  1474. 1000);
  1475. }
  1476. /**************************************************************************
  1477. *
  1478. * Hardware monitor
  1479. *
  1480. **************************************************************************/
  1481. /* Run periodically off the general workqueue */
  1482. static void efx_monitor(struct work_struct *data)
  1483. {
  1484. struct efx_nic *efx = container_of(data, struct efx_nic,
  1485. monitor_work.work);
  1486. netif_vdbg(efx, timer, efx->net_dev,
  1487. "hardware monitor executing on CPU %d\n",
  1488. raw_smp_processor_id());
  1489. BUG_ON(efx->type->monitor == NULL);
  1490. /* If the mac_lock is already held then it is likely a port
  1491. * reconfiguration is already in place, which will likely do
  1492. * most of the work of monitor() anyway. */
  1493. if (mutex_trylock(&efx->mac_lock)) {
  1494. if (efx->port_enabled)
  1495. efx->type->monitor(efx);
  1496. mutex_unlock(&efx->mac_lock);
  1497. }
  1498. queue_delayed_work(efx->workqueue, &efx->monitor_work,
  1499. efx_monitor_interval);
  1500. }
  1501. /**************************************************************************
  1502. *
  1503. * ioctls
  1504. *
  1505. *************************************************************************/
  1506. /* Net device ioctl
  1507. * Context: process, rtnl_lock() held.
  1508. */
  1509. static int efx_ioctl(struct net_device *net_dev, struct ifreq *ifr, int cmd)
  1510. {
  1511. struct efx_nic *efx = netdev_priv(net_dev);
  1512. struct mii_ioctl_data *data = if_mii(ifr);
  1513. if (cmd == SIOCSHWTSTAMP)
  1514. return efx_ptp_ioctl(efx, ifr, cmd);
  1515. /* Convert phy_id from older PRTAD/DEVAD format */
  1516. if ((cmd == SIOCGMIIREG || cmd == SIOCSMIIREG) &&
  1517. (data->phy_id & 0xfc00) == 0x0400)
  1518. data->phy_id ^= MDIO_PHY_ID_C45 | 0x0400;
  1519. return mdio_mii_ioctl(&efx->mdio, data, cmd);
  1520. }
  1521. /**************************************************************************
  1522. *
  1523. * NAPI interface
  1524. *
  1525. **************************************************************************/
  1526. static void efx_init_napi_channel(struct efx_channel *channel)
  1527. {
  1528. struct efx_nic *efx = channel->efx;
  1529. channel->napi_dev = efx->net_dev;
  1530. netif_napi_add(channel->napi_dev, &channel->napi_str,
  1531. efx_poll, napi_weight);
  1532. }
  1533. static void efx_init_napi(struct efx_nic *efx)
  1534. {
  1535. struct efx_channel *channel;
  1536. efx_for_each_channel(channel, efx)
  1537. efx_init_napi_channel(channel);
  1538. }
  1539. static void efx_fini_napi_channel(struct efx_channel *channel)
  1540. {
  1541. if (channel->napi_dev)
  1542. netif_napi_del(&channel->napi_str);
  1543. channel->napi_dev = NULL;
  1544. }
  1545. static void efx_fini_napi(struct efx_nic *efx)
  1546. {
  1547. struct efx_channel *channel;
  1548. efx_for_each_channel(channel, efx)
  1549. efx_fini_napi_channel(channel);
  1550. }
  1551. /**************************************************************************
  1552. *
  1553. * Kernel netpoll interface
  1554. *
  1555. *************************************************************************/
  1556. #ifdef CONFIG_NET_POLL_CONTROLLER
  1557. /* Although in the common case interrupts will be disabled, this is not
  1558. * guaranteed. However, all our work happens inside the NAPI callback,
  1559. * so no locking is required.
  1560. */
  1561. static void efx_netpoll(struct net_device *net_dev)
  1562. {
  1563. struct efx_nic *efx = netdev_priv(net_dev);
  1564. struct efx_channel *channel;
  1565. efx_for_each_channel(channel, efx)
  1566. efx_schedule_channel(channel);
  1567. }
  1568. #endif
  1569. /**************************************************************************
  1570. *
  1571. * Kernel net device interface
  1572. *
  1573. *************************************************************************/
  1574. /* Context: process, rtnl_lock() held. */
  1575. static int efx_net_open(struct net_device *net_dev)
  1576. {
  1577. struct efx_nic *efx = netdev_priv(net_dev);
  1578. int rc;
  1579. netif_dbg(efx, ifup, efx->net_dev, "opening device on CPU %d\n",
  1580. raw_smp_processor_id());
  1581. rc = efx_check_disabled(efx);
  1582. if (rc)
  1583. return rc;
  1584. if (efx->phy_mode & PHY_MODE_SPECIAL)
  1585. return -EBUSY;
  1586. if (efx_mcdi_poll_reboot(efx) && efx_reset(efx, RESET_TYPE_ALL))
  1587. return -EIO;
  1588. /* Notify the kernel of the link state polled during driver load,
  1589. * before the monitor starts running */
  1590. efx_link_status_changed(efx);
  1591. efx_start_all(efx);
  1592. efx_selftest_async_start(efx);
  1593. return 0;
  1594. }
  1595. /* Context: process, rtnl_lock() held.
  1596. * Note that the kernel will ignore our return code; this method
  1597. * should really be a void.
  1598. */
  1599. static int efx_net_stop(struct net_device *net_dev)
  1600. {
  1601. struct efx_nic *efx = netdev_priv(net_dev);
  1602. netif_dbg(efx, ifdown, efx->net_dev, "closing on CPU %d\n",
  1603. raw_smp_processor_id());
  1604. /* Stop the device and flush all the channels */
  1605. efx_stop_all(efx);
  1606. return 0;
  1607. }
  1608. /* Context: process, dev_base_lock or RTNL held, non-blocking. */
  1609. static struct rtnl_link_stats64 *efx_net_stats(struct net_device *net_dev,
  1610. struct rtnl_link_stats64 *stats)
  1611. {
  1612. struct efx_nic *efx = netdev_priv(net_dev);
  1613. struct efx_mac_stats *mac_stats = &efx->mac_stats;
  1614. spin_lock_bh(&efx->stats_lock);
  1615. efx->type->update_stats(efx);
  1616. stats->rx_packets = mac_stats->rx_packets;
  1617. stats->tx_packets = mac_stats->tx_packets;
  1618. stats->rx_bytes = mac_stats->rx_bytes;
  1619. stats->tx_bytes = mac_stats->tx_bytes;
  1620. stats->rx_dropped = efx->n_rx_nodesc_drop_cnt;
  1621. stats->multicast = mac_stats->rx_multicast;
  1622. stats->collisions = mac_stats->tx_collision;
  1623. stats->rx_length_errors = (mac_stats->rx_gtjumbo +
  1624. mac_stats->rx_length_error);
  1625. stats->rx_crc_errors = mac_stats->rx_bad;
  1626. stats->rx_frame_errors = mac_stats->rx_align_error;
  1627. stats->rx_fifo_errors = mac_stats->rx_overflow;
  1628. stats->rx_missed_errors = mac_stats->rx_missed;
  1629. stats->tx_window_errors = mac_stats->tx_late_collision;
  1630. stats->rx_errors = (stats->rx_length_errors +
  1631. stats->rx_crc_errors +
  1632. stats->rx_frame_errors +
  1633. mac_stats->rx_symbol_error);
  1634. stats->tx_errors = (stats->tx_window_errors +
  1635. mac_stats->tx_bad);
  1636. spin_unlock_bh(&efx->stats_lock);
  1637. return stats;
  1638. }
  1639. /* Context: netif_tx_lock held, BHs disabled. */
  1640. static void efx_watchdog(struct net_device *net_dev)
  1641. {
  1642. struct efx_nic *efx = netdev_priv(net_dev);
  1643. netif_err(efx, tx_err, efx->net_dev,
  1644. "TX stuck with port_enabled=%d: resetting channels\n",
  1645. efx->port_enabled);
  1646. efx_schedule_reset(efx, RESET_TYPE_TX_WATCHDOG);
  1647. }
  1648. /* Context: process, rtnl_lock() held. */
  1649. static int efx_change_mtu(struct net_device *net_dev, int new_mtu)
  1650. {
  1651. struct efx_nic *efx = netdev_priv(net_dev);
  1652. int rc;
  1653. rc = efx_check_disabled(efx);
  1654. if (rc)
  1655. return rc;
  1656. if (new_mtu > EFX_MAX_MTU)
  1657. return -EINVAL;
  1658. netif_dbg(efx, drv, efx->net_dev, "changing MTU to %d\n", new_mtu);
  1659. efx_device_detach_sync(efx);
  1660. efx_stop_all(efx);
  1661. mutex_lock(&efx->mac_lock);
  1662. net_dev->mtu = new_mtu;
  1663. efx->type->reconfigure_mac(efx);
  1664. mutex_unlock(&efx->mac_lock);
  1665. efx_start_all(efx);
  1666. netif_device_attach(efx->net_dev);
  1667. return 0;
  1668. }
  1669. static int efx_set_mac_address(struct net_device *net_dev, void *data)
  1670. {
  1671. struct efx_nic *efx = netdev_priv(net_dev);
  1672. struct sockaddr *addr = data;
  1673. char *new_addr = addr->sa_data;
  1674. if (!is_valid_ether_addr(new_addr)) {
  1675. netif_err(efx, drv, efx->net_dev,
  1676. "invalid ethernet MAC address requested: %pM\n",
  1677. new_addr);
  1678. return -EADDRNOTAVAIL;
  1679. }
  1680. memcpy(net_dev->dev_addr, new_addr, net_dev->addr_len);
  1681. efx_sriov_mac_address_changed(efx);
  1682. /* Reconfigure the MAC */
  1683. mutex_lock(&efx->mac_lock);
  1684. efx->type->reconfigure_mac(efx);
  1685. mutex_unlock(&efx->mac_lock);
  1686. return 0;
  1687. }
  1688. /* Context: netif_addr_lock held, BHs disabled. */
  1689. static void efx_set_rx_mode(struct net_device *net_dev)
  1690. {
  1691. struct efx_nic *efx = netdev_priv(net_dev);
  1692. struct netdev_hw_addr *ha;
  1693. union efx_multicast_hash *mc_hash = &efx->multicast_hash;
  1694. u32 crc;
  1695. int bit;
  1696. efx->promiscuous = !!(net_dev->flags & IFF_PROMISC);
  1697. /* Build multicast hash table */
  1698. if (efx->promiscuous || (net_dev->flags & IFF_ALLMULTI)) {
  1699. memset(mc_hash, 0xff, sizeof(*mc_hash));
  1700. } else {
  1701. memset(mc_hash, 0x00, sizeof(*mc_hash));
  1702. netdev_for_each_mc_addr(ha, net_dev) {
  1703. crc = ether_crc_le(ETH_ALEN, ha->addr);
  1704. bit = crc & (EFX_MCAST_HASH_ENTRIES - 1);
  1705. __set_bit_le(bit, mc_hash);
  1706. }
  1707. /* Broadcast packets go through the multicast hash filter.
  1708. * ether_crc_le() of the broadcast address is 0xbe2612ff
  1709. * so we always add bit 0xff to the mask.
  1710. */
  1711. __set_bit_le(0xff, mc_hash);
  1712. }
  1713. if (efx->port_enabled)
  1714. queue_work(efx->workqueue, &efx->mac_work);
  1715. /* Otherwise efx_start_port() will do this */
  1716. }
  1717. static int efx_set_features(struct net_device *net_dev, netdev_features_t data)
  1718. {
  1719. struct efx_nic *efx = netdev_priv(net_dev);
  1720. /* If disabling RX n-tuple filtering, clear existing filters */
  1721. if (net_dev->features & ~data & NETIF_F_NTUPLE)
  1722. efx_filter_clear_rx(efx, EFX_FILTER_PRI_MANUAL);
  1723. return 0;
  1724. }
  1725. static const struct net_device_ops efx_netdev_ops = {
  1726. .ndo_open = efx_net_open,
  1727. .ndo_stop = efx_net_stop,
  1728. .ndo_get_stats64 = efx_net_stats,
  1729. .ndo_tx_timeout = efx_watchdog,
  1730. .ndo_start_xmit = efx_hard_start_xmit,
  1731. .ndo_validate_addr = eth_validate_addr,
  1732. .ndo_do_ioctl = efx_ioctl,
  1733. .ndo_change_mtu = efx_change_mtu,
  1734. .ndo_set_mac_address = efx_set_mac_address,
  1735. .ndo_set_rx_mode = efx_set_rx_mode,
  1736. .ndo_set_features = efx_set_features,
  1737. #ifdef CONFIG_SFC_SRIOV
  1738. .ndo_set_vf_mac = efx_sriov_set_vf_mac,
  1739. .ndo_set_vf_vlan = efx_sriov_set_vf_vlan,
  1740. .ndo_set_vf_spoofchk = efx_sriov_set_vf_spoofchk,
  1741. .ndo_get_vf_config = efx_sriov_get_vf_config,
  1742. #endif
  1743. #ifdef CONFIG_NET_POLL_CONTROLLER
  1744. .ndo_poll_controller = efx_netpoll,
  1745. #endif
  1746. .ndo_setup_tc = efx_setup_tc,
  1747. #ifdef CONFIG_RFS_ACCEL
  1748. .ndo_rx_flow_steer = efx_filter_rfs,
  1749. #endif
  1750. };
  1751. static void efx_update_name(struct efx_nic *efx)
  1752. {
  1753. strcpy(efx->name, efx->net_dev->name);
  1754. efx_mtd_rename(efx);
  1755. efx_set_channel_names(efx);
  1756. }
  1757. static int efx_netdev_event(struct notifier_block *this,
  1758. unsigned long event, void *ptr)
  1759. {
  1760. struct net_device *net_dev = netdev_notifier_info_to_dev(ptr);
  1761. if (net_dev->netdev_ops == &efx_netdev_ops &&
  1762. event == NETDEV_CHANGENAME)
  1763. efx_update_name(netdev_priv(net_dev));
  1764. return NOTIFY_DONE;
  1765. }
  1766. static struct notifier_block efx_netdev_notifier = {
  1767. .notifier_call = efx_netdev_event,
  1768. };
  1769. static ssize_t
  1770. show_phy_type(struct device *dev, struct device_attribute *attr, char *buf)
  1771. {
  1772. struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
  1773. return sprintf(buf, "%d\n", efx->phy_type);
  1774. }
  1775. static DEVICE_ATTR(phy_type, 0444, show_phy_type, NULL);
  1776. static int efx_register_netdev(struct efx_nic *efx)
  1777. {
  1778. struct net_device *net_dev = efx->net_dev;
  1779. struct efx_channel *channel;
  1780. int rc;
  1781. net_dev->watchdog_timeo = 5 * HZ;
  1782. net_dev->irq = efx->pci_dev->irq;
  1783. net_dev->netdev_ops = &efx_netdev_ops;
  1784. SET_ETHTOOL_OPS(net_dev, &efx_ethtool_ops);
  1785. net_dev->gso_max_segs = EFX_TSO_MAX_SEGS;
  1786. rtnl_lock();
  1787. /* Enable resets to be scheduled and check whether any were
  1788. * already requested. If so, the NIC is probably hosed so we
  1789. * abort.
  1790. */
  1791. efx->state = STATE_READY;
  1792. smp_mb(); /* ensure we change state before checking reset_pending */
  1793. if (efx->reset_pending) {
  1794. netif_err(efx, probe, efx->net_dev,
  1795. "aborting probe due to scheduled reset\n");
  1796. rc = -EIO;
  1797. goto fail_locked;
  1798. }
  1799. rc = dev_alloc_name(net_dev, net_dev->name);
  1800. if (rc < 0)
  1801. goto fail_locked;
  1802. efx_update_name(efx);
  1803. /* Always start with carrier off; PHY events will detect the link */
  1804. netif_carrier_off(net_dev);
  1805. rc = register_netdevice(net_dev);
  1806. if (rc)
  1807. goto fail_locked;
  1808. efx_for_each_channel(channel, efx) {
  1809. struct efx_tx_queue *tx_queue;
  1810. efx_for_each_channel_tx_queue(tx_queue, channel)
  1811. efx_init_tx_queue_core_txq(tx_queue);
  1812. }
  1813. rtnl_unlock();
  1814. rc = device_create_file(&efx->pci_dev->dev, &dev_attr_phy_type);
  1815. if (rc) {
  1816. netif_err(efx, drv, efx->net_dev,
  1817. "failed to init net dev attributes\n");
  1818. goto fail_registered;
  1819. }
  1820. return 0;
  1821. fail_registered:
  1822. rtnl_lock();
  1823. unregister_netdevice(net_dev);
  1824. fail_locked:
  1825. efx->state = STATE_UNINIT;
  1826. rtnl_unlock();
  1827. netif_err(efx, drv, efx->net_dev, "could not register net dev\n");
  1828. return rc;
  1829. }
  1830. static void efx_unregister_netdev(struct efx_nic *efx)
  1831. {
  1832. struct efx_channel *channel;
  1833. struct efx_tx_queue *tx_queue;
  1834. if (!efx->net_dev)
  1835. return;
  1836. BUG_ON(netdev_priv(efx->net_dev) != efx);
  1837. /* Free up any skbs still remaining. This has to happen before
  1838. * we try to unregister the netdev as running their destructors
  1839. * may be needed to get the device ref. count to 0. */
  1840. efx_for_each_channel(channel, efx) {
  1841. efx_for_each_channel_tx_queue(tx_queue, channel)
  1842. efx_release_tx_buffers(tx_queue);
  1843. }
  1844. strlcpy(efx->name, pci_name(efx->pci_dev), sizeof(efx->name));
  1845. device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_type);
  1846. rtnl_lock();
  1847. unregister_netdevice(efx->net_dev);
  1848. efx->state = STATE_UNINIT;
  1849. rtnl_unlock();
  1850. }
  1851. /**************************************************************************
  1852. *
  1853. * Device reset and suspend
  1854. *
  1855. **************************************************************************/
  1856. /* Tears down the entire software state and most of the hardware state
  1857. * before reset. */
  1858. void efx_reset_down(struct efx_nic *efx, enum reset_type method)
  1859. {
  1860. EFX_ASSERT_RESET_SERIALISED(efx);
  1861. efx_stop_all(efx);
  1862. efx_stop_interrupts(efx, false);
  1863. mutex_lock(&efx->mac_lock);
  1864. if (efx->port_initialized && method != RESET_TYPE_INVISIBLE)
  1865. efx->phy_op->fini(efx);
  1866. efx->type->fini(efx);
  1867. }
  1868. /* This function will always ensure that the locks acquired in
  1869. * efx_reset_down() are released. A failure return code indicates
  1870. * that we were unable to reinitialise the hardware, and the
  1871. * driver should be disabled. If ok is false, then the rx and tx
  1872. * engines are not restarted, pending a RESET_DISABLE. */
  1873. int efx_reset_up(struct efx_nic *efx, enum reset_type method, bool ok)
  1874. {
  1875. int rc;
  1876. EFX_ASSERT_RESET_SERIALISED(efx);
  1877. rc = efx->type->init(efx);
  1878. if (rc) {
  1879. netif_err(efx, drv, efx->net_dev, "failed to initialise NIC\n");
  1880. goto fail;
  1881. }
  1882. if (!ok)
  1883. goto fail;
  1884. if (efx->port_initialized && method != RESET_TYPE_INVISIBLE) {
  1885. rc = efx->phy_op->init(efx);
  1886. if (rc)
  1887. goto fail;
  1888. if (efx->phy_op->reconfigure(efx))
  1889. netif_err(efx, drv, efx->net_dev,
  1890. "could not restore PHY settings\n");
  1891. }
  1892. efx->type->reconfigure_mac(efx);
  1893. efx_start_interrupts(efx, false);
  1894. efx_restore_filters(efx);
  1895. efx_sriov_reset(efx);
  1896. mutex_unlock(&efx->mac_lock);
  1897. efx_start_all(efx);
  1898. return 0;
  1899. fail:
  1900. efx->port_initialized = false;
  1901. mutex_unlock(&efx->mac_lock);
  1902. return rc;
  1903. }
  1904. /* Reset the NIC using the specified method. Note that the reset may
  1905. * fail, in which case the card will be left in an unusable state.
  1906. *
  1907. * Caller must hold the rtnl_lock.
  1908. */
  1909. int efx_reset(struct efx_nic *efx, enum reset_type method)
  1910. {
  1911. int rc, rc2;
  1912. bool disabled;
  1913. netif_info(efx, drv, efx->net_dev, "resetting (%s)\n",
  1914. RESET_TYPE(method));
  1915. efx_device_detach_sync(efx);
  1916. efx_reset_down(efx, method);
  1917. rc = efx->type->reset(efx, method);
  1918. if (rc) {
  1919. netif_err(efx, drv, efx->net_dev, "failed to reset hardware\n");
  1920. goto out;
  1921. }
  1922. /* Clear flags for the scopes we covered. We assume the NIC and
  1923. * driver are now quiescent so that there is no race here.
  1924. */
  1925. efx->reset_pending &= -(1 << (method + 1));
  1926. /* Reinitialise bus-mastering, which may have been turned off before
  1927. * the reset was scheduled. This is still appropriate, even in the
  1928. * RESET_TYPE_DISABLE since this driver generally assumes the hardware
  1929. * can respond to requests. */
  1930. pci_set_master(efx->pci_dev);
  1931. out:
  1932. /* Leave device stopped if necessary */
  1933. disabled = rc ||
  1934. method == RESET_TYPE_DISABLE ||
  1935. method == RESET_TYPE_RECOVER_OR_DISABLE;
  1936. rc2 = efx_reset_up(efx, method, !disabled);
  1937. if (rc2) {
  1938. disabled = true;
  1939. if (!rc)
  1940. rc = rc2;
  1941. }
  1942. if (disabled) {
  1943. dev_close(efx->net_dev);
  1944. netif_err(efx, drv, efx->net_dev, "has been disabled\n");
  1945. efx->state = STATE_DISABLED;
  1946. } else {
  1947. netif_dbg(efx, drv, efx->net_dev, "reset complete\n");
  1948. netif_device_attach(efx->net_dev);
  1949. }
  1950. return rc;
  1951. }
  1952. /* Try recovery mechanisms.
  1953. * For now only EEH is supported.
  1954. * Returns 0 if the recovery mechanisms are unsuccessful.
  1955. * Returns a non-zero value otherwise.
  1956. */
  1957. int efx_try_recovery(struct efx_nic *efx)
  1958. {
  1959. #ifdef CONFIG_EEH
  1960. /* A PCI error can occur and not be seen by EEH because nothing
  1961. * happens on the PCI bus. In this case the driver may fail and
  1962. * schedule a 'recover or reset', leading to this recovery handler.
  1963. * Manually call the eeh failure check function.
  1964. */
  1965. struct eeh_dev *eehdev =
  1966. of_node_to_eeh_dev(pci_device_to_OF_node(efx->pci_dev));
  1967. if (eeh_dev_check_failure(eehdev)) {
  1968. /* The EEH mechanisms will handle the error and reset the
  1969. * device if necessary.
  1970. */
  1971. return 1;
  1972. }
  1973. #endif
  1974. return 0;
  1975. }
  1976. /* The worker thread exists so that code that cannot sleep can
  1977. * schedule a reset for later.
  1978. */
  1979. static void efx_reset_work(struct work_struct *data)
  1980. {
  1981. struct efx_nic *efx = container_of(data, struct efx_nic, reset_work);
  1982. unsigned long pending;
  1983. enum reset_type method;
  1984. pending = ACCESS_ONCE(efx->reset_pending);
  1985. method = fls(pending) - 1;
  1986. if ((method == RESET_TYPE_RECOVER_OR_DISABLE ||
  1987. method == RESET_TYPE_RECOVER_OR_ALL) &&
  1988. efx_try_recovery(efx))
  1989. return;
  1990. if (!pending)
  1991. return;
  1992. rtnl_lock();
  1993. /* We checked the state in efx_schedule_reset() but it may
  1994. * have changed by now. Now that we have the RTNL lock,
  1995. * it cannot change again.
  1996. */
  1997. if (efx->state == STATE_READY)
  1998. (void)efx_reset(efx, method);
  1999. rtnl_unlock();
  2000. }
  2001. void efx_schedule_reset(struct efx_nic *efx, enum reset_type type)
  2002. {
  2003. enum reset_type method;
  2004. if (efx->state == STATE_RECOVERY) {
  2005. netif_dbg(efx, drv, efx->net_dev,
  2006. "recovering: skip scheduling %s reset\n",
  2007. RESET_TYPE(type));
  2008. return;
  2009. }
  2010. switch (type) {
  2011. case RESET_TYPE_INVISIBLE:
  2012. case RESET_TYPE_ALL:
  2013. case RESET_TYPE_RECOVER_OR_ALL:
  2014. case RESET_TYPE_WORLD:
  2015. case RESET_TYPE_DISABLE:
  2016. case RESET_TYPE_RECOVER_OR_DISABLE:
  2017. method = type;
  2018. netif_dbg(efx, drv, efx->net_dev, "scheduling %s reset\n",
  2019. RESET_TYPE(method));
  2020. break;
  2021. default:
  2022. method = efx->type->map_reset_reason(type);
  2023. netif_dbg(efx, drv, efx->net_dev,
  2024. "scheduling %s reset for %s\n",
  2025. RESET_TYPE(method), RESET_TYPE(type));
  2026. break;
  2027. }
  2028. set_bit(method, &efx->reset_pending);
  2029. smp_mb(); /* ensure we change reset_pending before checking state */
  2030. /* If we're not READY then just leave the flags set as the cue
  2031. * to abort probing or reschedule the reset later.
  2032. */
  2033. if (ACCESS_ONCE(efx->state) != STATE_READY)
  2034. return;
  2035. /* efx_process_channel() will no longer read events once a
  2036. * reset is scheduled. So switch back to poll'd MCDI completions. */
  2037. efx_mcdi_mode_poll(efx);
  2038. queue_work(reset_workqueue, &efx->reset_work);
  2039. }
  2040. /**************************************************************************
  2041. *
  2042. * List of NICs we support
  2043. *
  2044. **************************************************************************/
  2045. /* PCI device ID table */
  2046. static DEFINE_PCI_DEVICE_TABLE(efx_pci_table) = {
  2047. {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE,
  2048. PCI_DEVICE_ID_SOLARFLARE_SFC4000A_0),
  2049. .driver_data = (unsigned long) &falcon_a1_nic_type},
  2050. {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE,
  2051. PCI_DEVICE_ID_SOLARFLARE_SFC4000B),
  2052. .driver_data = (unsigned long) &falcon_b0_nic_type},
  2053. {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0803), /* SFC9020 */
  2054. .driver_data = (unsigned long) &siena_a0_nic_type},
  2055. {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0813), /* SFL9021 */
  2056. .driver_data = (unsigned long) &siena_a0_nic_type},
  2057. {0} /* end of list */
  2058. };
  2059. /**************************************************************************
  2060. *
  2061. * Dummy PHY/MAC operations
  2062. *
  2063. * Can be used for some unimplemented operations
  2064. * Needed so all function pointers are valid and do not have to be tested
  2065. * before use
  2066. *
  2067. **************************************************************************/
  2068. int efx_port_dummy_op_int(struct efx_nic *efx)
  2069. {
  2070. return 0;
  2071. }
  2072. void efx_port_dummy_op_void(struct efx_nic *efx) {}
  2073. static bool efx_port_dummy_op_poll(struct efx_nic *efx)
  2074. {
  2075. return false;
  2076. }
  2077. static const struct efx_phy_operations efx_dummy_phy_operations = {
  2078. .init = efx_port_dummy_op_int,
  2079. .reconfigure = efx_port_dummy_op_int,
  2080. .poll = efx_port_dummy_op_poll,
  2081. .fini = efx_port_dummy_op_void,
  2082. };
  2083. /**************************************************************************
  2084. *
  2085. * Data housekeeping
  2086. *
  2087. **************************************************************************/
  2088. /* This zeroes out and then fills in the invariants in a struct
  2089. * efx_nic (including all sub-structures).
  2090. */
  2091. static int efx_init_struct(struct efx_nic *efx,
  2092. struct pci_dev *pci_dev, struct net_device *net_dev)
  2093. {
  2094. int i;
  2095. /* Initialise common structures */
  2096. spin_lock_init(&efx->biu_lock);
  2097. #ifdef CONFIG_SFC_MTD
  2098. INIT_LIST_HEAD(&efx->mtd_list);
  2099. #endif
  2100. INIT_WORK(&efx->reset_work, efx_reset_work);
  2101. INIT_DELAYED_WORK(&efx->monitor_work, efx_monitor);
  2102. INIT_DELAYED_WORK(&efx->selftest_work, efx_selftest_async_work);
  2103. efx->pci_dev = pci_dev;
  2104. efx->msg_enable = debug;
  2105. efx->state = STATE_UNINIT;
  2106. strlcpy(efx->name, pci_name(pci_dev), sizeof(efx->name));
  2107. efx->net_dev = net_dev;
  2108. spin_lock_init(&efx->stats_lock);
  2109. mutex_init(&efx->mac_lock);
  2110. efx->phy_op = &efx_dummy_phy_operations;
  2111. efx->mdio.dev = net_dev;
  2112. INIT_WORK(&efx->mac_work, efx_mac_work);
  2113. init_waitqueue_head(&efx->flush_wq);
  2114. for (i = 0; i < EFX_MAX_CHANNELS; i++) {
  2115. efx->channel[i] = efx_alloc_channel(efx, i, NULL);
  2116. if (!efx->channel[i])
  2117. goto fail;
  2118. }
  2119. EFX_BUG_ON_PARANOID(efx->type->phys_addr_channels > EFX_MAX_CHANNELS);
  2120. /* Higher numbered interrupt modes are less capable! */
  2121. efx->interrupt_mode = max(efx->type->max_interrupt_mode,
  2122. interrupt_mode);
  2123. /* Would be good to use the net_dev name, but we're too early */
  2124. snprintf(efx->workqueue_name, sizeof(efx->workqueue_name), "sfc%s",
  2125. pci_name(pci_dev));
  2126. efx->workqueue = create_singlethread_workqueue(efx->workqueue_name);
  2127. if (!efx->workqueue)
  2128. goto fail;
  2129. return 0;
  2130. fail:
  2131. efx_fini_struct(efx);
  2132. return -ENOMEM;
  2133. }
  2134. static void efx_fini_struct(struct efx_nic *efx)
  2135. {
  2136. int i;
  2137. for (i = 0; i < EFX_MAX_CHANNELS; i++)
  2138. kfree(efx->channel[i]);
  2139. if (efx->workqueue) {
  2140. destroy_workqueue(efx->workqueue);
  2141. efx->workqueue = NULL;
  2142. }
  2143. }
  2144. /**************************************************************************
  2145. *
  2146. * PCI interface
  2147. *
  2148. **************************************************************************/
  2149. /* Main body of final NIC shutdown code
  2150. * This is called only at module unload (or hotplug removal).
  2151. */
  2152. static void efx_pci_remove_main(struct efx_nic *efx)
  2153. {
  2154. /* Flush reset_work. It can no longer be scheduled since we
  2155. * are not READY.
  2156. */
  2157. BUG_ON(efx->state == STATE_READY);
  2158. cancel_work_sync(&efx->reset_work);
  2159. efx_stop_interrupts(efx, false);
  2160. efx_nic_fini_interrupt(efx);
  2161. efx_fini_port(efx);
  2162. efx->type->fini(efx);
  2163. efx_fini_napi(efx);
  2164. efx_remove_all(efx);
  2165. }
  2166. /* Final NIC shutdown
  2167. * This is called only at module unload (or hotplug removal).
  2168. */
  2169. static void efx_pci_remove(struct pci_dev *pci_dev)
  2170. {
  2171. struct efx_nic *efx;
  2172. efx = pci_get_drvdata(pci_dev);
  2173. if (!efx)
  2174. return;
  2175. /* Mark the NIC as fini, then stop the interface */
  2176. rtnl_lock();
  2177. dev_close(efx->net_dev);
  2178. efx_stop_interrupts(efx, false);
  2179. rtnl_unlock();
  2180. efx_sriov_fini(efx);
  2181. efx_unregister_netdev(efx);
  2182. efx_mtd_remove(efx);
  2183. efx_pci_remove_main(efx);
  2184. efx_fini_io(efx);
  2185. netif_dbg(efx, drv, efx->net_dev, "shutdown successful\n");
  2186. efx_fini_struct(efx);
  2187. pci_set_drvdata(pci_dev, NULL);
  2188. free_netdev(efx->net_dev);
  2189. pci_disable_pcie_error_reporting(pci_dev);
  2190. };
  2191. /* NIC VPD information
  2192. * Called during probe to display the part number of the
  2193. * installed NIC. VPD is potentially very large but this should
  2194. * always appear within the first 512 bytes.
  2195. */
  2196. #define SFC_VPD_LEN 512
  2197. static void efx_print_product_vpd(struct efx_nic *efx)
  2198. {
  2199. struct pci_dev *dev = efx->pci_dev;
  2200. char vpd_data[SFC_VPD_LEN];
  2201. ssize_t vpd_size;
  2202. int i, j;
  2203. /* Get the vpd data from the device */
  2204. vpd_size = pci_read_vpd(dev, 0, sizeof(vpd_data), vpd_data);
  2205. if (vpd_size <= 0) {
  2206. netif_err(efx, drv, efx->net_dev, "Unable to read VPD\n");
  2207. return;
  2208. }
  2209. /* Get the Read only section */
  2210. i = pci_vpd_find_tag(vpd_data, 0, vpd_size, PCI_VPD_LRDT_RO_DATA);
  2211. if (i < 0) {
  2212. netif_err(efx, drv, efx->net_dev, "VPD Read-only not found\n");
  2213. return;
  2214. }
  2215. j = pci_vpd_lrdt_size(&vpd_data[i]);
  2216. i += PCI_VPD_LRDT_TAG_SIZE;
  2217. if (i + j > vpd_size)
  2218. j = vpd_size - i;
  2219. /* Get the Part number */
  2220. i = pci_vpd_find_info_keyword(vpd_data, i, j, "PN");
  2221. if (i < 0) {
  2222. netif_err(efx, drv, efx->net_dev, "Part number not found\n");
  2223. return;
  2224. }
  2225. j = pci_vpd_info_field_size(&vpd_data[i]);
  2226. i += PCI_VPD_INFO_FLD_HDR_SIZE;
  2227. if (i + j > vpd_size) {
  2228. netif_err(efx, drv, efx->net_dev, "Incomplete part number\n");
  2229. return;
  2230. }
  2231. netif_info(efx, drv, efx->net_dev,
  2232. "Part Number : %.*s\n", j, &vpd_data[i]);
  2233. }
  2234. /* Main body of NIC initialisation
  2235. * This is called at module load (or hotplug insertion, theoretically).
  2236. */
  2237. static int efx_pci_probe_main(struct efx_nic *efx)
  2238. {
  2239. int rc;
  2240. /* Do start-of-day initialisation */
  2241. rc = efx_probe_all(efx);
  2242. if (rc)
  2243. goto fail1;
  2244. efx_init_napi(efx);
  2245. rc = efx->type->init(efx);
  2246. if (rc) {
  2247. netif_err(efx, probe, efx->net_dev,
  2248. "failed to initialise NIC\n");
  2249. goto fail3;
  2250. }
  2251. rc = efx_init_port(efx);
  2252. if (rc) {
  2253. netif_err(efx, probe, efx->net_dev,
  2254. "failed to initialise port\n");
  2255. goto fail4;
  2256. }
  2257. rc = efx_nic_init_interrupt(efx);
  2258. if (rc)
  2259. goto fail5;
  2260. efx_start_interrupts(efx, false);
  2261. return 0;
  2262. fail5:
  2263. efx_fini_port(efx);
  2264. fail4:
  2265. efx->type->fini(efx);
  2266. fail3:
  2267. efx_fini_napi(efx);
  2268. efx_remove_all(efx);
  2269. fail1:
  2270. return rc;
  2271. }
  2272. /* NIC initialisation
  2273. *
  2274. * This is called at module load (or hotplug insertion,
  2275. * theoretically). It sets up PCI mappings, resets the NIC,
  2276. * sets up and registers the network devices with the kernel and hooks
  2277. * the interrupt service routine. It does not prepare the device for
  2278. * transmission; this is left to the first time one of the network
  2279. * interfaces is brought up (i.e. efx_net_open).
  2280. */
  2281. static int efx_pci_probe(struct pci_dev *pci_dev,
  2282. const struct pci_device_id *entry)
  2283. {
  2284. struct net_device *net_dev;
  2285. struct efx_nic *efx;
  2286. int rc;
  2287. /* Allocate and initialise a struct net_device and struct efx_nic */
  2288. net_dev = alloc_etherdev_mqs(sizeof(*efx), EFX_MAX_CORE_TX_QUEUES,
  2289. EFX_MAX_RX_QUEUES);
  2290. if (!net_dev)
  2291. return -ENOMEM;
  2292. efx = netdev_priv(net_dev);
  2293. efx->type = (const struct efx_nic_type *) entry->driver_data;
  2294. net_dev->features |= (efx->type->offload_features | NETIF_F_SG |
  2295. NETIF_F_HIGHDMA | NETIF_F_TSO |
  2296. NETIF_F_RXCSUM);
  2297. if (efx->type->offload_features & NETIF_F_V6_CSUM)
  2298. net_dev->features |= NETIF_F_TSO6;
  2299. /* Mask for features that also apply to VLAN devices */
  2300. net_dev->vlan_features |= (NETIF_F_ALL_CSUM | NETIF_F_SG |
  2301. NETIF_F_HIGHDMA | NETIF_F_ALL_TSO |
  2302. NETIF_F_RXCSUM);
  2303. /* All offloads can be toggled */
  2304. net_dev->hw_features = net_dev->features & ~NETIF_F_HIGHDMA;
  2305. pci_set_drvdata(pci_dev, efx);
  2306. SET_NETDEV_DEV(net_dev, &pci_dev->dev);
  2307. rc = efx_init_struct(efx, pci_dev, net_dev);
  2308. if (rc)
  2309. goto fail1;
  2310. netif_info(efx, probe, efx->net_dev,
  2311. "Solarflare NIC detected\n");
  2312. efx_print_product_vpd(efx);
  2313. /* Set up basic I/O (BAR mappings etc) */
  2314. rc = efx_init_io(efx);
  2315. if (rc)
  2316. goto fail2;
  2317. rc = efx_pci_probe_main(efx);
  2318. if (rc)
  2319. goto fail3;
  2320. rc = efx_register_netdev(efx);
  2321. if (rc)
  2322. goto fail4;
  2323. rc = efx_sriov_init(efx);
  2324. if (rc)
  2325. netif_err(efx, probe, efx->net_dev,
  2326. "SR-IOV can't be enabled rc %d\n", rc);
  2327. netif_dbg(efx, probe, efx->net_dev, "initialisation successful\n");
  2328. /* Try to create MTDs, but allow this to fail */
  2329. rtnl_lock();
  2330. rc = efx_mtd_probe(efx);
  2331. rtnl_unlock();
  2332. if (rc)
  2333. netif_warn(efx, probe, efx->net_dev,
  2334. "failed to create MTDs (%d)\n", rc);
  2335. rc = pci_enable_pcie_error_reporting(pci_dev);
  2336. if (rc && rc != -EINVAL)
  2337. netif_warn(efx, probe, efx->net_dev,
  2338. "pci_enable_pcie_error_reporting failed (%d)\n", rc);
  2339. return 0;
  2340. fail4:
  2341. efx_pci_remove_main(efx);
  2342. fail3:
  2343. efx_fini_io(efx);
  2344. fail2:
  2345. efx_fini_struct(efx);
  2346. fail1:
  2347. pci_set_drvdata(pci_dev, NULL);
  2348. WARN_ON(rc > 0);
  2349. netif_dbg(efx, drv, efx->net_dev, "initialisation failed. rc=%d\n", rc);
  2350. free_netdev(net_dev);
  2351. return rc;
  2352. }
  2353. static int efx_pm_freeze(struct device *dev)
  2354. {
  2355. struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
  2356. rtnl_lock();
  2357. if (efx->state != STATE_DISABLED) {
  2358. efx->state = STATE_UNINIT;
  2359. efx_device_detach_sync(efx);
  2360. efx_stop_all(efx);
  2361. efx_stop_interrupts(efx, false);
  2362. }
  2363. rtnl_unlock();
  2364. return 0;
  2365. }
  2366. static int efx_pm_thaw(struct device *dev)
  2367. {
  2368. struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
  2369. rtnl_lock();
  2370. if (efx->state != STATE_DISABLED) {
  2371. efx_start_interrupts(efx, false);
  2372. mutex_lock(&efx->mac_lock);
  2373. efx->phy_op->reconfigure(efx);
  2374. mutex_unlock(&efx->mac_lock);
  2375. efx_start_all(efx);
  2376. netif_device_attach(efx->net_dev);
  2377. efx->state = STATE_READY;
  2378. efx->type->resume_wol(efx);
  2379. }
  2380. rtnl_unlock();
  2381. /* Reschedule any quenched resets scheduled during efx_pm_freeze() */
  2382. queue_work(reset_workqueue, &efx->reset_work);
  2383. return 0;
  2384. }
  2385. static int efx_pm_poweroff(struct device *dev)
  2386. {
  2387. struct pci_dev *pci_dev = to_pci_dev(dev);
  2388. struct efx_nic *efx = pci_get_drvdata(pci_dev);
  2389. efx->type->fini(efx);
  2390. efx->reset_pending = 0;
  2391. pci_save_state(pci_dev);
  2392. return pci_set_power_state(pci_dev, PCI_D3hot);
  2393. }
  2394. /* Used for both resume and restore */
  2395. static int efx_pm_resume(struct device *dev)
  2396. {
  2397. struct pci_dev *pci_dev = to_pci_dev(dev);
  2398. struct efx_nic *efx = pci_get_drvdata(pci_dev);
  2399. int rc;
  2400. rc = pci_set_power_state(pci_dev, PCI_D0);
  2401. if (rc)
  2402. return rc;
  2403. pci_restore_state(pci_dev);
  2404. rc = pci_enable_device(pci_dev);
  2405. if (rc)
  2406. return rc;
  2407. pci_set_master(efx->pci_dev);
  2408. rc = efx->type->reset(efx, RESET_TYPE_ALL);
  2409. if (rc)
  2410. return rc;
  2411. rc = efx->type->init(efx);
  2412. if (rc)
  2413. return rc;
  2414. efx_pm_thaw(dev);
  2415. return 0;
  2416. }
  2417. static int efx_pm_suspend(struct device *dev)
  2418. {
  2419. int rc;
  2420. efx_pm_freeze(dev);
  2421. rc = efx_pm_poweroff(dev);
  2422. if (rc)
  2423. efx_pm_resume(dev);
  2424. return rc;
  2425. }
  2426. static const struct dev_pm_ops efx_pm_ops = {
  2427. .suspend = efx_pm_suspend,
  2428. .resume = efx_pm_resume,
  2429. .freeze = efx_pm_freeze,
  2430. .thaw = efx_pm_thaw,
  2431. .poweroff = efx_pm_poweroff,
  2432. .restore = efx_pm_resume,
  2433. };
  2434. /* A PCI error affecting this device was detected.
  2435. * At this point MMIO and DMA may be disabled.
  2436. * Stop the software path and request a slot reset.
  2437. */
  2438. static pci_ers_result_t efx_io_error_detected(struct pci_dev *pdev,
  2439. enum pci_channel_state state)
  2440. {
  2441. pci_ers_result_t status = PCI_ERS_RESULT_RECOVERED;
  2442. struct efx_nic *efx = pci_get_drvdata(pdev);
  2443. if (state == pci_channel_io_perm_failure)
  2444. return PCI_ERS_RESULT_DISCONNECT;
  2445. rtnl_lock();
  2446. if (efx->state != STATE_DISABLED) {
  2447. efx->state = STATE_RECOVERY;
  2448. efx->reset_pending = 0;
  2449. efx_device_detach_sync(efx);
  2450. efx_stop_all(efx);
  2451. efx_stop_interrupts(efx, false);
  2452. status = PCI_ERS_RESULT_NEED_RESET;
  2453. } else {
  2454. /* If the interface is disabled we don't want to do anything
  2455. * with it.
  2456. */
  2457. status = PCI_ERS_RESULT_RECOVERED;
  2458. }
  2459. rtnl_unlock();
  2460. pci_disable_device(pdev);
  2461. return status;
  2462. }
  2463. /* Fake a successfull reset, which will be performed later in efx_io_resume. */
  2464. static pci_ers_result_t efx_io_slot_reset(struct pci_dev *pdev)
  2465. {
  2466. struct efx_nic *efx = pci_get_drvdata(pdev);
  2467. pci_ers_result_t status = PCI_ERS_RESULT_RECOVERED;
  2468. int rc;
  2469. if (pci_enable_device(pdev)) {
  2470. netif_err(efx, hw, efx->net_dev,
  2471. "Cannot re-enable PCI device after reset.\n");
  2472. status = PCI_ERS_RESULT_DISCONNECT;
  2473. }
  2474. rc = pci_cleanup_aer_uncorrect_error_status(pdev);
  2475. if (rc) {
  2476. netif_err(efx, hw, efx->net_dev,
  2477. "pci_cleanup_aer_uncorrect_error_status failed (%d)\n", rc);
  2478. /* Non-fatal error. Continue. */
  2479. }
  2480. return status;
  2481. }
  2482. /* Perform the actual reset and resume I/O operations. */
  2483. static void efx_io_resume(struct pci_dev *pdev)
  2484. {
  2485. struct efx_nic *efx = pci_get_drvdata(pdev);
  2486. int rc;
  2487. rtnl_lock();
  2488. if (efx->state == STATE_DISABLED)
  2489. goto out;
  2490. rc = efx_reset(efx, RESET_TYPE_ALL);
  2491. if (rc) {
  2492. netif_err(efx, hw, efx->net_dev,
  2493. "efx_reset failed after PCI error (%d)\n", rc);
  2494. } else {
  2495. efx->state = STATE_READY;
  2496. netif_dbg(efx, hw, efx->net_dev,
  2497. "Done resetting and resuming IO after PCI error.\n");
  2498. }
  2499. out:
  2500. rtnl_unlock();
  2501. }
  2502. /* For simplicity and reliability, we always require a slot reset and try to
  2503. * reset the hardware when a pci error affecting the device is detected.
  2504. * We leave both the link_reset and mmio_enabled callback unimplemented:
  2505. * with our request for slot reset the mmio_enabled callback will never be
  2506. * called, and the link_reset callback is not used by AER or EEH mechanisms.
  2507. */
  2508. static struct pci_error_handlers efx_err_handlers = {
  2509. .error_detected = efx_io_error_detected,
  2510. .slot_reset = efx_io_slot_reset,
  2511. .resume = efx_io_resume,
  2512. };
  2513. static struct pci_driver efx_pci_driver = {
  2514. .name = KBUILD_MODNAME,
  2515. .id_table = efx_pci_table,
  2516. .probe = efx_pci_probe,
  2517. .remove = efx_pci_remove,
  2518. .driver.pm = &efx_pm_ops,
  2519. .err_handler = &efx_err_handlers,
  2520. };
  2521. /**************************************************************************
  2522. *
  2523. * Kernel module interface
  2524. *
  2525. *************************************************************************/
  2526. module_param(interrupt_mode, uint, 0444);
  2527. MODULE_PARM_DESC(interrupt_mode,
  2528. "Interrupt mode (0=>MSIX 1=>MSI 2=>legacy)");
  2529. static int __init efx_init_module(void)
  2530. {
  2531. int rc;
  2532. printk(KERN_INFO "Solarflare NET driver v" EFX_DRIVER_VERSION "\n");
  2533. rc = register_netdevice_notifier(&efx_netdev_notifier);
  2534. if (rc)
  2535. goto err_notifier;
  2536. rc = efx_init_sriov();
  2537. if (rc)
  2538. goto err_sriov;
  2539. reset_workqueue = create_singlethread_workqueue("sfc_reset");
  2540. if (!reset_workqueue) {
  2541. rc = -ENOMEM;
  2542. goto err_reset;
  2543. }
  2544. rc = pci_register_driver(&efx_pci_driver);
  2545. if (rc < 0)
  2546. goto err_pci;
  2547. return 0;
  2548. err_pci:
  2549. destroy_workqueue(reset_workqueue);
  2550. err_reset:
  2551. efx_fini_sriov();
  2552. err_sriov:
  2553. unregister_netdevice_notifier(&efx_netdev_notifier);
  2554. err_notifier:
  2555. return rc;
  2556. }
  2557. static void __exit efx_exit_module(void)
  2558. {
  2559. printk(KERN_INFO "Solarflare NET driver unloading\n");
  2560. pci_unregister_driver(&efx_pci_driver);
  2561. destroy_workqueue(reset_workqueue);
  2562. efx_fini_sriov();
  2563. unregister_netdevice_notifier(&efx_netdev_notifier);
  2564. }
  2565. module_init(efx_init_module);
  2566. module_exit(efx_exit_module);
  2567. MODULE_AUTHOR("Solarflare Communications and "
  2568. "Michael Brown <mbrown@fensystems.co.uk>");
  2569. MODULE_DESCRIPTION("Solarflare Communications network driver");
  2570. MODULE_LICENSE("GPL");
  2571. MODULE_DEVICE_TABLE(pci, efx_pci_table);