efx.c 80 KB

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