efx.c 80 KB

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