falcon.c 92 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272
  1. /****************************************************************************
  2. * Driver for Solarflare Solarstorm network controllers and boards
  3. * Copyright 2005-2006 Fen Systems Ltd.
  4. * Copyright 2006-2008 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/bitops.h>
  11. #include <linux/delay.h>
  12. #include <linux/pci.h>
  13. #include <linux/module.h>
  14. #include <linux/seq_file.h>
  15. #include <linux/i2c.h>
  16. #include <linux/mii.h>
  17. #include "net_driver.h"
  18. #include "bitfield.h"
  19. #include "efx.h"
  20. #include "mac.h"
  21. #include "spi.h"
  22. #include "falcon.h"
  23. #include "regs.h"
  24. #include "io.h"
  25. #include "mdio_10g.h"
  26. #include "phy.h"
  27. #include "workarounds.h"
  28. /* Hardware control for SFC4000 (aka Falcon). */
  29. /**************************************************************************
  30. *
  31. * Configurable values
  32. *
  33. **************************************************************************
  34. */
  35. /* This is set to 16 for a good reason. In summary, if larger than
  36. * 16, the descriptor cache holds more than a default socket
  37. * buffer's worth of packets (for UDP we can only have at most one
  38. * socket buffer's worth outstanding). This combined with the fact
  39. * that we only get 1 TX event per descriptor cache means the NIC
  40. * goes idle.
  41. */
  42. #define TX_DC_ENTRIES 16
  43. #define TX_DC_ENTRIES_ORDER 1
  44. #define TX_DC_BASE 0x130000
  45. #define RX_DC_ENTRIES 64
  46. #define RX_DC_ENTRIES_ORDER 3
  47. #define RX_DC_BASE 0x100000
  48. static const unsigned int
  49. /* "Large" EEPROM device: Atmel AT25640 or similar
  50. * 8 KB, 16-bit address, 32 B write block */
  51. large_eeprom_type = ((13 << SPI_DEV_TYPE_SIZE_LBN)
  52. | (2 << SPI_DEV_TYPE_ADDR_LEN_LBN)
  53. | (5 << SPI_DEV_TYPE_BLOCK_SIZE_LBN)),
  54. /* Default flash device: Atmel AT25F1024
  55. * 128 KB, 24-bit address, 32 KB erase block, 256 B write block */
  56. default_flash_type = ((17 << SPI_DEV_TYPE_SIZE_LBN)
  57. | (3 << SPI_DEV_TYPE_ADDR_LEN_LBN)
  58. | (0x52 << SPI_DEV_TYPE_ERASE_CMD_LBN)
  59. | (15 << SPI_DEV_TYPE_ERASE_SIZE_LBN)
  60. | (8 << SPI_DEV_TYPE_BLOCK_SIZE_LBN));
  61. /* RX FIFO XOFF watermark
  62. *
  63. * When the amount of the RX FIFO increases used increases past this
  64. * watermark send XOFF. Only used if RX flow control is enabled (ethtool -A)
  65. * This also has an effect on RX/TX arbitration
  66. */
  67. static int rx_xoff_thresh_bytes = -1;
  68. module_param(rx_xoff_thresh_bytes, int, 0644);
  69. MODULE_PARM_DESC(rx_xoff_thresh_bytes, "RX fifo XOFF threshold");
  70. /* RX FIFO XON watermark
  71. *
  72. * When the amount of the RX FIFO used decreases below this
  73. * watermark send XON. Only used if TX flow control is enabled (ethtool -A)
  74. * This also has an effect on RX/TX arbitration
  75. */
  76. static int rx_xon_thresh_bytes = -1;
  77. module_param(rx_xon_thresh_bytes, int, 0644);
  78. MODULE_PARM_DESC(rx_xon_thresh_bytes, "RX fifo XON threshold");
  79. /* If FALCON_MAX_INT_ERRORS internal errors occur within
  80. * FALCON_INT_ERROR_EXPIRE seconds, we consider the NIC broken and
  81. * disable it.
  82. */
  83. #define FALCON_INT_ERROR_EXPIRE 3600
  84. #define FALCON_MAX_INT_ERRORS 5
  85. /* We poll for events every FLUSH_INTERVAL ms, and check FLUSH_POLL_COUNT times
  86. */
  87. #define FALCON_FLUSH_INTERVAL 10
  88. #define FALCON_FLUSH_POLL_COUNT 100
  89. /**************************************************************************
  90. *
  91. * Falcon constants
  92. *
  93. **************************************************************************
  94. */
  95. /* Size and alignment of special buffers (4KB) */
  96. #define FALCON_BUF_SIZE 4096
  97. /* Depth of RX flush request fifo */
  98. #define FALCON_RX_FLUSH_COUNT 4
  99. #define FALCON_IS_DUAL_FUNC(efx) \
  100. (falcon_rev(efx) < FALCON_REV_B0)
  101. /**************************************************************************
  102. *
  103. * Falcon hardware access
  104. *
  105. **************************************************************************/
  106. static inline void falcon_write_buf_tbl(struct efx_nic *efx, efx_qword_t *value,
  107. unsigned int index)
  108. {
  109. efx_sram_writeq(efx, efx->membase + efx->type->buf_tbl_base,
  110. value, index);
  111. }
  112. /* Read the current event from the event queue */
  113. static inline efx_qword_t *falcon_event(struct efx_channel *channel,
  114. unsigned int index)
  115. {
  116. return (((efx_qword_t *) (channel->eventq.addr)) + index);
  117. }
  118. /* See if an event is present
  119. *
  120. * We check both the high and low dword of the event for all ones. We
  121. * wrote all ones when we cleared the event, and no valid event can
  122. * have all ones in either its high or low dwords. This approach is
  123. * robust against reordering.
  124. *
  125. * Note that using a single 64-bit comparison is incorrect; even
  126. * though the CPU read will be atomic, the DMA write may not be.
  127. */
  128. static inline int falcon_event_present(efx_qword_t *event)
  129. {
  130. return (!(EFX_DWORD_IS_ALL_ONES(event->dword[0]) |
  131. EFX_DWORD_IS_ALL_ONES(event->dword[1])));
  132. }
  133. /**************************************************************************
  134. *
  135. * I2C bus - this is a bit-bashing interface using GPIO pins
  136. * Note that it uses the output enables to tristate the outputs
  137. * SDA is the data pin and SCL is the clock
  138. *
  139. **************************************************************************
  140. */
  141. static void falcon_setsda(void *data, int state)
  142. {
  143. struct efx_nic *efx = (struct efx_nic *)data;
  144. efx_oword_t reg;
  145. efx_reado(efx, &reg, FR_AB_GPIO_CTL);
  146. EFX_SET_OWORD_FIELD(reg, FRF_AB_GPIO3_OEN, !state);
  147. efx_writeo(efx, &reg, FR_AB_GPIO_CTL);
  148. }
  149. static void falcon_setscl(void *data, int state)
  150. {
  151. struct efx_nic *efx = (struct efx_nic *)data;
  152. efx_oword_t reg;
  153. efx_reado(efx, &reg, FR_AB_GPIO_CTL);
  154. EFX_SET_OWORD_FIELD(reg, FRF_AB_GPIO0_OEN, !state);
  155. efx_writeo(efx, &reg, FR_AB_GPIO_CTL);
  156. }
  157. static int falcon_getsda(void *data)
  158. {
  159. struct efx_nic *efx = (struct efx_nic *)data;
  160. efx_oword_t reg;
  161. efx_reado(efx, &reg, FR_AB_GPIO_CTL);
  162. return EFX_OWORD_FIELD(reg, FRF_AB_GPIO3_IN);
  163. }
  164. static int falcon_getscl(void *data)
  165. {
  166. struct efx_nic *efx = (struct efx_nic *)data;
  167. efx_oword_t reg;
  168. efx_reado(efx, &reg, FR_AB_GPIO_CTL);
  169. return EFX_OWORD_FIELD(reg, FRF_AB_GPIO0_IN);
  170. }
  171. static struct i2c_algo_bit_data falcon_i2c_bit_operations = {
  172. .setsda = falcon_setsda,
  173. .setscl = falcon_setscl,
  174. .getsda = falcon_getsda,
  175. .getscl = falcon_getscl,
  176. .udelay = 5,
  177. /* Wait up to 50 ms for slave to let us pull SCL high */
  178. .timeout = DIV_ROUND_UP(HZ, 20),
  179. };
  180. /**************************************************************************
  181. *
  182. * Falcon special buffer handling
  183. * Special buffers are used for event queues and the TX and RX
  184. * descriptor rings.
  185. *
  186. *************************************************************************/
  187. /*
  188. * Initialise a Falcon special buffer
  189. *
  190. * This will define a buffer (previously allocated via
  191. * falcon_alloc_special_buffer()) in Falcon's buffer table, allowing
  192. * it to be used for event queues, descriptor rings etc.
  193. */
  194. static void
  195. falcon_init_special_buffer(struct efx_nic *efx,
  196. struct efx_special_buffer *buffer)
  197. {
  198. efx_qword_t buf_desc;
  199. int index;
  200. dma_addr_t dma_addr;
  201. int i;
  202. EFX_BUG_ON_PARANOID(!buffer->addr);
  203. /* Write buffer descriptors to NIC */
  204. for (i = 0; i < buffer->entries; i++) {
  205. index = buffer->index + i;
  206. dma_addr = buffer->dma_addr + (i * 4096);
  207. EFX_LOG(efx, "mapping special buffer %d at %llx\n",
  208. index, (unsigned long long)dma_addr);
  209. EFX_POPULATE_QWORD_3(buf_desc,
  210. FRF_AZ_BUF_ADR_REGION, 0,
  211. FRF_AZ_BUF_ADR_FBUF, dma_addr >> 12,
  212. FRF_AZ_BUF_OWNER_ID_FBUF, 0);
  213. falcon_write_buf_tbl(efx, &buf_desc, index);
  214. }
  215. }
  216. /* Unmaps a buffer from Falcon and clears the buffer table entries */
  217. static void
  218. falcon_fini_special_buffer(struct efx_nic *efx,
  219. struct efx_special_buffer *buffer)
  220. {
  221. efx_oword_t buf_tbl_upd;
  222. unsigned int start = buffer->index;
  223. unsigned int end = (buffer->index + buffer->entries - 1);
  224. if (!buffer->entries)
  225. return;
  226. EFX_LOG(efx, "unmapping special buffers %d-%d\n",
  227. buffer->index, buffer->index + buffer->entries - 1);
  228. EFX_POPULATE_OWORD_4(buf_tbl_upd,
  229. FRF_AZ_BUF_UPD_CMD, 0,
  230. FRF_AZ_BUF_CLR_CMD, 1,
  231. FRF_AZ_BUF_CLR_END_ID, end,
  232. FRF_AZ_BUF_CLR_START_ID, start);
  233. efx_writeo(efx, &buf_tbl_upd, FR_AZ_BUF_TBL_UPD);
  234. }
  235. /*
  236. * Allocate a new Falcon special buffer
  237. *
  238. * This allocates memory for a new buffer, clears it and allocates a
  239. * new buffer ID range. It does not write into Falcon's buffer table.
  240. *
  241. * This call will allocate 4KB buffers, since Falcon can't use 8KB
  242. * buffers for event queues and descriptor rings.
  243. */
  244. static int falcon_alloc_special_buffer(struct efx_nic *efx,
  245. struct efx_special_buffer *buffer,
  246. unsigned int len)
  247. {
  248. len = ALIGN(len, FALCON_BUF_SIZE);
  249. buffer->addr = pci_alloc_consistent(efx->pci_dev, len,
  250. &buffer->dma_addr);
  251. if (!buffer->addr)
  252. return -ENOMEM;
  253. buffer->len = len;
  254. buffer->entries = len / FALCON_BUF_SIZE;
  255. BUG_ON(buffer->dma_addr & (FALCON_BUF_SIZE - 1));
  256. /* All zeros is a potentially valid event so memset to 0xff */
  257. memset(buffer->addr, 0xff, len);
  258. /* Select new buffer ID */
  259. buffer->index = efx->next_buffer_table;
  260. efx->next_buffer_table += buffer->entries;
  261. EFX_LOG(efx, "allocating special buffers %d-%d at %llx+%x "
  262. "(virt %p phys %llx)\n", buffer->index,
  263. buffer->index + buffer->entries - 1,
  264. (u64)buffer->dma_addr, len,
  265. buffer->addr, (u64)virt_to_phys(buffer->addr));
  266. return 0;
  267. }
  268. static void falcon_free_special_buffer(struct efx_nic *efx,
  269. struct efx_special_buffer *buffer)
  270. {
  271. if (!buffer->addr)
  272. return;
  273. EFX_LOG(efx, "deallocating special buffers %d-%d at %llx+%x "
  274. "(virt %p phys %llx)\n", buffer->index,
  275. buffer->index + buffer->entries - 1,
  276. (u64)buffer->dma_addr, buffer->len,
  277. buffer->addr, (u64)virt_to_phys(buffer->addr));
  278. pci_free_consistent(efx->pci_dev, buffer->len, buffer->addr,
  279. buffer->dma_addr);
  280. buffer->addr = NULL;
  281. buffer->entries = 0;
  282. }
  283. /**************************************************************************
  284. *
  285. * Falcon generic buffer handling
  286. * These buffers are used for interrupt status and MAC stats
  287. *
  288. **************************************************************************/
  289. static int falcon_alloc_buffer(struct efx_nic *efx,
  290. struct efx_buffer *buffer, unsigned int len)
  291. {
  292. buffer->addr = pci_alloc_consistent(efx->pci_dev, len,
  293. &buffer->dma_addr);
  294. if (!buffer->addr)
  295. return -ENOMEM;
  296. buffer->len = len;
  297. memset(buffer->addr, 0, len);
  298. return 0;
  299. }
  300. static void falcon_free_buffer(struct efx_nic *efx, struct efx_buffer *buffer)
  301. {
  302. if (buffer->addr) {
  303. pci_free_consistent(efx->pci_dev, buffer->len,
  304. buffer->addr, buffer->dma_addr);
  305. buffer->addr = NULL;
  306. }
  307. }
  308. /**************************************************************************
  309. *
  310. * Falcon TX path
  311. *
  312. **************************************************************************/
  313. /* Returns a pointer to the specified transmit descriptor in the TX
  314. * descriptor queue belonging to the specified channel.
  315. */
  316. static inline efx_qword_t *falcon_tx_desc(struct efx_tx_queue *tx_queue,
  317. unsigned int index)
  318. {
  319. return (((efx_qword_t *) (tx_queue->txd.addr)) + index);
  320. }
  321. /* This writes to the TX_DESC_WPTR; write pointer for TX descriptor ring */
  322. static inline void falcon_notify_tx_desc(struct efx_tx_queue *tx_queue)
  323. {
  324. unsigned write_ptr;
  325. efx_dword_t reg;
  326. write_ptr = tx_queue->write_count & EFX_TXQ_MASK;
  327. EFX_POPULATE_DWORD_1(reg, FRF_AZ_TX_DESC_WPTR_DWORD, write_ptr);
  328. efx_writed_page(tx_queue->efx, &reg,
  329. FR_AZ_TX_DESC_UPD_DWORD_P0, tx_queue->queue);
  330. }
  331. /* For each entry inserted into the software descriptor ring, create a
  332. * descriptor in the hardware TX descriptor ring (in host memory), and
  333. * write a doorbell.
  334. */
  335. void falcon_push_buffers(struct efx_tx_queue *tx_queue)
  336. {
  337. struct efx_tx_buffer *buffer;
  338. efx_qword_t *txd;
  339. unsigned write_ptr;
  340. BUG_ON(tx_queue->write_count == tx_queue->insert_count);
  341. do {
  342. write_ptr = tx_queue->write_count & EFX_TXQ_MASK;
  343. buffer = &tx_queue->buffer[write_ptr];
  344. txd = falcon_tx_desc(tx_queue, write_ptr);
  345. ++tx_queue->write_count;
  346. /* Create TX descriptor ring entry */
  347. EFX_POPULATE_QWORD_4(*txd,
  348. FSF_AZ_TX_KER_CONT, buffer->continuation,
  349. FSF_AZ_TX_KER_BYTE_COUNT, buffer->len,
  350. FSF_AZ_TX_KER_BUF_REGION, 0,
  351. FSF_AZ_TX_KER_BUF_ADDR, buffer->dma_addr);
  352. } while (tx_queue->write_count != tx_queue->insert_count);
  353. wmb(); /* Ensure descriptors are written before they are fetched */
  354. falcon_notify_tx_desc(tx_queue);
  355. }
  356. /* Allocate hardware resources for a TX queue */
  357. int falcon_probe_tx(struct efx_tx_queue *tx_queue)
  358. {
  359. struct efx_nic *efx = tx_queue->efx;
  360. BUILD_BUG_ON(EFX_TXQ_SIZE < 512 || EFX_TXQ_SIZE > 4096 ||
  361. EFX_TXQ_SIZE & EFX_TXQ_MASK);
  362. return falcon_alloc_special_buffer(efx, &tx_queue->txd,
  363. EFX_TXQ_SIZE * sizeof(efx_qword_t));
  364. }
  365. void falcon_init_tx(struct efx_tx_queue *tx_queue)
  366. {
  367. efx_oword_t tx_desc_ptr;
  368. struct efx_nic *efx = tx_queue->efx;
  369. tx_queue->flushed = FLUSH_NONE;
  370. /* Pin TX descriptor ring */
  371. falcon_init_special_buffer(efx, &tx_queue->txd);
  372. /* Push TX descriptor ring to card */
  373. EFX_POPULATE_OWORD_10(tx_desc_ptr,
  374. FRF_AZ_TX_DESCQ_EN, 1,
  375. FRF_AZ_TX_ISCSI_DDIG_EN, 0,
  376. FRF_AZ_TX_ISCSI_HDIG_EN, 0,
  377. FRF_AZ_TX_DESCQ_BUF_BASE_ID, tx_queue->txd.index,
  378. FRF_AZ_TX_DESCQ_EVQ_ID,
  379. tx_queue->channel->channel,
  380. FRF_AZ_TX_DESCQ_OWNER_ID, 0,
  381. FRF_AZ_TX_DESCQ_LABEL, tx_queue->queue,
  382. FRF_AZ_TX_DESCQ_SIZE,
  383. __ffs(tx_queue->txd.entries),
  384. FRF_AZ_TX_DESCQ_TYPE, 0,
  385. FRF_BZ_TX_NON_IP_DROP_DIS, 1);
  386. if (falcon_rev(efx) >= FALCON_REV_B0) {
  387. int csum = tx_queue->queue == EFX_TX_QUEUE_OFFLOAD_CSUM;
  388. EFX_SET_OWORD_FIELD(tx_desc_ptr, FRF_BZ_TX_IP_CHKSM_DIS, !csum);
  389. EFX_SET_OWORD_FIELD(tx_desc_ptr, FRF_BZ_TX_TCP_CHKSM_DIS,
  390. !csum);
  391. }
  392. efx_writeo_table(efx, &tx_desc_ptr, efx->type->txd_ptr_tbl_base,
  393. tx_queue->queue);
  394. if (falcon_rev(efx) < FALCON_REV_B0) {
  395. efx_oword_t reg;
  396. /* Only 128 bits in this register */
  397. BUILD_BUG_ON(EFX_TX_QUEUE_COUNT >= 128);
  398. efx_reado(efx, &reg, FR_AA_TX_CHKSM_CFG);
  399. if (tx_queue->queue == EFX_TX_QUEUE_OFFLOAD_CSUM)
  400. clear_bit_le(tx_queue->queue, (void *)&reg);
  401. else
  402. set_bit_le(tx_queue->queue, (void *)&reg);
  403. efx_writeo(efx, &reg, FR_AA_TX_CHKSM_CFG);
  404. }
  405. }
  406. static void falcon_flush_tx_queue(struct efx_tx_queue *tx_queue)
  407. {
  408. struct efx_nic *efx = tx_queue->efx;
  409. efx_oword_t tx_flush_descq;
  410. tx_queue->flushed = FLUSH_PENDING;
  411. /* Post a flush command */
  412. EFX_POPULATE_OWORD_2(tx_flush_descq,
  413. FRF_AZ_TX_FLUSH_DESCQ_CMD, 1,
  414. FRF_AZ_TX_FLUSH_DESCQ, tx_queue->queue);
  415. efx_writeo(efx, &tx_flush_descq, FR_AZ_TX_FLUSH_DESCQ);
  416. }
  417. void falcon_fini_tx(struct efx_tx_queue *tx_queue)
  418. {
  419. struct efx_nic *efx = tx_queue->efx;
  420. efx_oword_t tx_desc_ptr;
  421. /* The queue should have been flushed */
  422. WARN_ON(tx_queue->flushed != FLUSH_DONE);
  423. /* Remove TX descriptor ring from card */
  424. EFX_ZERO_OWORD(tx_desc_ptr);
  425. efx_writeo_table(efx, &tx_desc_ptr, efx->type->txd_ptr_tbl_base,
  426. tx_queue->queue);
  427. /* Unpin TX descriptor ring */
  428. falcon_fini_special_buffer(efx, &tx_queue->txd);
  429. }
  430. /* Free buffers backing TX queue */
  431. void falcon_remove_tx(struct efx_tx_queue *tx_queue)
  432. {
  433. falcon_free_special_buffer(tx_queue->efx, &tx_queue->txd);
  434. }
  435. /**************************************************************************
  436. *
  437. * Falcon RX path
  438. *
  439. **************************************************************************/
  440. /* Returns a pointer to the specified descriptor in the RX descriptor queue */
  441. static inline efx_qword_t *falcon_rx_desc(struct efx_rx_queue *rx_queue,
  442. unsigned int index)
  443. {
  444. return (((efx_qword_t *) (rx_queue->rxd.addr)) + index);
  445. }
  446. /* This creates an entry in the RX descriptor queue */
  447. static inline void falcon_build_rx_desc(struct efx_rx_queue *rx_queue,
  448. unsigned index)
  449. {
  450. struct efx_rx_buffer *rx_buf;
  451. efx_qword_t *rxd;
  452. rxd = falcon_rx_desc(rx_queue, index);
  453. rx_buf = efx_rx_buffer(rx_queue, index);
  454. EFX_POPULATE_QWORD_3(*rxd,
  455. FSF_AZ_RX_KER_BUF_SIZE,
  456. rx_buf->len -
  457. rx_queue->efx->type->rx_buffer_padding,
  458. FSF_AZ_RX_KER_BUF_REGION, 0,
  459. FSF_AZ_RX_KER_BUF_ADDR, rx_buf->dma_addr);
  460. }
  461. /* This writes to the RX_DESC_WPTR register for the specified receive
  462. * descriptor ring.
  463. */
  464. void falcon_notify_rx_desc(struct efx_rx_queue *rx_queue)
  465. {
  466. efx_dword_t reg;
  467. unsigned write_ptr;
  468. while (rx_queue->notified_count != rx_queue->added_count) {
  469. falcon_build_rx_desc(rx_queue,
  470. rx_queue->notified_count &
  471. EFX_RXQ_MASK);
  472. ++rx_queue->notified_count;
  473. }
  474. wmb();
  475. write_ptr = rx_queue->added_count & EFX_RXQ_MASK;
  476. EFX_POPULATE_DWORD_1(reg, FRF_AZ_RX_DESC_WPTR_DWORD, write_ptr);
  477. efx_writed_page(rx_queue->efx, &reg,
  478. FR_AZ_RX_DESC_UPD_DWORD_P0, rx_queue->queue);
  479. }
  480. int falcon_probe_rx(struct efx_rx_queue *rx_queue)
  481. {
  482. struct efx_nic *efx = rx_queue->efx;
  483. BUILD_BUG_ON(EFX_RXQ_SIZE < 512 || EFX_RXQ_SIZE > 4096 ||
  484. EFX_RXQ_SIZE & EFX_RXQ_MASK);
  485. return falcon_alloc_special_buffer(efx, &rx_queue->rxd,
  486. EFX_RXQ_SIZE * sizeof(efx_qword_t));
  487. }
  488. void falcon_init_rx(struct efx_rx_queue *rx_queue)
  489. {
  490. efx_oword_t rx_desc_ptr;
  491. struct efx_nic *efx = rx_queue->efx;
  492. bool is_b0 = falcon_rev(efx) >= FALCON_REV_B0;
  493. bool iscsi_digest_en = is_b0;
  494. EFX_LOG(efx, "RX queue %d ring in special buffers %d-%d\n",
  495. rx_queue->queue, rx_queue->rxd.index,
  496. rx_queue->rxd.index + rx_queue->rxd.entries - 1);
  497. rx_queue->flushed = FLUSH_NONE;
  498. /* Pin RX descriptor ring */
  499. falcon_init_special_buffer(efx, &rx_queue->rxd);
  500. /* Push RX descriptor ring to card */
  501. EFX_POPULATE_OWORD_10(rx_desc_ptr,
  502. FRF_AZ_RX_ISCSI_DDIG_EN, iscsi_digest_en,
  503. FRF_AZ_RX_ISCSI_HDIG_EN, iscsi_digest_en,
  504. FRF_AZ_RX_DESCQ_BUF_BASE_ID, rx_queue->rxd.index,
  505. FRF_AZ_RX_DESCQ_EVQ_ID,
  506. rx_queue->channel->channel,
  507. FRF_AZ_RX_DESCQ_OWNER_ID, 0,
  508. FRF_AZ_RX_DESCQ_LABEL, rx_queue->queue,
  509. FRF_AZ_RX_DESCQ_SIZE,
  510. __ffs(rx_queue->rxd.entries),
  511. FRF_AZ_RX_DESCQ_TYPE, 0 /* kernel queue */ ,
  512. /* For >=B0 this is scatter so disable */
  513. FRF_AZ_RX_DESCQ_JUMBO, !is_b0,
  514. FRF_AZ_RX_DESCQ_EN, 1);
  515. efx_writeo_table(efx, &rx_desc_ptr, efx->type->rxd_ptr_tbl_base,
  516. rx_queue->queue);
  517. }
  518. static void falcon_flush_rx_queue(struct efx_rx_queue *rx_queue)
  519. {
  520. struct efx_nic *efx = rx_queue->efx;
  521. efx_oword_t rx_flush_descq;
  522. rx_queue->flushed = FLUSH_PENDING;
  523. /* Post a flush command */
  524. EFX_POPULATE_OWORD_2(rx_flush_descq,
  525. FRF_AZ_RX_FLUSH_DESCQ_CMD, 1,
  526. FRF_AZ_RX_FLUSH_DESCQ, rx_queue->queue);
  527. efx_writeo(efx, &rx_flush_descq, FR_AZ_RX_FLUSH_DESCQ);
  528. }
  529. void falcon_fini_rx(struct efx_rx_queue *rx_queue)
  530. {
  531. efx_oword_t rx_desc_ptr;
  532. struct efx_nic *efx = rx_queue->efx;
  533. /* The queue should already have been flushed */
  534. WARN_ON(rx_queue->flushed != FLUSH_DONE);
  535. /* Remove RX descriptor ring from card */
  536. EFX_ZERO_OWORD(rx_desc_ptr);
  537. efx_writeo_table(efx, &rx_desc_ptr, efx->type->rxd_ptr_tbl_base,
  538. rx_queue->queue);
  539. /* Unpin RX descriptor ring */
  540. falcon_fini_special_buffer(efx, &rx_queue->rxd);
  541. }
  542. /* Free buffers backing RX queue */
  543. void falcon_remove_rx(struct efx_rx_queue *rx_queue)
  544. {
  545. falcon_free_special_buffer(rx_queue->efx, &rx_queue->rxd);
  546. }
  547. /**************************************************************************
  548. *
  549. * Falcon event queue processing
  550. * Event queues are processed by per-channel tasklets.
  551. *
  552. **************************************************************************/
  553. /* Update a channel's event queue's read pointer (RPTR) register
  554. *
  555. * This writes the EVQ_RPTR_REG register for the specified channel's
  556. * event queue.
  557. *
  558. * Note that EVQ_RPTR_REG contains the index of the "last read" event,
  559. * whereas channel->eventq_read_ptr contains the index of the "next to
  560. * read" event.
  561. */
  562. void falcon_eventq_read_ack(struct efx_channel *channel)
  563. {
  564. efx_dword_t reg;
  565. struct efx_nic *efx = channel->efx;
  566. EFX_POPULATE_DWORD_1(reg, FRF_AZ_EVQ_RPTR, channel->eventq_read_ptr);
  567. efx_writed_table(efx, &reg, efx->type->evq_rptr_tbl_base,
  568. channel->channel);
  569. }
  570. /* Use HW to insert a SW defined event */
  571. void falcon_generate_event(struct efx_channel *channel, efx_qword_t *event)
  572. {
  573. efx_oword_t drv_ev_reg;
  574. BUILD_BUG_ON(FRF_AZ_DRV_EV_DATA_LBN != 0 ||
  575. FRF_AZ_DRV_EV_DATA_WIDTH != 64);
  576. drv_ev_reg.u32[0] = event->u32[0];
  577. drv_ev_reg.u32[1] = event->u32[1];
  578. drv_ev_reg.u32[2] = 0;
  579. drv_ev_reg.u32[3] = 0;
  580. EFX_SET_OWORD_FIELD(drv_ev_reg, FRF_AZ_DRV_EV_QID, channel->channel);
  581. efx_writeo(channel->efx, &drv_ev_reg, FR_AZ_DRV_EV);
  582. }
  583. /* Handle a transmit completion event
  584. *
  585. * Falcon batches TX completion events; the message we receive is of
  586. * the form "complete all TX events up to this index".
  587. */
  588. static void falcon_handle_tx_event(struct efx_channel *channel,
  589. efx_qword_t *event)
  590. {
  591. unsigned int tx_ev_desc_ptr;
  592. unsigned int tx_ev_q_label;
  593. struct efx_tx_queue *tx_queue;
  594. struct efx_nic *efx = channel->efx;
  595. if (likely(EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_COMP))) {
  596. /* Transmit completion */
  597. tx_ev_desc_ptr = EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_DESC_PTR);
  598. tx_ev_q_label = EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_Q_LABEL);
  599. tx_queue = &efx->tx_queue[tx_ev_q_label];
  600. channel->irq_mod_score +=
  601. (tx_ev_desc_ptr - tx_queue->read_count) &
  602. EFX_TXQ_MASK;
  603. efx_xmit_done(tx_queue, tx_ev_desc_ptr);
  604. } else if (EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_WQ_FF_FULL)) {
  605. /* Rewrite the FIFO write pointer */
  606. tx_ev_q_label = EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_Q_LABEL);
  607. tx_queue = &efx->tx_queue[tx_ev_q_label];
  608. if (efx_dev_registered(efx))
  609. netif_tx_lock(efx->net_dev);
  610. falcon_notify_tx_desc(tx_queue);
  611. if (efx_dev_registered(efx))
  612. netif_tx_unlock(efx->net_dev);
  613. } else if (EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_PKT_ERR) &&
  614. EFX_WORKAROUND_10727(efx)) {
  615. efx_schedule_reset(efx, RESET_TYPE_TX_DESC_FETCH);
  616. } else {
  617. EFX_ERR(efx, "channel %d unexpected TX event "
  618. EFX_QWORD_FMT"\n", channel->channel,
  619. EFX_QWORD_VAL(*event));
  620. }
  621. }
  622. /* Detect errors included in the rx_evt_pkt_ok bit. */
  623. static void falcon_handle_rx_not_ok(struct efx_rx_queue *rx_queue,
  624. const efx_qword_t *event,
  625. bool *rx_ev_pkt_ok,
  626. bool *discard)
  627. {
  628. struct efx_nic *efx = rx_queue->efx;
  629. bool rx_ev_buf_owner_id_err, rx_ev_ip_hdr_chksum_err;
  630. bool rx_ev_tcp_udp_chksum_err, rx_ev_eth_crc_err;
  631. bool rx_ev_frm_trunc, rx_ev_drib_nib, rx_ev_tobe_disc;
  632. bool rx_ev_other_err, rx_ev_pause_frm;
  633. bool rx_ev_ip_frag_err, rx_ev_hdr_type, rx_ev_mcast_pkt;
  634. unsigned rx_ev_pkt_type;
  635. rx_ev_hdr_type = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_HDR_TYPE);
  636. rx_ev_mcast_pkt = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_MCAST_PKT);
  637. rx_ev_tobe_disc = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_TOBE_DISC);
  638. rx_ev_pkt_type = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_PKT_TYPE);
  639. rx_ev_buf_owner_id_err = EFX_QWORD_FIELD(*event,
  640. FSF_AZ_RX_EV_BUF_OWNER_ID_ERR);
  641. rx_ev_ip_frag_err = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_IP_FRAG_ERR);
  642. rx_ev_ip_hdr_chksum_err = EFX_QWORD_FIELD(*event,
  643. FSF_AZ_RX_EV_IP_HDR_CHKSUM_ERR);
  644. rx_ev_tcp_udp_chksum_err = EFX_QWORD_FIELD(*event,
  645. FSF_AZ_RX_EV_TCP_UDP_CHKSUM_ERR);
  646. rx_ev_eth_crc_err = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_ETH_CRC_ERR);
  647. rx_ev_frm_trunc = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_FRM_TRUNC);
  648. rx_ev_drib_nib = ((falcon_rev(efx) >= FALCON_REV_B0) ?
  649. 0 : EFX_QWORD_FIELD(*event, FSF_AA_RX_EV_DRIB_NIB));
  650. rx_ev_pause_frm = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_PAUSE_FRM_ERR);
  651. /* Every error apart from tobe_disc and pause_frm */
  652. rx_ev_other_err = (rx_ev_drib_nib | rx_ev_tcp_udp_chksum_err |
  653. rx_ev_buf_owner_id_err | rx_ev_eth_crc_err |
  654. rx_ev_frm_trunc | rx_ev_ip_hdr_chksum_err);
  655. /* Count errors that are not in MAC stats. Ignore expected
  656. * checksum errors during self-test. */
  657. if (rx_ev_frm_trunc)
  658. ++rx_queue->channel->n_rx_frm_trunc;
  659. else if (rx_ev_tobe_disc)
  660. ++rx_queue->channel->n_rx_tobe_disc;
  661. else if (!efx->loopback_selftest) {
  662. if (rx_ev_ip_hdr_chksum_err)
  663. ++rx_queue->channel->n_rx_ip_hdr_chksum_err;
  664. else if (rx_ev_tcp_udp_chksum_err)
  665. ++rx_queue->channel->n_rx_tcp_udp_chksum_err;
  666. }
  667. if (rx_ev_ip_frag_err)
  668. ++rx_queue->channel->n_rx_ip_frag_err;
  669. /* The frame must be discarded if any of these are true. */
  670. *discard = (rx_ev_eth_crc_err | rx_ev_frm_trunc | rx_ev_drib_nib |
  671. rx_ev_tobe_disc | rx_ev_pause_frm);
  672. /* TOBE_DISC is expected on unicast mismatches; don't print out an
  673. * error message. FRM_TRUNC indicates RXDP dropped the packet due
  674. * to a FIFO overflow.
  675. */
  676. #ifdef EFX_ENABLE_DEBUG
  677. if (rx_ev_other_err) {
  678. EFX_INFO_RL(efx, " RX queue %d unexpected RX event "
  679. EFX_QWORD_FMT "%s%s%s%s%s%s%s%s\n",
  680. rx_queue->queue, EFX_QWORD_VAL(*event),
  681. rx_ev_buf_owner_id_err ? " [OWNER_ID_ERR]" : "",
  682. rx_ev_ip_hdr_chksum_err ?
  683. " [IP_HDR_CHKSUM_ERR]" : "",
  684. rx_ev_tcp_udp_chksum_err ?
  685. " [TCP_UDP_CHKSUM_ERR]" : "",
  686. rx_ev_eth_crc_err ? " [ETH_CRC_ERR]" : "",
  687. rx_ev_frm_trunc ? " [FRM_TRUNC]" : "",
  688. rx_ev_drib_nib ? " [DRIB_NIB]" : "",
  689. rx_ev_tobe_disc ? " [TOBE_DISC]" : "",
  690. rx_ev_pause_frm ? " [PAUSE]" : "");
  691. }
  692. #endif
  693. }
  694. /* Handle receive events that are not in-order. */
  695. static void falcon_handle_rx_bad_index(struct efx_rx_queue *rx_queue,
  696. unsigned index)
  697. {
  698. struct efx_nic *efx = rx_queue->efx;
  699. unsigned expected, dropped;
  700. expected = rx_queue->removed_count & EFX_RXQ_MASK;
  701. dropped = (index - expected) & EFX_RXQ_MASK;
  702. EFX_INFO(efx, "dropped %d events (index=%d expected=%d)\n",
  703. dropped, index, expected);
  704. efx_schedule_reset(efx, EFX_WORKAROUND_5676(efx) ?
  705. RESET_TYPE_RX_RECOVERY : RESET_TYPE_DISABLE);
  706. }
  707. /* Handle a packet received event
  708. *
  709. * Falcon silicon gives a "discard" flag if it's a unicast packet with the
  710. * wrong destination address
  711. * Also "is multicast" and "matches multicast filter" flags can be used to
  712. * discard non-matching multicast packets.
  713. */
  714. static void falcon_handle_rx_event(struct efx_channel *channel,
  715. const efx_qword_t *event)
  716. {
  717. unsigned int rx_ev_desc_ptr, rx_ev_byte_cnt;
  718. unsigned int rx_ev_hdr_type, rx_ev_mcast_pkt;
  719. unsigned expected_ptr;
  720. bool rx_ev_pkt_ok, discard = false, checksummed;
  721. struct efx_rx_queue *rx_queue;
  722. struct efx_nic *efx = channel->efx;
  723. /* Basic packet information */
  724. rx_ev_byte_cnt = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_BYTE_CNT);
  725. rx_ev_pkt_ok = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_PKT_OK);
  726. rx_ev_hdr_type = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_HDR_TYPE);
  727. WARN_ON(EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_JUMBO_CONT));
  728. WARN_ON(EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_SOP) != 1);
  729. WARN_ON(EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_Q_LABEL) !=
  730. channel->channel);
  731. rx_queue = &efx->rx_queue[channel->channel];
  732. rx_ev_desc_ptr = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_DESC_PTR);
  733. expected_ptr = rx_queue->removed_count & EFX_RXQ_MASK;
  734. if (unlikely(rx_ev_desc_ptr != expected_ptr))
  735. falcon_handle_rx_bad_index(rx_queue, rx_ev_desc_ptr);
  736. if (likely(rx_ev_pkt_ok)) {
  737. /* If packet is marked as OK and packet type is TCP/IPv4 or
  738. * UDP/IPv4, then we can rely on the hardware checksum.
  739. */
  740. checksummed =
  741. efx->rx_checksum_enabled &&
  742. (rx_ev_hdr_type == FSE_AB_RX_EV_HDR_TYPE_IPV4_TCP ||
  743. rx_ev_hdr_type == FSE_AB_RX_EV_HDR_TYPE_IPV4_UDP);
  744. } else {
  745. falcon_handle_rx_not_ok(rx_queue, event, &rx_ev_pkt_ok,
  746. &discard);
  747. checksummed = false;
  748. }
  749. /* Detect multicast packets that didn't match the filter */
  750. rx_ev_mcast_pkt = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_MCAST_PKT);
  751. if (rx_ev_mcast_pkt) {
  752. unsigned int rx_ev_mcast_hash_match =
  753. EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_MCAST_HASH_MATCH);
  754. if (unlikely(!rx_ev_mcast_hash_match))
  755. discard = true;
  756. }
  757. channel->irq_mod_score += 2;
  758. /* Handle received packet */
  759. efx_rx_packet(rx_queue, rx_ev_desc_ptr, rx_ev_byte_cnt,
  760. checksummed, discard);
  761. }
  762. /* Global events are basically PHY events */
  763. static void falcon_handle_global_event(struct efx_channel *channel,
  764. efx_qword_t *event)
  765. {
  766. struct efx_nic *efx = channel->efx;
  767. bool handled = false;
  768. if (EFX_QWORD_FIELD(*event, FSF_AB_GLB_EV_G_PHY0_INTR) ||
  769. EFX_QWORD_FIELD(*event, FSF_AB_GLB_EV_XG_PHY0_INTR) ||
  770. EFX_QWORD_FIELD(*event, FSF_AB_GLB_EV_XFP_PHY0_INTR)) {
  771. /* Ignored */
  772. handled = true;
  773. }
  774. if ((falcon_rev(efx) >= FALCON_REV_B0) &&
  775. EFX_QWORD_FIELD(*event, FSF_BB_GLB_EV_XG_MGT_INTR)) {
  776. efx->xmac_poll_required = true;
  777. handled = true;
  778. }
  779. if (falcon_rev(efx) <= FALCON_REV_A1 ?
  780. EFX_QWORD_FIELD(*event, FSF_AA_GLB_EV_RX_RECOVERY) :
  781. EFX_QWORD_FIELD(*event, FSF_BB_GLB_EV_RX_RECOVERY)) {
  782. EFX_ERR(efx, "channel %d seen global RX_RESET "
  783. "event. Resetting.\n", channel->channel);
  784. atomic_inc(&efx->rx_reset);
  785. efx_schedule_reset(efx, EFX_WORKAROUND_6555(efx) ?
  786. RESET_TYPE_RX_RECOVERY : RESET_TYPE_DISABLE);
  787. handled = true;
  788. }
  789. if (!handled)
  790. EFX_ERR(efx, "channel %d unknown global event "
  791. EFX_QWORD_FMT "\n", channel->channel,
  792. EFX_QWORD_VAL(*event));
  793. }
  794. static void falcon_handle_driver_event(struct efx_channel *channel,
  795. efx_qword_t *event)
  796. {
  797. struct efx_nic *efx = channel->efx;
  798. unsigned int ev_sub_code;
  799. unsigned int ev_sub_data;
  800. ev_sub_code = EFX_QWORD_FIELD(*event, FSF_AZ_DRIVER_EV_SUBCODE);
  801. ev_sub_data = EFX_QWORD_FIELD(*event, FSF_AZ_DRIVER_EV_SUBDATA);
  802. switch (ev_sub_code) {
  803. case FSE_AZ_TX_DESCQ_FLS_DONE_EV:
  804. EFX_TRACE(efx, "channel %d TXQ %d flushed\n",
  805. channel->channel, ev_sub_data);
  806. break;
  807. case FSE_AZ_RX_DESCQ_FLS_DONE_EV:
  808. EFX_TRACE(efx, "channel %d RXQ %d flushed\n",
  809. channel->channel, ev_sub_data);
  810. break;
  811. case FSE_AZ_EVQ_INIT_DONE_EV:
  812. EFX_LOG(efx, "channel %d EVQ %d initialised\n",
  813. channel->channel, ev_sub_data);
  814. break;
  815. case FSE_AZ_SRM_UPD_DONE_EV:
  816. EFX_TRACE(efx, "channel %d SRAM update done\n",
  817. channel->channel);
  818. break;
  819. case FSE_AZ_WAKE_UP_EV:
  820. EFX_TRACE(efx, "channel %d RXQ %d wakeup event\n",
  821. channel->channel, ev_sub_data);
  822. break;
  823. case FSE_AZ_TIMER_EV:
  824. EFX_TRACE(efx, "channel %d RX queue %d timer expired\n",
  825. channel->channel, ev_sub_data);
  826. break;
  827. case FSE_AA_RX_RECOVER_EV:
  828. EFX_ERR(efx, "channel %d seen DRIVER RX_RESET event. "
  829. "Resetting.\n", channel->channel);
  830. atomic_inc(&efx->rx_reset);
  831. efx_schedule_reset(efx,
  832. EFX_WORKAROUND_6555(efx) ?
  833. RESET_TYPE_RX_RECOVERY :
  834. RESET_TYPE_DISABLE);
  835. break;
  836. case FSE_BZ_RX_DSC_ERROR_EV:
  837. EFX_ERR(efx, "RX DMA Q %d reports descriptor fetch error."
  838. " RX Q %d is disabled.\n", ev_sub_data, ev_sub_data);
  839. efx_schedule_reset(efx, RESET_TYPE_RX_DESC_FETCH);
  840. break;
  841. case FSE_BZ_TX_DSC_ERROR_EV:
  842. EFX_ERR(efx, "TX DMA Q %d reports descriptor fetch error."
  843. " TX Q %d is disabled.\n", ev_sub_data, ev_sub_data);
  844. efx_schedule_reset(efx, RESET_TYPE_TX_DESC_FETCH);
  845. break;
  846. default:
  847. EFX_TRACE(efx, "channel %d unknown driver event code %d "
  848. "data %04x\n", channel->channel, ev_sub_code,
  849. ev_sub_data);
  850. break;
  851. }
  852. }
  853. int falcon_process_eventq(struct efx_channel *channel, int rx_quota)
  854. {
  855. unsigned int read_ptr;
  856. efx_qword_t event, *p_event;
  857. int ev_code;
  858. int rx_packets = 0;
  859. read_ptr = channel->eventq_read_ptr;
  860. do {
  861. p_event = falcon_event(channel, read_ptr);
  862. event = *p_event;
  863. if (!falcon_event_present(&event))
  864. /* End of events */
  865. break;
  866. EFX_TRACE(channel->efx, "channel %d event is "EFX_QWORD_FMT"\n",
  867. channel->channel, EFX_QWORD_VAL(event));
  868. /* Clear this event by marking it all ones */
  869. EFX_SET_QWORD(*p_event);
  870. ev_code = EFX_QWORD_FIELD(event, FSF_AZ_EV_CODE);
  871. switch (ev_code) {
  872. case FSE_AZ_EV_CODE_RX_EV:
  873. falcon_handle_rx_event(channel, &event);
  874. ++rx_packets;
  875. break;
  876. case FSE_AZ_EV_CODE_TX_EV:
  877. falcon_handle_tx_event(channel, &event);
  878. break;
  879. case FSE_AZ_EV_CODE_DRV_GEN_EV:
  880. channel->eventq_magic = EFX_QWORD_FIELD(
  881. event, FSF_AZ_DRV_GEN_EV_MAGIC);
  882. EFX_LOG(channel->efx, "channel %d received generated "
  883. "event "EFX_QWORD_FMT"\n", channel->channel,
  884. EFX_QWORD_VAL(event));
  885. break;
  886. case FSE_AZ_EV_CODE_GLOBAL_EV:
  887. falcon_handle_global_event(channel, &event);
  888. break;
  889. case FSE_AZ_EV_CODE_DRIVER_EV:
  890. falcon_handle_driver_event(channel, &event);
  891. break;
  892. default:
  893. EFX_ERR(channel->efx, "channel %d unknown event type %d"
  894. " (data " EFX_QWORD_FMT ")\n", channel->channel,
  895. ev_code, EFX_QWORD_VAL(event));
  896. }
  897. /* Increment read pointer */
  898. read_ptr = (read_ptr + 1) & EFX_EVQ_MASK;
  899. } while (rx_packets < rx_quota);
  900. channel->eventq_read_ptr = read_ptr;
  901. return rx_packets;
  902. }
  903. void falcon_set_int_moderation(struct efx_channel *channel)
  904. {
  905. efx_dword_t timer_cmd;
  906. struct efx_nic *efx = channel->efx;
  907. /* Set timer register */
  908. if (channel->irq_moderation) {
  909. EFX_POPULATE_DWORD_2(timer_cmd,
  910. FRF_AB_TC_TIMER_MODE,
  911. FFE_BB_TIMER_MODE_INT_HLDOFF,
  912. FRF_AB_TC_TIMER_VAL,
  913. channel->irq_moderation - 1);
  914. } else {
  915. EFX_POPULATE_DWORD_2(timer_cmd,
  916. FRF_AB_TC_TIMER_MODE,
  917. FFE_BB_TIMER_MODE_DIS,
  918. FRF_AB_TC_TIMER_VAL, 0);
  919. }
  920. BUILD_BUG_ON(FR_AA_TIMER_COMMAND_KER != FR_BZ_TIMER_COMMAND_P0);
  921. efx_writed_page_locked(efx, &timer_cmd, FR_BZ_TIMER_COMMAND_P0,
  922. channel->channel);
  923. }
  924. /* Allocate buffer table entries for event queue */
  925. int falcon_probe_eventq(struct efx_channel *channel)
  926. {
  927. struct efx_nic *efx = channel->efx;
  928. BUILD_BUG_ON(EFX_EVQ_SIZE < 512 || EFX_EVQ_SIZE > 32768 ||
  929. EFX_EVQ_SIZE & EFX_EVQ_MASK);
  930. return falcon_alloc_special_buffer(efx, &channel->eventq,
  931. EFX_EVQ_SIZE * sizeof(efx_qword_t));
  932. }
  933. void falcon_init_eventq(struct efx_channel *channel)
  934. {
  935. efx_oword_t evq_ptr;
  936. struct efx_nic *efx = channel->efx;
  937. EFX_LOG(efx, "channel %d event queue in special buffers %d-%d\n",
  938. channel->channel, channel->eventq.index,
  939. channel->eventq.index + channel->eventq.entries - 1);
  940. /* Pin event queue buffer */
  941. falcon_init_special_buffer(efx, &channel->eventq);
  942. /* Fill event queue with all ones (i.e. empty events) */
  943. memset(channel->eventq.addr, 0xff, channel->eventq.len);
  944. /* Push event queue to card */
  945. EFX_POPULATE_OWORD_3(evq_ptr,
  946. FRF_AZ_EVQ_EN, 1,
  947. FRF_AZ_EVQ_SIZE, __ffs(channel->eventq.entries),
  948. FRF_AZ_EVQ_BUF_BASE_ID, channel->eventq.index);
  949. efx_writeo_table(efx, &evq_ptr, efx->type->evq_ptr_tbl_base,
  950. channel->channel);
  951. falcon_set_int_moderation(channel);
  952. }
  953. void falcon_fini_eventq(struct efx_channel *channel)
  954. {
  955. efx_oword_t eventq_ptr;
  956. struct efx_nic *efx = channel->efx;
  957. /* Remove event queue from card */
  958. EFX_ZERO_OWORD(eventq_ptr);
  959. efx_writeo_table(efx, &eventq_ptr, efx->type->evq_ptr_tbl_base,
  960. channel->channel);
  961. /* Unpin event queue */
  962. falcon_fini_special_buffer(efx, &channel->eventq);
  963. }
  964. /* Free buffers backing event queue */
  965. void falcon_remove_eventq(struct efx_channel *channel)
  966. {
  967. falcon_free_special_buffer(channel->efx, &channel->eventq);
  968. }
  969. /* Generates a test event on the event queue. A subsequent call to
  970. * process_eventq() should pick up the event and place the value of
  971. * "magic" into channel->eventq_magic;
  972. */
  973. void falcon_generate_test_event(struct efx_channel *channel, unsigned int magic)
  974. {
  975. efx_qword_t test_event;
  976. EFX_POPULATE_QWORD_2(test_event, FSF_AZ_EV_CODE,
  977. FSE_AZ_EV_CODE_DRV_GEN_EV,
  978. FSF_AZ_DRV_GEN_EV_MAGIC, magic);
  979. falcon_generate_event(channel, &test_event);
  980. }
  981. /**************************************************************************
  982. *
  983. * Flush handling
  984. *
  985. **************************************************************************/
  986. static void falcon_poll_flush_events(struct efx_nic *efx)
  987. {
  988. struct efx_channel *channel = &efx->channel[0];
  989. struct efx_tx_queue *tx_queue;
  990. struct efx_rx_queue *rx_queue;
  991. unsigned int read_ptr = channel->eventq_read_ptr;
  992. unsigned int end_ptr = (read_ptr - 1) & EFX_EVQ_MASK;
  993. do {
  994. efx_qword_t *event = falcon_event(channel, read_ptr);
  995. int ev_code, ev_sub_code, ev_queue;
  996. bool ev_failed;
  997. if (!falcon_event_present(event))
  998. break;
  999. ev_code = EFX_QWORD_FIELD(*event, FSF_AZ_EV_CODE);
  1000. ev_sub_code = EFX_QWORD_FIELD(*event,
  1001. FSF_AZ_DRIVER_EV_SUBCODE);
  1002. if (ev_code == FSE_AZ_EV_CODE_DRIVER_EV &&
  1003. ev_sub_code == FSE_AZ_TX_DESCQ_FLS_DONE_EV) {
  1004. ev_queue = EFX_QWORD_FIELD(*event,
  1005. FSF_AZ_DRIVER_EV_SUBDATA);
  1006. if (ev_queue < EFX_TX_QUEUE_COUNT) {
  1007. tx_queue = efx->tx_queue + ev_queue;
  1008. tx_queue->flushed = FLUSH_DONE;
  1009. }
  1010. } else if (ev_code == FSE_AZ_EV_CODE_DRIVER_EV &&
  1011. ev_sub_code == FSE_AZ_RX_DESCQ_FLS_DONE_EV) {
  1012. ev_queue = EFX_QWORD_FIELD(
  1013. *event, FSF_AZ_DRIVER_EV_RX_DESCQ_ID);
  1014. ev_failed = EFX_QWORD_FIELD(
  1015. *event, FSF_AZ_DRIVER_EV_RX_FLUSH_FAIL);
  1016. if (ev_queue < efx->n_rx_queues) {
  1017. rx_queue = efx->rx_queue + ev_queue;
  1018. rx_queue->flushed =
  1019. ev_failed ? FLUSH_FAILED : FLUSH_DONE;
  1020. }
  1021. }
  1022. /* We're about to destroy the queue anyway, so
  1023. * it's ok to throw away every non-flush event */
  1024. EFX_SET_QWORD(*event);
  1025. read_ptr = (read_ptr + 1) & EFX_EVQ_MASK;
  1026. } while (read_ptr != end_ptr);
  1027. channel->eventq_read_ptr = read_ptr;
  1028. }
  1029. static void falcon_prepare_flush(struct efx_nic *efx)
  1030. {
  1031. falcon_deconfigure_mac_wrapper(efx);
  1032. /* Wait for the tx and rx fifo's to get to the next packet boundary
  1033. * (~1ms without back-pressure), then to drain the remainder of the
  1034. * fifo's at data path speeds (negligible), with a healthy margin. */
  1035. msleep(10);
  1036. }
  1037. /* Handle tx and rx flushes at the same time, since they run in
  1038. * parallel in the hardware and there's no reason for us to
  1039. * serialise them */
  1040. int falcon_flush_queues(struct efx_nic *efx)
  1041. {
  1042. struct efx_rx_queue *rx_queue;
  1043. struct efx_tx_queue *tx_queue;
  1044. int i, tx_pending, rx_pending;
  1045. falcon_prepare_flush(efx);
  1046. /* Flush all tx queues in parallel */
  1047. efx_for_each_tx_queue(tx_queue, efx)
  1048. falcon_flush_tx_queue(tx_queue);
  1049. /* The hardware supports four concurrent rx flushes, each of which may
  1050. * need to be retried if there is an outstanding descriptor fetch */
  1051. for (i = 0; i < FALCON_FLUSH_POLL_COUNT; ++i) {
  1052. rx_pending = tx_pending = 0;
  1053. efx_for_each_rx_queue(rx_queue, efx) {
  1054. if (rx_queue->flushed == FLUSH_PENDING)
  1055. ++rx_pending;
  1056. }
  1057. efx_for_each_rx_queue(rx_queue, efx) {
  1058. if (rx_pending == FALCON_RX_FLUSH_COUNT)
  1059. break;
  1060. if (rx_queue->flushed == FLUSH_FAILED ||
  1061. rx_queue->flushed == FLUSH_NONE) {
  1062. falcon_flush_rx_queue(rx_queue);
  1063. ++rx_pending;
  1064. }
  1065. }
  1066. efx_for_each_tx_queue(tx_queue, efx) {
  1067. if (tx_queue->flushed != FLUSH_DONE)
  1068. ++tx_pending;
  1069. }
  1070. if (rx_pending == 0 && tx_pending == 0)
  1071. return 0;
  1072. msleep(FALCON_FLUSH_INTERVAL);
  1073. falcon_poll_flush_events(efx);
  1074. }
  1075. /* Mark the queues as all flushed. We're going to return failure
  1076. * leading to a reset, or fake up success anyway */
  1077. efx_for_each_tx_queue(tx_queue, efx) {
  1078. if (tx_queue->flushed != FLUSH_DONE)
  1079. EFX_ERR(efx, "tx queue %d flush command timed out\n",
  1080. tx_queue->queue);
  1081. tx_queue->flushed = FLUSH_DONE;
  1082. }
  1083. efx_for_each_rx_queue(rx_queue, efx) {
  1084. if (rx_queue->flushed != FLUSH_DONE)
  1085. EFX_ERR(efx, "rx queue %d flush command timed out\n",
  1086. rx_queue->queue);
  1087. rx_queue->flushed = FLUSH_DONE;
  1088. }
  1089. if (EFX_WORKAROUND_7803(efx))
  1090. return 0;
  1091. return -ETIMEDOUT;
  1092. }
  1093. /**************************************************************************
  1094. *
  1095. * Falcon hardware interrupts
  1096. * The hardware interrupt handler does very little work; all the event
  1097. * queue processing is carried out by per-channel tasklets.
  1098. *
  1099. **************************************************************************/
  1100. /* Enable/disable/generate Falcon interrupts */
  1101. static inline void falcon_interrupts(struct efx_nic *efx, int enabled,
  1102. int force)
  1103. {
  1104. efx_oword_t int_en_reg_ker;
  1105. EFX_POPULATE_OWORD_2(int_en_reg_ker,
  1106. FRF_AZ_KER_INT_KER, force,
  1107. FRF_AZ_DRV_INT_EN_KER, enabled);
  1108. efx_writeo(efx, &int_en_reg_ker, FR_AZ_INT_EN_KER);
  1109. }
  1110. void falcon_enable_interrupts(struct efx_nic *efx)
  1111. {
  1112. efx_oword_t int_adr_reg_ker;
  1113. struct efx_channel *channel;
  1114. EFX_ZERO_OWORD(*((efx_oword_t *) efx->irq_status.addr));
  1115. wmb(); /* Ensure interrupt vector is clear before interrupts enabled */
  1116. /* Program address */
  1117. EFX_POPULATE_OWORD_2(int_adr_reg_ker,
  1118. FRF_AZ_NORM_INT_VEC_DIS_KER,
  1119. EFX_INT_MODE_USE_MSI(efx),
  1120. FRF_AZ_INT_ADR_KER, efx->irq_status.dma_addr);
  1121. efx_writeo(efx, &int_adr_reg_ker, FR_AZ_INT_ADR_KER);
  1122. /* Enable interrupts */
  1123. falcon_interrupts(efx, 1, 0);
  1124. /* Force processing of all the channels to get the EVQ RPTRs up to
  1125. date */
  1126. efx_for_each_channel(channel, efx)
  1127. efx_schedule_channel(channel);
  1128. }
  1129. void falcon_disable_interrupts(struct efx_nic *efx)
  1130. {
  1131. /* Disable interrupts */
  1132. falcon_interrupts(efx, 0, 0);
  1133. }
  1134. /* Generate a Falcon test interrupt
  1135. * Interrupt must already have been enabled, otherwise nasty things
  1136. * may happen.
  1137. */
  1138. void falcon_generate_interrupt(struct efx_nic *efx)
  1139. {
  1140. falcon_interrupts(efx, 1, 1);
  1141. }
  1142. /* Acknowledge a legacy interrupt from Falcon
  1143. *
  1144. * This acknowledges a legacy (not MSI) interrupt via INT_ACK_KER_REG.
  1145. *
  1146. * Due to SFC bug 3706 (silicon revision <=A1) reads can be duplicated in the
  1147. * BIU. Interrupt acknowledge is read sensitive so must write instead
  1148. * (then read to ensure the BIU collector is flushed)
  1149. *
  1150. * NB most hardware supports MSI interrupts
  1151. */
  1152. static inline void falcon_irq_ack_a1(struct efx_nic *efx)
  1153. {
  1154. efx_dword_t reg;
  1155. EFX_POPULATE_DWORD_1(reg, FRF_AA_INT_ACK_KER_FIELD, 0xb7eb7e);
  1156. efx_writed(efx, &reg, FR_AA_INT_ACK_KER);
  1157. efx_readd(efx, &reg, FR_AA_WORK_AROUND_BROKEN_PCI_READS);
  1158. }
  1159. /* Process a fatal interrupt
  1160. * Disable bus mastering ASAP and schedule a reset
  1161. */
  1162. static irqreturn_t falcon_fatal_interrupt(struct efx_nic *efx)
  1163. {
  1164. struct falcon_nic_data *nic_data = efx->nic_data;
  1165. efx_oword_t *int_ker = efx->irq_status.addr;
  1166. efx_oword_t fatal_intr;
  1167. int error, mem_perr;
  1168. efx_reado(efx, &fatal_intr, FR_AZ_FATAL_INTR_KER);
  1169. error = EFX_OWORD_FIELD(fatal_intr, FRF_AZ_FATAL_INTR);
  1170. EFX_ERR(efx, "SYSTEM ERROR " EFX_OWORD_FMT " status "
  1171. EFX_OWORD_FMT ": %s\n", EFX_OWORD_VAL(*int_ker),
  1172. EFX_OWORD_VAL(fatal_intr),
  1173. error ? "disabling bus mastering" : "no recognised error");
  1174. if (error == 0)
  1175. goto out;
  1176. /* If this is a memory parity error dump which blocks are offending */
  1177. mem_perr = EFX_OWORD_FIELD(fatal_intr, FRF_AZ_MEM_PERR_INT_KER);
  1178. if (mem_perr) {
  1179. efx_oword_t reg;
  1180. efx_reado(efx, &reg, FR_AZ_MEM_STAT);
  1181. EFX_ERR(efx, "SYSTEM ERROR: memory parity error "
  1182. EFX_OWORD_FMT "\n", EFX_OWORD_VAL(reg));
  1183. }
  1184. /* Disable both devices */
  1185. pci_clear_master(efx->pci_dev);
  1186. if (FALCON_IS_DUAL_FUNC(efx))
  1187. pci_clear_master(nic_data->pci_dev2);
  1188. falcon_disable_interrupts(efx);
  1189. /* Count errors and reset or disable the NIC accordingly */
  1190. if (efx->int_error_count == 0 ||
  1191. time_after(jiffies, efx->int_error_expire)) {
  1192. efx->int_error_count = 0;
  1193. efx->int_error_expire =
  1194. jiffies + FALCON_INT_ERROR_EXPIRE * HZ;
  1195. }
  1196. if (++efx->int_error_count < FALCON_MAX_INT_ERRORS) {
  1197. EFX_ERR(efx, "SYSTEM ERROR - reset scheduled\n");
  1198. efx_schedule_reset(efx, RESET_TYPE_INT_ERROR);
  1199. } else {
  1200. EFX_ERR(efx, "SYSTEM ERROR - max number of errors seen."
  1201. "NIC will be disabled\n");
  1202. efx_schedule_reset(efx, RESET_TYPE_DISABLE);
  1203. }
  1204. out:
  1205. return IRQ_HANDLED;
  1206. }
  1207. /* Handle a legacy interrupt from Falcon
  1208. * Acknowledges the interrupt and schedule event queue processing.
  1209. */
  1210. static irqreturn_t falcon_legacy_interrupt_b0(int irq, void *dev_id)
  1211. {
  1212. struct efx_nic *efx = dev_id;
  1213. efx_oword_t *int_ker = efx->irq_status.addr;
  1214. irqreturn_t result = IRQ_NONE;
  1215. struct efx_channel *channel;
  1216. efx_dword_t reg;
  1217. u32 queues;
  1218. int syserr;
  1219. /* Read the ISR which also ACKs the interrupts */
  1220. efx_readd(efx, &reg, FR_BZ_INT_ISR0);
  1221. queues = EFX_EXTRACT_DWORD(reg, 0, 31);
  1222. /* Check to see if we have a serious error condition */
  1223. syserr = EFX_OWORD_FIELD(*int_ker, FSF_AZ_NET_IVEC_FATAL_INT);
  1224. if (unlikely(syserr))
  1225. return falcon_fatal_interrupt(efx);
  1226. /* Schedule processing of any interrupting queues */
  1227. efx_for_each_channel(channel, efx) {
  1228. if ((queues & 1) ||
  1229. falcon_event_present(
  1230. falcon_event(channel, channel->eventq_read_ptr))) {
  1231. efx_schedule_channel(channel);
  1232. result = IRQ_HANDLED;
  1233. }
  1234. queues >>= 1;
  1235. }
  1236. if (result == IRQ_HANDLED) {
  1237. efx->last_irq_cpu = raw_smp_processor_id();
  1238. EFX_TRACE(efx, "IRQ %d on CPU %d status " EFX_DWORD_FMT "\n",
  1239. irq, raw_smp_processor_id(), EFX_DWORD_VAL(reg));
  1240. }
  1241. return result;
  1242. }
  1243. static irqreturn_t falcon_legacy_interrupt_a1(int irq, void *dev_id)
  1244. {
  1245. struct efx_nic *efx = dev_id;
  1246. efx_oword_t *int_ker = efx->irq_status.addr;
  1247. struct efx_channel *channel;
  1248. int syserr;
  1249. int queues;
  1250. /* Check to see if this is our interrupt. If it isn't, we
  1251. * exit without having touched the hardware.
  1252. */
  1253. if (unlikely(EFX_OWORD_IS_ZERO(*int_ker))) {
  1254. EFX_TRACE(efx, "IRQ %d on CPU %d not for me\n", irq,
  1255. raw_smp_processor_id());
  1256. return IRQ_NONE;
  1257. }
  1258. efx->last_irq_cpu = raw_smp_processor_id();
  1259. EFX_TRACE(efx, "IRQ %d on CPU %d status " EFX_OWORD_FMT "\n",
  1260. irq, raw_smp_processor_id(), EFX_OWORD_VAL(*int_ker));
  1261. /* Check to see if we have a serious error condition */
  1262. syserr = EFX_OWORD_FIELD(*int_ker, FSF_AZ_NET_IVEC_FATAL_INT);
  1263. if (unlikely(syserr))
  1264. return falcon_fatal_interrupt(efx);
  1265. /* Determine interrupting queues, clear interrupt status
  1266. * register and acknowledge the device interrupt.
  1267. */
  1268. BUILD_BUG_ON(INT_EVQS_WIDTH > EFX_MAX_CHANNELS);
  1269. queues = EFX_OWORD_FIELD(*int_ker, INT_EVQS);
  1270. EFX_ZERO_OWORD(*int_ker);
  1271. wmb(); /* Ensure the vector is cleared before interrupt ack */
  1272. falcon_irq_ack_a1(efx);
  1273. /* Schedule processing of any interrupting queues */
  1274. channel = &efx->channel[0];
  1275. while (queues) {
  1276. if (queues & 0x01)
  1277. efx_schedule_channel(channel);
  1278. channel++;
  1279. queues >>= 1;
  1280. }
  1281. return IRQ_HANDLED;
  1282. }
  1283. /* Handle an MSI interrupt from Falcon
  1284. *
  1285. * Handle an MSI hardware interrupt. This routine schedules event
  1286. * queue processing. No interrupt acknowledgement cycle is necessary.
  1287. * Also, we never need to check that the interrupt is for us, since
  1288. * MSI interrupts cannot be shared.
  1289. */
  1290. static irqreturn_t falcon_msi_interrupt(int irq, void *dev_id)
  1291. {
  1292. struct efx_channel *channel = dev_id;
  1293. struct efx_nic *efx = channel->efx;
  1294. efx_oword_t *int_ker = efx->irq_status.addr;
  1295. int syserr;
  1296. efx->last_irq_cpu = raw_smp_processor_id();
  1297. EFX_TRACE(efx, "IRQ %d on CPU %d status " EFX_OWORD_FMT "\n",
  1298. irq, raw_smp_processor_id(), EFX_OWORD_VAL(*int_ker));
  1299. /* Check to see if we have a serious error condition */
  1300. syserr = EFX_OWORD_FIELD(*int_ker, FATAL_INT);
  1301. if (unlikely(syserr))
  1302. return falcon_fatal_interrupt(efx);
  1303. /* Schedule processing of the channel */
  1304. efx_schedule_channel(channel);
  1305. return IRQ_HANDLED;
  1306. }
  1307. /* Setup RSS indirection table.
  1308. * This maps from the hash value of the packet to RXQ
  1309. */
  1310. static void falcon_setup_rss_indir_table(struct efx_nic *efx)
  1311. {
  1312. int i = 0;
  1313. unsigned long offset;
  1314. efx_dword_t dword;
  1315. if (falcon_rev(efx) < FALCON_REV_B0)
  1316. return;
  1317. for (offset = FR_BZ_RX_INDIRECTION_TBL;
  1318. offset < FR_BZ_RX_INDIRECTION_TBL + 0x800;
  1319. offset += 0x10) {
  1320. EFX_POPULATE_DWORD_1(dword, FRF_BZ_IT_QUEUE,
  1321. i % efx->n_rx_queues);
  1322. efx_writed(efx, &dword, offset);
  1323. i++;
  1324. }
  1325. }
  1326. /* Hook interrupt handler(s)
  1327. * Try MSI and then legacy interrupts.
  1328. */
  1329. int falcon_init_interrupt(struct efx_nic *efx)
  1330. {
  1331. struct efx_channel *channel;
  1332. int rc;
  1333. if (!EFX_INT_MODE_USE_MSI(efx)) {
  1334. irq_handler_t handler;
  1335. if (falcon_rev(efx) >= FALCON_REV_B0)
  1336. handler = falcon_legacy_interrupt_b0;
  1337. else
  1338. handler = falcon_legacy_interrupt_a1;
  1339. rc = request_irq(efx->legacy_irq, handler, IRQF_SHARED,
  1340. efx->name, efx);
  1341. if (rc) {
  1342. EFX_ERR(efx, "failed to hook legacy IRQ %d\n",
  1343. efx->pci_dev->irq);
  1344. goto fail1;
  1345. }
  1346. return 0;
  1347. }
  1348. /* Hook MSI or MSI-X interrupt */
  1349. efx_for_each_channel(channel, efx) {
  1350. rc = request_irq(channel->irq, falcon_msi_interrupt,
  1351. IRQF_PROBE_SHARED, /* Not shared */
  1352. channel->name, channel);
  1353. if (rc) {
  1354. EFX_ERR(efx, "failed to hook IRQ %d\n", channel->irq);
  1355. goto fail2;
  1356. }
  1357. }
  1358. return 0;
  1359. fail2:
  1360. efx_for_each_channel(channel, efx)
  1361. free_irq(channel->irq, channel);
  1362. fail1:
  1363. return rc;
  1364. }
  1365. void falcon_fini_interrupt(struct efx_nic *efx)
  1366. {
  1367. struct efx_channel *channel;
  1368. efx_oword_t reg;
  1369. /* Disable MSI/MSI-X interrupts */
  1370. efx_for_each_channel(channel, efx) {
  1371. if (channel->irq)
  1372. free_irq(channel->irq, channel);
  1373. }
  1374. /* ACK legacy interrupt */
  1375. if (falcon_rev(efx) >= FALCON_REV_B0)
  1376. efx_reado(efx, &reg, FR_BZ_INT_ISR0);
  1377. else
  1378. falcon_irq_ack_a1(efx);
  1379. /* Disable legacy interrupt */
  1380. if (efx->legacy_irq)
  1381. free_irq(efx->legacy_irq, efx);
  1382. }
  1383. /**************************************************************************
  1384. *
  1385. * EEPROM/flash
  1386. *
  1387. **************************************************************************
  1388. */
  1389. #define FALCON_SPI_MAX_LEN sizeof(efx_oword_t)
  1390. static int falcon_spi_poll(struct efx_nic *efx)
  1391. {
  1392. efx_oword_t reg;
  1393. efx_reado(efx, &reg, FR_AB_EE_SPI_HCMD);
  1394. return EFX_OWORD_FIELD(reg, FRF_AB_EE_SPI_HCMD_CMD_EN) ? -EBUSY : 0;
  1395. }
  1396. /* Wait for SPI command completion */
  1397. static int falcon_spi_wait(struct efx_nic *efx)
  1398. {
  1399. /* Most commands will finish quickly, so we start polling at
  1400. * very short intervals. Sometimes the command may have to
  1401. * wait for VPD or expansion ROM access outside of our
  1402. * control, so we allow up to 100 ms. */
  1403. unsigned long timeout = jiffies + 1 + DIV_ROUND_UP(HZ, 10);
  1404. int i;
  1405. for (i = 0; i < 10; i++) {
  1406. if (!falcon_spi_poll(efx))
  1407. return 0;
  1408. udelay(10);
  1409. }
  1410. for (;;) {
  1411. if (!falcon_spi_poll(efx))
  1412. return 0;
  1413. if (time_after_eq(jiffies, timeout)) {
  1414. EFX_ERR(efx, "timed out waiting for SPI\n");
  1415. return -ETIMEDOUT;
  1416. }
  1417. schedule_timeout_uninterruptible(1);
  1418. }
  1419. }
  1420. int falcon_spi_cmd(const struct efx_spi_device *spi,
  1421. unsigned int command, int address,
  1422. const void *in, void *out, size_t len)
  1423. {
  1424. struct efx_nic *efx = spi->efx;
  1425. bool addressed = (address >= 0);
  1426. bool reading = (out != NULL);
  1427. efx_oword_t reg;
  1428. int rc;
  1429. /* Input validation */
  1430. if (len > FALCON_SPI_MAX_LEN)
  1431. return -EINVAL;
  1432. BUG_ON(!mutex_is_locked(&efx->spi_lock));
  1433. /* Check that previous command is not still running */
  1434. rc = falcon_spi_poll(efx);
  1435. if (rc)
  1436. return rc;
  1437. /* Program address register, if we have an address */
  1438. if (addressed) {
  1439. EFX_POPULATE_OWORD_1(reg, FRF_AB_EE_SPI_HADR_ADR, address);
  1440. efx_writeo(efx, &reg, FR_AB_EE_SPI_HADR);
  1441. }
  1442. /* Program data register, if we have data */
  1443. if (in != NULL) {
  1444. memcpy(&reg, in, len);
  1445. efx_writeo(efx, &reg, FR_AB_EE_SPI_HDATA);
  1446. }
  1447. /* Issue read/write command */
  1448. EFX_POPULATE_OWORD_7(reg,
  1449. FRF_AB_EE_SPI_HCMD_CMD_EN, 1,
  1450. FRF_AB_EE_SPI_HCMD_SF_SEL, spi->device_id,
  1451. FRF_AB_EE_SPI_HCMD_DABCNT, len,
  1452. FRF_AB_EE_SPI_HCMD_READ, reading,
  1453. FRF_AB_EE_SPI_HCMD_DUBCNT, 0,
  1454. FRF_AB_EE_SPI_HCMD_ADBCNT,
  1455. (addressed ? spi->addr_len : 0),
  1456. FRF_AB_EE_SPI_HCMD_ENC, command);
  1457. efx_writeo(efx, &reg, FR_AB_EE_SPI_HCMD);
  1458. /* Wait for read/write to complete */
  1459. rc = falcon_spi_wait(efx);
  1460. if (rc)
  1461. return rc;
  1462. /* Read data */
  1463. if (out != NULL) {
  1464. efx_reado(efx, &reg, FR_AB_EE_SPI_HDATA);
  1465. memcpy(out, &reg, len);
  1466. }
  1467. return 0;
  1468. }
  1469. static size_t
  1470. falcon_spi_write_limit(const struct efx_spi_device *spi, size_t start)
  1471. {
  1472. return min(FALCON_SPI_MAX_LEN,
  1473. (spi->block_size - (start & (spi->block_size - 1))));
  1474. }
  1475. static inline u8
  1476. efx_spi_munge_command(const struct efx_spi_device *spi,
  1477. const u8 command, const unsigned int address)
  1478. {
  1479. return command | (((address >> 8) & spi->munge_address) << 3);
  1480. }
  1481. /* Wait up to 10 ms for buffered write completion */
  1482. int falcon_spi_wait_write(const struct efx_spi_device *spi)
  1483. {
  1484. struct efx_nic *efx = spi->efx;
  1485. unsigned long timeout = jiffies + 1 + DIV_ROUND_UP(HZ, 100);
  1486. u8 status;
  1487. int rc;
  1488. for (;;) {
  1489. rc = falcon_spi_cmd(spi, SPI_RDSR, -1, NULL,
  1490. &status, sizeof(status));
  1491. if (rc)
  1492. return rc;
  1493. if (!(status & SPI_STATUS_NRDY))
  1494. return 0;
  1495. if (time_after_eq(jiffies, timeout)) {
  1496. EFX_ERR(efx, "SPI write timeout on device %d"
  1497. " last status=0x%02x\n",
  1498. spi->device_id, status);
  1499. return -ETIMEDOUT;
  1500. }
  1501. schedule_timeout_uninterruptible(1);
  1502. }
  1503. }
  1504. int falcon_spi_read(const struct efx_spi_device *spi, loff_t start,
  1505. size_t len, size_t *retlen, u8 *buffer)
  1506. {
  1507. size_t block_len, pos = 0;
  1508. unsigned int command;
  1509. int rc = 0;
  1510. while (pos < len) {
  1511. block_len = min(len - pos, FALCON_SPI_MAX_LEN);
  1512. command = efx_spi_munge_command(spi, SPI_READ, start + pos);
  1513. rc = falcon_spi_cmd(spi, command, start + pos, NULL,
  1514. buffer + pos, block_len);
  1515. if (rc)
  1516. break;
  1517. pos += block_len;
  1518. /* Avoid locking up the system */
  1519. cond_resched();
  1520. if (signal_pending(current)) {
  1521. rc = -EINTR;
  1522. break;
  1523. }
  1524. }
  1525. if (retlen)
  1526. *retlen = pos;
  1527. return rc;
  1528. }
  1529. int falcon_spi_write(const struct efx_spi_device *spi, loff_t start,
  1530. size_t len, size_t *retlen, const u8 *buffer)
  1531. {
  1532. u8 verify_buffer[FALCON_SPI_MAX_LEN];
  1533. size_t block_len, pos = 0;
  1534. unsigned int command;
  1535. int rc = 0;
  1536. while (pos < len) {
  1537. rc = falcon_spi_cmd(spi, SPI_WREN, -1, NULL, NULL, 0);
  1538. if (rc)
  1539. break;
  1540. block_len = min(len - pos,
  1541. falcon_spi_write_limit(spi, start + pos));
  1542. command = efx_spi_munge_command(spi, SPI_WRITE, start + pos);
  1543. rc = falcon_spi_cmd(spi, command, start + pos,
  1544. buffer + pos, NULL, block_len);
  1545. if (rc)
  1546. break;
  1547. rc = falcon_spi_wait_write(spi);
  1548. if (rc)
  1549. break;
  1550. command = efx_spi_munge_command(spi, SPI_READ, start + pos);
  1551. rc = falcon_spi_cmd(spi, command, start + pos,
  1552. NULL, verify_buffer, block_len);
  1553. if (memcmp(verify_buffer, buffer + pos, block_len)) {
  1554. rc = -EIO;
  1555. break;
  1556. }
  1557. pos += block_len;
  1558. /* Avoid locking up the system */
  1559. cond_resched();
  1560. if (signal_pending(current)) {
  1561. rc = -EINTR;
  1562. break;
  1563. }
  1564. }
  1565. if (retlen)
  1566. *retlen = pos;
  1567. return rc;
  1568. }
  1569. /**************************************************************************
  1570. *
  1571. * MAC wrapper
  1572. *
  1573. **************************************************************************
  1574. */
  1575. static int falcon_reset_macs(struct efx_nic *efx)
  1576. {
  1577. efx_oword_t reg;
  1578. int count;
  1579. if (falcon_rev(efx) < FALCON_REV_B0) {
  1580. /* It's not safe to use GLB_CTL_REG to reset the
  1581. * macs, so instead use the internal MAC resets
  1582. */
  1583. if (!EFX_IS10G(efx)) {
  1584. EFX_POPULATE_OWORD_1(reg, FRF_AB_GM_SW_RST, 1);
  1585. efx_writeo(efx, &reg, FR_AB_GM_CFG1);
  1586. udelay(1000);
  1587. EFX_POPULATE_OWORD_1(reg, FRF_AB_GM_SW_RST, 0);
  1588. efx_writeo(efx, &reg, FR_AB_GM_CFG1);
  1589. udelay(1000);
  1590. return 0;
  1591. } else {
  1592. EFX_POPULATE_OWORD_1(reg, FRF_AB_XM_CORE_RST, 1);
  1593. efx_writeo(efx, &reg, FR_AB_XM_GLB_CFG);
  1594. for (count = 0; count < 10000; count++) {
  1595. efx_reado(efx, &reg, FR_AB_XM_GLB_CFG);
  1596. if (EFX_OWORD_FIELD(reg, FRF_AB_XM_CORE_RST) ==
  1597. 0)
  1598. return 0;
  1599. udelay(10);
  1600. }
  1601. EFX_ERR(efx, "timed out waiting for XMAC core reset\n");
  1602. return -ETIMEDOUT;
  1603. }
  1604. }
  1605. /* MAC stats will fail whilst the TX fifo is draining. Serialise
  1606. * the drain sequence with the statistics fetch */
  1607. falcon_stop_nic_stats(efx);
  1608. efx_reado(efx, &reg, FR_AB_MAC_CTRL);
  1609. EFX_SET_OWORD_FIELD(reg, FRF_BB_TXFIFO_DRAIN_EN, 1);
  1610. efx_writeo(efx, &reg, FR_AB_MAC_CTRL);
  1611. efx_reado(efx, &reg, FR_AB_GLB_CTL);
  1612. EFX_SET_OWORD_FIELD(reg, FRF_AB_RST_XGTX, 1);
  1613. EFX_SET_OWORD_FIELD(reg, FRF_AB_RST_XGRX, 1);
  1614. EFX_SET_OWORD_FIELD(reg, FRF_AB_RST_EM, 1);
  1615. efx_writeo(efx, &reg, FR_AB_GLB_CTL);
  1616. count = 0;
  1617. while (1) {
  1618. efx_reado(efx, &reg, FR_AB_GLB_CTL);
  1619. if (!EFX_OWORD_FIELD(reg, FRF_AB_RST_XGTX) &&
  1620. !EFX_OWORD_FIELD(reg, FRF_AB_RST_XGRX) &&
  1621. !EFX_OWORD_FIELD(reg, FRF_AB_RST_EM)) {
  1622. EFX_LOG(efx, "Completed MAC reset after %d loops\n",
  1623. count);
  1624. break;
  1625. }
  1626. if (count > 20) {
  1627. EFX_ERR(efx, "MAC reset failed\n");
  1628. break;
  1629. }
  1630. count++;
  1631. udelay(10);
  1632. }
  1633. /* If we've reset the EM block and the link is up, then
  1634. * we'll have to kick the XAUI link so the PHY can recover */
  1635. if (efx->link_state.up && EFX_IS10G(efx) && EFX_WORKAROUND_5147(efx))
  1636. falcon_reset_xaui(efx);
  1637. falcon_start_nic_stats(efx);
  1638. return 0;
  1639. }
  1640. void falcon_drain_tx_fifo(struct efx_nic *efx)
  1641. {
  1642. efx_oword_t reg;
  1643. if ((falcon_rev(efx) < FALCON_REV_B0) ||
  1644. (efx->loopback_mode != LOOPBACK_NONE))
  1645. return;
  1646. efx_reado(efx, &reg, FR_AB_MAC_CTRL);
  1647. /* There is no point in draining more than once */
  1648. if (EFX_OWORD_FIELD(reg, FRF_BB_TXFIFO_DRAIN_EN))
  1649. return;
  1650. falcon_reset_macs(efx);
  1651. }
  1652. void falcon_deconfigure_mac_wrapper(struct efx_nic *efx)
  1653. {
  1654. efx_oword_t reg;
  1655. if (falcon_rev(efx) < FALCON_REV_B0)
  1656. return;
  1657. /* Isolate the MAC -> RX */
  1658. efx_reado(efx, &reg, FR_AZ_RX_CFG);
  1659. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_INGR_EN, 0);
  1660. efx_writeo(efx, &reg, FR_AZ_RX_CFG);
  1661. if (!efx->link_state.up)
  1662. falcon_drain_tx_fifo(efx);
  1663. }
  1664. void falcon_reconfigure_mac_wrapper(struct efx_nic *efx)
  1665. {
  1666. struct efx_link_state *link_state = &efx->link_state;
  1667. efx_oword_t reg;
  1668. int link_speed;
  1669. bool tx_fc;
  1670. switch (link_state->speed) {
  1671. case 10000: link_speed = 3; break;
  1672. case 1000: link_speed = 2; break;
  1673. case 100: link_speed = 1; break;
  1674. default: link_speed = 0; break;
  1675. }
  1676. /* MAC_LINK_STATUS controls MAC backpressure but doesn't work
  1677. * as advertised. Disable to ensure packets are not
  1678. * indefinitely held and TX queue can be flushed at any point
  1679. * while the link is down. */
  1680. EFX_POPULATE_OWORD_5(reg,
  1681. FRF_AB_MAC_XOFF_VAL, 0xffff /* max pause time */,
  1682. FRF_AB_MAC_BCAD_ACPT, 1,
  1683. FRF_AB_MAC_UC_PROM, efx->promiscuous,
  1684. FRF_AB_MAC_LINK_STATUS, 1, /* always set */
  1685. FRF_AB_MAC_SPEED, link_speed);
  1686. /* On B0, MAC backpressure can be disabled and packets get
  1687. * discarded. */
  1688. if (falcon_rev(efx) >= FALCON_REV_B0) {
  1689. EFX_SET_OWORD_FIELD(reg, FRF_BB_TXFIFO_DRAIN_EN,
  1690. !link_state->up);
  1691. }
  1692. efx_writeo(efx, &reg, FR_AB_MAC_CTRL);
  1693. /* Restore the multicast hash registers. */
  1694. falcon_push_multicast_hash(efx);
  1695. /* Transmission of pause frames when RX crosses the threshold is
  1696. * covered by RX_XOFF_MAC_EN and XM_TX_CFG_REG:XM_FCNTL.
  1697. * Action on receipt of pause frames is controller by XM_DIS_FCNTL */
  1698. tx_fc = !!(efx->link_state.fc & EFX_FC_TX);
  1699. efx_reado(efx, &reg, FR_AZ_RX_CFG);
  1700. EFX_SET_OWORD_FIELD(reg, FRF_AZ_RX_XOFF_MAC_EN, tx_fc);
  1701. /* Unisolate the MAC -> RX */
  1702. if (falcon_rev(efx) >= FALCON_REV_B0)
  1703. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_INGR_EN, 1);
  1704. efx_writeo(efx, &reg, FR_AZ_RX_CFG);
  1705. }
  1706. static void falcon_stats_request(struct efx_nic *efx)
  1707. {
  1708. struct falcon_nic_data *nic_data = efx->nic_data;
  1709. efx_oword_t reg;
  1710. WARN_ON(nic_data->stats_pending);
  1711. WARN_ON(nic_data->stats_disable_count);
  1712. if (nic_data->stats_dma_done == NULL)
  1713. return; /* no mac selected */
  1714. *nic_data->stats_dma_done = FALCON_STATS_NOT_DONE;
  1715. nic_data->stats_pending = true;
  1716. wmb(); /* ensure done flag is clear */
  1717. /* Initiate DMA transfer of stats */
  1718. EFX_POPULATE_OWORD_2(reg,
  1719. FRF_AB_MAC_STAT_DMA_CMD, 1,
  1720. FRF_AB_MAC_STAT_DMA_ADR,
  1721. efx->stats_buffer.dma_addr);
  1722. efx_writeo(efx, &reg, FR_AB_MAC_STAT_DMA);
  1723. mod_timer(&nic_data->stats_timer, round_jiffies_up(jiffies + HZ / 2));
  1724. }
  1725. static void falcon_stats_complete(struct efx_nic *efx)
  1726. {
  1727. struct falcon_nic_data *nic_data = efx->nic_data;
  1728. if (!nic_data->stats_pending)
  1729. return;
  1730. nic_data->stats_pending = 0;
  1731. if (*nic_data->stats_dma_done == FALCON_STATS_DONE) {
  1732. rmb(); /* read the done flag before the stats */
  1733. efx->mac_op->update_stats(efx);
  1734. } else {
  1735. EFX_ERR(efx, "timed out waiting for statistics\n");
  1736. }
  1737. }
  1738. static void falcon_stats_timer_func(unsigned long context)
  1739. {
  1740. struct efx_nic *efx = (struct efx_nic *)context;
  1741. struct falcon_nic_data *nic_data = efx->nic_data;
  1742. spin_lock(&efx->stats_lock);
  1743. falcon_stats_complete(efx);
  1744. if (nic_data->stats_disable_count == 0)
  1745. falcon_stats_request(efx);
  1746. spin_unlock(&efx->stats_lock);
  1747. }
  1748. static bool falcon_loopback_link_poll(struct efx_nic *efx)
  1749. {
  1750. struct efx_link_state old_state = efx->link_state;
  1751. WARN_ON(!mutex_is_locked(&efx->mac_lock));
  1752. WARN_ON(!LOOPBACK_INTERNAL(efx));
  1753. efx->link_state.fd = true;
  1754. efx->link_state.fc = efx->wanted_fc;
  1755. efx->link_state.up = true;
  1756. if (efx->loopback_mode == LOOPBACK_GMAC)
  1757. efx->link_state.speed = 1000;
  1758. else
  1759. efx->link_state.speed = 10000;
  1760. return !efx_link_state_equal(&efx->link_state, &old_state);
  1761. }
  1762. /**************************************************************************
  1763. *
  1764. * PHY access via GMII
  1765. *
  1766. **************************************************************************
  1767. */
  1768. /* Wait for GMII access to complete */
  1769. static int falcon_gmii_wait(struct efx_nic *efx)
  1770. {
  1771. efx_oword_t md_stat;
  1772. int count;
  1773. /* wait upto 50ms - taken max from datasheet */
  1774. for (count = 0; count < 5000; count++) {
  1775. efx_reado(efx, &md_stat, FR_AB_MD_STAT);
  1776. if (EFX_OWORD_FIELD(md_stat, FRF_AB_MD_BSY) == 0) {
  1777. if (EFX_OWORD_FIELD(md_stat, FRF_AB_MD_LNFL) != 0 ||
  1778. EFX_OWORD_FIELD(md_stat, FRF_AB_MD_BSERR) != 0) {
  1779. EFX_ERR(efx, "error from GMII access "
  1780. EFX_OWORD_FMT"\n",
  1781. EFX_OWORD_VAL(md_stat));
  1782. return -EIO;
  1783. }
  1784. return 0;
  1785. }
  1786. udelay(10);
  1787. }
  1788. EFX_ERR(efx, "timed out waiting for GMII\n");
  1789. return -ETIMEDOUT;
  1790. }
  1791. /* Write an MDIO register of a PHY connected to Falcon. */
  1792. static int falcon_mdio_write(struct net_device *net_dev,
  1793. int prtad, int devad, u16 addr, u16 value)
  1794. {
  1795. struct efx_nic *efx = netdev_priv(net_dev);
  1796. efx_oword_t reg;
  1797. int rc;
  1798. EFX_REGDUMP(efx, "writing MDIO %d register %d.%d with 0x%04x\n",
  1799. prtad, devad, addr, value);
  1800. mutex_lock(&efx->mdio_lock);
  1801. /* Check MDIO not currently being accessed */
  1802. rc = falcon_gmii_wait(efx);
  1803. if (rc)
  1804. goto out;
  1805. /* Write the address/ID register */
  1806. EFX_POPULATE_OWORD_1(reg, FRF_AB_MD_PHY_ADR, addr);
  1807. efx_writeo(efx, &reg, FR_AB_MD_PHY_ADR);
  1808. EFX_POPULATE_OWORD_2(reg, FRF_AB_MD_PRT_ADR, prtad,
  1809. FRF_AB_MD_DEV_ADR, devad);
  1810. efx_writeo(efx, &reg, FR_AB_MD_ID);
  1811. /* Write data */
  1812. EFX_POPULATE_OWORD_1(reg, FRF_AB_MD_TXD, value);
  1813. efx_writeo(efx, &reg, FR_AB_MD_TXD);
  1814. EFX_POPULATE_OWORD_2(reg,
  1815. FRF_AB_MD_WRC, 1,
  1816. FRF_AB_MD_GC, 0);
  1817. efx_writeo(efx, &reg, FR_AB_MD_CS);
  1818. /* Wait for data to be written */
  1819. rc = falcon_gmii_wait(efx);
  1820. if (rc) {
  1821. /* Abort the write operation */
  1822. EFX_POPULATE_OWORD_2(reg,
  1823. FRF_AB_MD_WRC, 0,
  1824. FRF_AB_MD_GC, 1);
  1825. efx_writeo(efx, &reg, FR_AB_MD_CS);
  1826. udelay(10);
  1827. }
  1828. out:
  1829. mutex_unlock(&efx->mdio_lock);
  1830. return rc;
  1831. }
  1832. /* Read an MDIO register of a PHY connected to Falcon. */
  1833. static int falcon_mdio_read(struct net_device *net_dev,
  1834. int prtad, int devad, u16 addr)
  1835. {
  1836. struct efx_nic *efx = netdev_priv(net_dev);
  1837. efx_oword_t reg;
  1838. int rc;
  1839. mutex_lock(&efx->mdio_lock);
  1840. /* Check MDIO not currently being accessed */
  1841. rc = falcon_gmii_wait(efx);
  1842. if (rc)
  1843. goto out;
  1844. EFX_POPULATE_OWORD_1(reg, FRF_AB_MD_PHY_ADR, addr);
  1845. efx_writeo(efx, &reg, FR_AB_MD_PHY_ADR);
  1846. EFX_POPULATE_OWORD_2(reg, FRF_AB_MD_PRT_ADR, prtad,
  1847. FRF_AB_MD_DEV_ADR, devad);
  1848. efx_writeo(efx, &reg, FR_AB_MD_ID);
  1849. /* Request data to be read */
  1850. EFX_POPULATE_OWORD_2(reg, FRF_AB_MD_RDC, 1, FRF_AB_MD_GC, 0);
  1851. efx_writeo(efx, &reg, FR_AB_MD_CS);
  1852. /* Wait for data to become available */
  1853. rc = falcon_gmii_wait(efx);
  1854. if (rc == 0) {
  1855. efx_reado(efx, &reg, FR_AB_MD_RXD);
  1856. rc = EFX_OWORD_FIELD(reg, FRF_AB_MD_RXD);
  1857. EFX_REGDUMP(efx, "read from MDIO %d register %d.%d, got %04x\n",
  1858. prtad, devad, addr, rc);
  1859. } else {
  1860. /* Abort the read operation */
  1861. EFX_POPULATE_OWORD_2(reg,
  1862. FRF_AB_MD_RIC, 0,
  1863. FRF_AB_MD_GC, 1);
  1864. efx_writeo(efx, &reg, FR_AB_MD_CS);
  1865. EFX_LOG(efx, "read from MDIO %d register %d.%d, got error %d\n",
  1866. prtad, devad, addr, rc);
  1867. }
  1868. out:
  1869. mutex_unlock(&efx->mdio_lock);
  1870. return rc;
  1871. }
  1872. static void falcon_clock_mac(struct efx_nic *efx)
  1873. {
  1874. unsigned strap_val;
  1875. efx_oword_t nic_stat;
  1876. /* Configure the NIC generated MAC clock correctly */
  1877. efx_reado(efx, &nic_stat, FR_AB_NIC_STAT);
  1878. strap_val = EFX_IS10G(efx) ? 5 : 3;
  1879. if (falcon_rev(efx) >= FALCON_REV_B0) {
  1880. EFX_SET_OWORD_FIELD(nic_stat, FRF_BB_EE_STRAP_EN, 1);
  1881. EFX_SET_OWORD_FIELD(nic_stat, FRF_BB_EE_STRAP, strap_val);
  1882. efx_writeo(efx, &nic_stat, FR_AB_NIC_STAT);
  1883. } else {
  1884. /* Falcon A1 does not support 1G/10G speed switching
  1885. * and must not be used with a PHY that does. */
  1886. BUG_ON(EFX_OWORD_FIELD(nic_stat, FRF_AB_STRAP_PINS) !=
  1887. strap_val);
  1888. }
  1889. }
  1890. int falcon_switch_mac(struct efx_nic *efx)
  1891. {
  1892. struct efx_mac_operations *old_mac_op = efx->mac_op;
  1893. struct falcon_nic_data *nic_data = efx->nic_data;
  1894. unsigned int stats_done_offset;
  1895. int rc = 0;
  1896. /* Don't try to fetch MAC stats while we're switching MACs */
  1897. falcon_stop_nic_stats(efx);
  1898. WARN_ON(!mutex_is_locked(&efx->mac_lock));
  1899. efx->mac_op = (EFX_IS10G(efx) ?
  1900. &falcon_xmac_operations : &falcon_gmac_operations);
  1901. if (EFX_IS10G(efx))
  1902. stats_done_offset = XgDmaDone_offset;
  1903. else
  1904. stats_done_offset = GDmaDone_offset;
  1905. nic_data->stats_dma_done = efx->stats_buffer.addr + stats_done_offset;
  1906. if (old_mac_op == efx->mac_op)
  1907. goto out;
  1908. falcon_clock_mac(efx);
  1909. EFX_LOG(efx, "selected %cMAC\n", EFX_IS10G(efx) ? 'X' : 'G');
  1910. /* Not all macs support a mac-level link state */
  1911. efx->xmac_poll_required = false;
  1912. rc = falcon_reset_macs(efx);
  1913. out:
  1914. falcon_start_nic_stats(efx);
  1915. return rc;
  1916. }
  1917. /* This call is responsible for hooking in the MAC and PHY operations */
  1918. int falcon_probe_port(struct efx_nic *efx)
  1919. {
  1920. int rc;
  1921. switch (efx->phy_type) {
  1922. case PHY_TYPE_SFX7101:
  1923. efx->phy_op = &falcon_sfx7101_phy_ops;
  1924. break;
  1925. case PHY_TYPE_SFT9001A:
  1926. case PHY_TYPE_SFT9001B:
  1927. efx->phy_op = &falcon_sft9001_phy_ops;
  1928. break;
  1929. case PHY_TYPE_QT2022C2:
  1930. case PHY_TYPE_QT2025C:
  1931. efx->phy_op = &falcon_qt202x_phy_ops;
  1932. break;
  1933. default:
  1934. EFX_ERR(efx, "Unknown PHY type %d\n",
  1935. efx->phy_type);
  1936. return -ENODEV;
  1937. }
  1938. if (efx->phy_op->macs & EFX_XMAC)
  1939. efx->loopback_modes |= ((1 << LOOPBACK_XGMII) |
  1940. (1 << LOOPBACK_XGXS) |
  1941. (1 << LOOPBACK_XAUI));
  1942. if (efx->phy_op->macs & EFX_GMAC)
  1943. efx->loopback_modes |= (1 << LOOPBACK_GMAC);
  1944. efx->loopback_modes |= efx->phy_op->loopbacks;
  1945. /* Set up MDIO structure for PHY */
  1946. efx->mdio.mmds = efx->phy_op->mmds;
  1947. efx->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  1948. efx->mdio.mdio_read = falcon_mdio_read;
  1949. efx->mdio.mdio_write = falcon_mdio_write;
  1950. /* Hardware flow ctrl. FalconA RX FIFO too small for pause generation */
  1951. if (falcon_rev(efx) >= FALCON_REV_B0)
  1952. efx->wanted_fc = EFX_FC_RX | EFX_FC_TX;
  1953. else
  1954. efx->wanted_fc = EFX_FC_RX;
  1955. /* Allocate buffer for stats */
  1956. rc = falcon_alloc_buffer(efx, &efx->stats_buffer,
  1957. FALCON_MAC_STATS_SIZE);
  1958. if (rc)
  1959. return rc;
  1960. EFX_LOG(efx, "stats buffer at %llx (virt %p phys %llx)\n",
  1961. (u64)efx->stats_buffer.dma_addr,
  1962. efx->stats_buffer.addr,
  1963. (u64)virt_to_phys(efx->stats_buffer.addr));
  1964. return 0;
  1965. }
  1966. void falcon_remove_port(struct efx_nic *efx)
  1967. {
  1968. falcon_free_buffer(efx, &efx->stats_buffer);
  1969. }
  1970. /**************************************************************************
  1971. *
  1972. * Multicast filtering
  1973. *
  1974. **************************************************************************
  1975. */
  1976. void falcon_push_multicast_hash(struct efx_nic *efx)
  1977. {
  1978. union efx_multicast_hash *mc_hash = &efx->multicast_hash;
  1979. WARN_ON(!mutex_is_locked(&efx->mac_lock));
  1980. efx_writeo(efx, &mc_hash->oword[0], FR_AB_MAC_MC_HASH_REG0);
  1981. efx_writeo(efx, &mc_hash->oword[1], FR_AB_MAC_MC_HASH_REG1);
  1982. }
  1983. /**************************************************************************
  1984. *
  1985. * Falcon test code
  1986. *
  1987. **************************************************************************/
  1988. int falcon_read_nvram(struct efx_nic *efx, struct falcon_nvconfig *nvconfig_out)
  1989. {
  1990. struct falcon_nvconfig *nvconfig;
  1991. struct efx_spi_device *spi;
  1992. void *region;
  1993. int rc, magic_num, struct_ver;
  1994. __le16 *word, *limit;
  1995. u32 csum;
  1996. spi = efx->spi_flash ? efx->spi_flash : efx->spi_eeprom;
  1997. if (!spi)
  1998. return -EINVAL;
  1999. region = kmalloc(FALCON_NVCONFIG_END, GFP_KERNEL);
  2000. if (!region)
  2001. return -ENOMEM;
  2002. nvconfig = region + FALCON_NVCONFIG_OFFSET;
  2003. mutex_lock(&efx->spi_lock);
  2004. rc = falcon_spi_read(spi, 0, FALCON_NVCONFIG_END, NULL, region);
  2005. mutex_unlock(&efx->spi_lock);
  2006. if (rc) {
  2007. EFX_ERR(efx, "Failed to read %s\n",
  2008. efx->spi_flash ? "flash" : "EEPROM");
  2009. rc = -EIO;
  2010. goto out;
  2011. }
  2012. magic_num = le16_to_cpu(nvconfig->board_magic_num);
  2013. struct_ver = le16_to_cpu(nvconfig->board_struct_ver);
  2014. rc = -EINVAL;
  2015. if (magic_num != FALCON_NVCONFIG_BOARD_MAGIC_NUM) {
  2016. EFX_ERR(efx, "NVRAM bad magic 0x%x\n", magic_num);
  2017. goto out;
  2018. }
  2019. if (struct_ver < 2) {
  2020. EFX_ERR(efx, "NVRAM has ancient version 0x%x\n", struct_ver);
  2021. goto out;
  2022. } else if (struct_ver < 4) {
  2023. word = &nvconfig->board_magic_num;
  2024. limit = (__le16 *) (nvconfig + 1);
  2025. } else {
  2026. word = region;
  2027. limit = region + FALCON_NVCONFIG_END;
  2028. }
  2029. for (csum = 0; word < limit; ++word)
  2030. csum += le16_to_cpu(*word);
  2031. if (~csum & 0xffff) {
  2032. EFX_ERR(efx, "NVRAM has incorrect checksum\n");
  2033. goto out;
  2034. }
  2035. rc = 0;
  2036. if (nvconfig_out)
  2037. memcpy(nvconfig_out, nvconfig, sizeof(*nvconfig));
  2038. out:
  2039. kfree(region);
  2040. return rc;
  2041. }
  2042. /* Registers tested in the falcon register test */
  2043. static struct {
  2044. unsigned address;
  2045. efx_oword_t mask;
  2046. } efx_test_registers[] = {
  2047. { FR_AZ_ADR_REGION,
  2048. EFX_OWORD32(0x0001FFFF, 0x0001FFFF, 0x0001FFFF, 0x0001FFFF) },
  2049. { FR_AZ_RX_CFG,
  2050. EFX_OWORD32(0xFFFFFFFE, 0x00017FFF, 0x00000000, 0x00000000) },
  2051. { FR_AZ_TX_CFG,
  2052. EFX_OWORD32(0x7FFF0037, 0x00000000, 0x00000000, 0x00000000) },
  2053. { FR_AZ_TX_RESERVED,
  2054. EFX_OWORD32(0xFFFEFE80, 0x1FFFFFFF, 0x020000FE, 0x007FFFFF) },
  2055. { FR_AB_MAC_CTRL,
  2056. EFX_OWORD32(0xFFFF0000, 0x00000000, 0x00000000, 0x00000000) },
  2057. { FR_AZ_SRM_TX_DC_CFG,
  2058. EFX_OWORD32(0x001FFFFF, 0x00000000, 0x00000000, 0x00000000) },
  2059. { FR_AZ_RX_DC_CFG,
  2060. EFX_OWORD32(0x0000000F, 0x00000000, 0x00000000, 0x00000000) },
  2061. { FR_AZ_RX_DC_PF_WM,
  2062. EFX_OWORD32(0x000003FF, 0x00000000, 0x00000000, 0x00000000) },
  2063. { FR_BZ_DP_CTRL,
  2064. EFX_OWORD32(0x00000FFF, 0x00000000, 0x00000000, 0x00000000) },
  2065. { FR_AB_GM_CFG2,
  2066. EFX_OWORD32(0x00007337, 0x00000000, 0x00000000, 0x00000000) },
  2067. { FR_AB_GMF_CFG0,
  2068. EFX_OWORD32(0x00001F1F, 0x00000000, 0x00000000, 0x00000000) },
  2069. { FR_AB_XM_GLB_CFG,
  2070. EFX_OWORD32(0x00000C68, 0x00000000, 0x00000000, 0x00000000) },
  2071. { FR_AB_XM_TX_CFG,
  2072. EFX_OWORD32(0x00080164, 0x00000000, 0x00000000, 0x00000000) },
  2073. { FR_AB_XM_RX_CFG,
  2074. EFX_OWORD32(0x07100A0C, 0x00000000, 0x00000000, 0x00000000) },
  2075. { FR_AB_XM_RX_PARAM,
  2076. EFX_OWORD32(0x00001FF8, 0x00000000, 0x00000000, 0x00000000) },
  2077. { FR_AB_XM_FC,
  2078. EFX_OWORD32(0xFFFF0001, 0x00000000, 0x00000000, 0x00000000) },
  2079. { FR_AB_XM_ADR_LO,
  2080. EFX_OWORD32(0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000) },
  2081. { FR_AB_XX_SD_CTL,
  2082. EFX_OWORD32(0x0003FF0F, 0x00000000, 0x00000000, 0x00000000) },
  2083. };
  2084. static bool efx_masked_compare_oword(const efx_oword_t *a, const efx_oword_t *b,
  2085. const efx_oword_t *mask)
  2086. {
  2087. return ((a->u64[0] ^ b->u64[0]) & mask->u64[0]) ||
  2088. ((a->u64[1] ^ b->u64[1]) & mask->u64[1]);
  2089. }
  2090. int falcon_test_registers(struct efx_nic *efx)
  2091. {
  2092. unsigned address = 0, i, j;
  2093. efx_oword_t mask, imask, original, reg, buf;
  2094. /* Falcon should be in loopback to isolate the XMAC from the PHY */
  2095. WARN_ON(!LOOPBACK_INTERNAL(efx));
  2096. for (i = 0; i < ARRAY_SIZE(efx_test_registers); ++i) {
  2097. address = efx_test_registers[i].address;
  2098. mask = imask = efx_test_registers[i].mask;
  2099. EFX_INVERT_OWORD(imask);
  2100. efx_reado(efx, &original, address);
  2101. /* bit sweep on and off */
  2102. for (j = 0; j < 128; j++) {
  2103. if (!EFX_EXTRACT_OWORD32(mask, j, j))
  2104. continue;
  2105. /* Test this testable bit can be set in isolation */
  2106. EFX_AND_OWORD(reg, original, mask);
  2107. EFX_SET_OWORD32(reg, j, j, 1);
  2108. efx_writeo(efx, &reg, address);
  2109. efx_reado(efx, &buf, address);
  2110. if (efx_masked_compare_oword(&reg, &buf, &mask))
  2111. goto fail;
  2112. /* Test this testable bit can be cleared in isolation */
  2113. EFX_OR_OWORD(reg, original, mask);
  2114. EFX_SET_OWORD32(reg, j, j, 0);
  2115. efx_writeo(efx, &reg, address);
  2116. efx_reado(efx, &buf, address);
  2117. if (efx_masked_compare_oword(&reg, &buf, &mask))
  2118. goto fail;
  2119. }
  2120. efx_writeo(efx, &original, address);
  2121. }
  2122. return 0;
  2123. fail:
  2124. EFX_ERR(efx, "wrote "EFX_OWORD_FMT" read "EFX_OWORD_FMT
  2125. " at address 0x%x mask "EFX_OWORD_FMT"\n", EFX_OWORD_VAL(reg),
  2126. EFX_OWORD_VAL(buf), address, EFX_OWORD_VAL(mask));
  2127. return -EIO;
  2128. }
  2129. /**************************************************************************
  2130. *
  2131. * Device reset
  2132. *
  2133. **************************************************************************
  2134. */
  2135. /* Resets NIC to known state. This routine must be called in process
  2136. * context and is allowed to sleep. */
  2137. int falcon_reset_hw(struct efx_nic *efx, enum reset_type method)
  2138. {
  2139. struct falcon_nic_data *nic_data = efx->nic_data;
  2140. efx_oword_t glb_ctl_reg_ker;
  2141. int rc;
  2142. EFX_LOG(efx, "performing %s hardware reset\n", RESET_TYPE(method));
  2143. /* Initiate device reset */
  2144. if (method == RESET_TYPE_WORLD) {
  2145. rc = pci_save_state(efx->pci_dev);
  2146. if (rc) {
  2147. EFX_ERR(efx, "failed to backup PCI state of primary "
  2148. "function prior to hardware reset\n");
  2149. goto fail1;
  2150. }
  2151. if (FALCON_IS_DUAL_FUNC(efx)) {
  2152. rc = pci_save_state(nic_data->pci_dev2);
  2153. if (rc) {
  2154. EFX_ERR(efx, "failed to backup PCI state of "
  2155. "secondary function prior to "
  2156. "hardware reset\n");
  2157. goto fail2;
  2158. }
  2159. }
  2160. EFX_POPULATE_OWORD_2(glb_ctl_reg_ker,
  2161. FRF_AB_EXT_PHY_RST_DUR,
  2162. FFE_AB_EXT_PHY_RST_DUR_10240US,
  2163. FRF_AB_SWRST, 1);
  2164. } else {
  2165. EFX_POPULATE_OWORD_7(glb_ctl_reg_ker,
  2166. /* exclude PHY from "invisible" reset */
  2167. FRF_AB_EXT_PHY_RST_CTL,
  2168. method == RESET_TYPE_INVISIBLE,
  2169. /* exclude EEPROM/flash and PCIe */
  2170. FRF_AB_PCIE_CORE_RST_CTL, 1,
  2171. FRF_AB_PCIE_NSTKY_RST_CTL, 1,
  2172. FRF_AB_PCIE_SD_RST_CTL, 1,
  2173. FRF_AB_EE_RST_CTL, 1,
  2174. FRF_AB_EXT_PHY_RST_DUR,
  2175. FFE_AB_EXT_PHY_RST_DUR_10240US,
  2176. FRF_AB_SWRST, 1);
  2177. }
  2178. efx_writeo(efx, &glb_ctl_reg_ker, FR_AB_GLB_CTL);
  2179. EFX_LOG(efx, "waiting for hardware reset\n");
  2180. schedule_timeout_uninterruptible(HZ / 20);
  2181. /* Restore PCI configuration if needed */
  2182. if (method == RESET_TYPE_WORLD) {
  2183. if (FALCON_IS_DUAL_FUNC(efx)) {
  2184. rc = pci_restore_state(nic_data->pci_dev2);
  2185. if (rc) {
  2186. EFX_ERR(efx, "failed to restore PCI config for "
  2187. "the secondary function\n");
  2188. goto fail3;
  2189. }
  2190. }
  2191. rc = pci_restore_state(efx->pci_dev);
  2192. if (rc) {
  2193. EFX_ERR(efx, "failed to restore PCI config for the "
  2194. "primary function\n");
  2195. goto fail4;
  2196. }
  2197. EFX_LOG(efx, "successfully restored PCI config\n");
  2198. }
  2199. /* Assert that reset complete */
  2200. efx_reado(efx, &glb_ctl_reg_ker, FR_AB_GLB_CTL);
  2201. if (EFX_OWORD_FIELD(glb_ctl_reg_ker, FRF_AB_SWRST) != 0) {
  2202. rc = -ETIMEDOUT;
  2203. EFX_ERR(efx, "timed out waiting for hardware reset\n");
  2204. goto fail5;
  2205. }
  2206. EFX_LOG(efx, "hardware reset complete\n");
  2207. return 0;
  2208. /* pci_save_state() and pci_restore_state() MUST be called in pairs */
  2209. fail2:
  2210. fail3:
  2211. pci_restore_state(efx->pci_dev);
  2212. fail1:
  2213. fail4:
  2214. fail5:
  2215. return rc;
  2216. }
  2217. void falcon_monitor(struct efx_nic *efx)
  2218. {
  2219. bool link_changed;
  2220. int rc;
  2221. BUG_ON(!mutex_is_locked(&efx->mac_lock));
  2222. rc = falcon_board(efx)->type->monitor(efx);
  2223. if (rc) {
  2224. EFX_ERR(efx, "Board sensor %s; shutting down PHY\n",
  2225. (rc == -ERANGE) ? "reported fault" : "failed");
  2226. efx->phy_mode |= PHY_MODE_LOW_POWER;
  2227. __efx_reconfigure_port(efx);
  2228. }
  2229. if (LOOPBACK_INTERNAL(efx))
  2230. link_changed = falcon_loopback_link_poll(efx);
  2231. else
  2232. link_changed = efx->phy_op->poll(efx);
  2233. if (link_changed) {
  2234. falcon_stop_nic_stats(efx);
  2235. falcon_deconfigure_mac_wrapper(efx);
  2236. falcon_switch_mac(efx);
  2237. efx->mac_op->reconfigure(efx);
  2238. falcon_start_nic_stats(efx);
  2239. efx_link_status_changed(efx);
  2240. }
  2241. if (EFX_IS10G(efx))
  2242. falcon_poll_xmac(efx);
  2243. }
  2244. /* Zeroes out the SRAM contents. This routine must be called in
  2245. * process context and is allowed to sleep.
  2246. */
  2247. static int falcon_reset_sram(struct efx_nic *efx)
  2248. {
  2249. efx_oword_t srm_cfg_reg_ker, gpio_cfg_reg_ker;
  2250. int count;
  2251. /* Set the SRAM wake/sleep GPIO appropriately. */
  2252. efx_reado(efx, &gpio_cfg_reg_ker, FR_AB_GPIO_CTL);
  2253. EFX_SET_OWORD_FIELD(gpio_cfg_reg_ker, FRF_AB_GPIO1_OEN, 1);
  2254. EFX_SET_OWORD_FIELD(gpio_cfg_reg_ker, FRF_AB_GPIO1_OUT, 1);
  2255. efx_writeo(efx, &gpio_cfg_reg_ker, FR_AB_GPIO_CTL);
  2256. /* Initiate SRAM reset */
  2257. EFX_POPULATE_OWORD_2(srm_cfg_reg_ker,
  2258. FRF_AZ_SRM_INIT_EN, 1,
  2259. FRF_AZ_SRM_NB_SZ, 0);
  2260. efx_writeo(efx, &srm_cfg_reg_ker, FR_AZ_SRM_CFG);
  2261. /* Wait for SRAM reset to complete */
  2262. count = 0;
  2263. do {
  2264. EFX_LOG(efx, "waiting for SRAM reset (attempt %d)...\n", count);
  2265. /* SRAM reset is slow; expect around 16ms */
  2266. schedule_timeout_uninterruptible(HZ / 50);
  2267. /* Check for reset complete */
  2268. efx_reado(efx, &srm_cfg_reg_ker, FR_AZ_SRM_CFG);
  2269. if (!EFX_OWORD_FIELD(srm_cfg_reg_ker, FRF_AZ_SRM_INIT_EN)) {
  2270. EFX_LOG(efx, "SRAM reset complete\n");
  2271. return 0;
  2272. }
  2273. } while (++count < 20); /* wait upto 0.4 sec */
  2274. EFX_ERR(efx, "timed out waiting for SRAM reset\n");
  2275. return -ETIMEDOUT;
  2276. }
  2277. static int falcon_spi_device_init(struct efx_nic *efx,
  2278. struct efx_spi_device **spi_device_ret,
  2279. unsigned int device_id, u32 device_type)
  2280. {
  2281. struct efx_spi_device *spi_device;
  2282. if (device_type != 0) {
  2283. spi_device = kzalloc(sizeof(*spi_device), GFP_KERNEL);
  2284. if (!spi_device)
  2285. return -ENOMEM;
  2286. spi_device->device_id = device_id;
  2287. spi_device->size =
  2288. 1 << SPI_DEV_TYPE_FIELD(device_type, SPI_DEV_TYPE_SIZE);
  2289. spi_device->addr_len =
  2290. SPI_DEV_TYPE_FIELD(device_type, SPI_DEV_TYPE_ADDR_LEN);
  2291. spi_device->munge_address = (spi_device->size == 1 << 9 &&
  2292. spi_device->addr_len == 1);
  2293. spi_device->erase_command =
  2294. SPI_DEV_TYPE_FIELD(device_type, SPI_DEV_TYPE_ERASE_CMD);
  2295. spi_device->erase_size =
  2296. 1 << SPI_DEV_TYPE_FIELD(device_type,
  2297. SPI_DEV_TYPE_ERASE_SIZE);
  2298. spi_device->block_size =
  2299. 1 << SPI_DEV_TYPE_FIELD(device_type,
  2300. SPI_DEV_TYPE_BLOCK_SIZE);
  2301. spi_device->efx = efx;
  2302. } else {
  2303. spi_device = NULL;
  2304. }
  2305. kfree(*spi_device_ret);
  2306. *spi_device_ret = spi_device;
  2307. return 0;
  2308. }
  2309. static void falcon_remove_spi_devices(struct efx_nic *efx)
  2310. {
  2311. kfree(efx->spi_eeprom);
  2312. efx->spi_eeprom = NULL;
  2313. kfree(efx->spi_flash);
  2314. efx->spi_flash = NULL;
  2315. }
  2316. /* Extract non-volatile configuration */
  2317. static int falcon_probe_nvconfig(struct efx_nic *efx)
  2318. {
  2319. struct falcon_nvconfig *nvconfig;
  2320. int board_rev;
  2321. int rc;
  2322. nvconfig = kmalloc(sizeof(*nvconfig), GFP_KERNEL);
  2323. if (!nvconfig)
  2324. return -ENOMEM;
  2325. rc = falcon_read_nvram(efx, nvconfig);
  2326. if (rc == -EINVAL) {
  2327. EFX_ERR(efx, "NVRAM is invalid therefore using defaults\n");
  2328. efx->phy_type = PHY_TYPE_NONE;
  2329. efx->mdio.prtad = MDIO_PRTAD_NONE;
  2330. board_rev = 0;
  2331. rc = 0;
  2332. } else if (rc) {
  2333. goto fail1;
  2334. } else {
  2335. struct falcon_nvconfig_board_v2 *v2 = &nvconfig->board_v2;
  2336. struct falcon_nvconfig_board_v3 *v3 = &nvconfig->board_v3;
  2337. efx->phy_type = v2->port0_phy_type;
  2338. efx->mdio.prtad = v2->port0_phy_addr;
  2339. board_rev = le16_to_cpu(v2->board_revision);
  2340. if (le16_to_cpu(nvconfig->board_struct_ver) >= 3) {
  2341. rc = falcon_spi_device_init(
  2342. efx, &efx->spi_flash, FFE_AB_SPI_DEVICE_FLASH,
  2343. le32_to_cpu(v3->spi_device_type
  2344. [FFE_AB_SPI_DEVICE_FLASH]));
  2345. if (rc)
  2346. goto fail2;
  2347. rc = falcon_spi_device_init(
  2348. efx, &efx->spi_eeprom, FFE_AB_SPI_DEVICE_EEPROM,
  2349. le32_to_cpu(v3->spi_device_type
  2350. [FFE_AB_SPI_DEVICE_EEPROM]));
  2351. if (rc)
  2352. goto fail2;
  2353. }
  2354. }
  2355. /* Read the MAC addresses */
  2356. memcpy(efx->mac_address, nvconfig->mac_address[0], ETH_ALEN);
  2357. EFX_LOG(efx, "PHY is %d phy_id %d\n", efx->phy_type, efx->mdio.prtad);
  2358. falcon_probe_board(efx, board_rev);
  2359. kfree(nvconfig);
  2360. return 0;
  2361. fail2:
  2362. falcon_remove_spi_devices(efx);
  2363. fail1:
  2364. kfree(nvconfig);
  2365. return rc;
  2366. }
  2367. /* Probe the NIC variant (revision, ASIC vs FPGA, function count, port
  2368. * count, port speed). Set workaround and feature flags accordingly.
  2369. */
  2370. static int falcon_probe_nic_variant(struct efx_nic *efx)
  2371. {
  2372. efx_oword_t altera_build;
  2373. efx_oword_t nic_stat;
  2374. efx_reado(efx, &altera_build, FR_AZ_ALTERA_BUILD);
  2375. if (EFX_OWORD_FIELD(altera_build, FRF_AZ_ALTERA_BUILD_VER)) {
  2376. EFX_ERR(efx, "Falcon FPGA not supported\n");
  2377. return -ENODEV;
  2378. }
  2379. efx_reado(efx, &nic_stat, FR_AB_NIC_STAT);
  2380. switch (falcon_rev(efx)) {
  2381. case FALCON_REV_A0:
  2382. case 0xff:
  2383. EFX_ERR(efx, "Falcon rev A0 not supported\n");
  2384. return -ENODEV;
  2385. case FALCON_REV_A1:
  2386. if (EFX_OWORD_FIELD(nic_stat, FRF_AA_STRAP_PCIE) == 0) {
  2387. EFX_ERR(efx, "Falcon rev A1 PCI-X not supported\n");
  2388. return -ENODEV;
  2389. }
  2390. break;
  2391. case FALCON_REV_B0:
  2392. break;
  2393. default:
  2394. EFX_ERR(efx, "Unknown Falcon rev %d\n", falcon_rev(efx));
  2395. return -ENODEV;
  2396. }
  2397. /* Initial assumed speed */
  2398. efx->link_state.speed = EFX_OWORD_FIELD(nic_stat, FRF_AB_STRAP_10G) ? 10000 : 1000;
  2399. return 0;
  2400. }
  2401. /* Probe all SPI devices on the NIC */
  2402. static void falcon_probe_spi_devices(struct efx_nic *efx)
  2403. {
  2404. efx_oword_t nic_stat, gpio_ctl, ee_vpd_cfg;
  2405. int boot_dev;
  2406. efx_reado(efx, &gpio_ctl, FR_AB_GPIO_CTL);
  2407. efx_reado(efx, &nic_stat, FR_AB_NIC_STAT);
  2408. efx_reado(efx, &ee_vpd_cfg, FR_AB_EE_VPD_CFG0);
  2409. if (EFX_OWORD_FIELD(gpio_ctl, FRF_AB_GPIO3_PWRUP_VALUE)) {
  2410. boot_dev = (EFX_OWORD_FIELD(nic_stat, FRF_AB_SF_PRST) ?
  2411. FFE_AB_SPI_DEVICE_FLASH : FFE_AB_SPI_DEVICE_EEPROM);
  2412. EFX_LOG(efx, "Booted from %s\n",
  2413. boot_dev == FFE_AB_SPI_DEVICE_FLASH ? "flash" : "EEPROM");
  2414. } else {
  2415. /* Disable VPD and set clock dividers to safe
  2416. * values for initial programming. */
  2417. boot_dev = -1;
  2418. EFX_LOG(efx, "Booted from internal ASIC settings;"
  2419. " setting SPI config\n");
  2420. EFX_POPULATE_OWORD_3(ee_vpd_cfg, FRF_AB_EE_VPD_EN, 0,
  2421. /* 125 MHz / 7 ~= 20 MHz */
  2422. FRF_AB_EE_SF_CLOCK_DIV, 7,
  2423. /* 125 MHz / 63 ~= 2 MHz */
  2424. FRF_AB_EE_EE_CLOCK_DIV, 63);
  2425. efx_writeo(efx, &ee_vpd_cfg, FR_AB_EE_VPD_CFG0);
  2426. }
  2427. if (boot_dev == FFE_AB_SPI_DEVICE_FLASH)
  2428. falcon_spi_device_init(efx, &efx->spi_flash,
  2429. FFE_AB_SPI_DEVICE_FLASH,
  2430. default_flash_type);
  2431. if (boot_dev == FFE_AB_SPI_DEVICE_EEPROM)
  2432. falcon_spi_device_init(efx, &efx->spi_eeprom,
  2433. FFE_AB_SPI_DEVICE_EEPROM,
  2434. large_eeprom_type);
  2435. }
  2436. int falcon_probe_nic(struct efx_nic *efx)
  2437. {
  2438. struct falcon_nic_data *nic_data;
  2439. struct falcon_board *board;
  2440. int rc;
  2441. /* Allocate storage for hardware specific data */
  2442. nic_data = kzalloc(sizeof(*nic_data), GFP_KERNEL);
  2443. if (!nic_data)
  2444. return -ENOMEM;
  2445. efx->nic_data = nic_data;
  2446. /* Determine number of ports etc. */
  2447. rc = falcon_probe_nic_variant(efx);
  2448. if (rc)
  2449. goto fail1;
  2450. /* Probe secondary function if expected */
  2451. if (FALCON_IS_DUAL_FUNC(efx)) {
  2452. struct pci_dev *dev = pci_dev_get(efx->pci_dev);
  2453. while ((dev = pci_get_device(EFX_VENDID_SFC, FALCON_A_S_DEVID,
  2454. dev))) {
  2455. if (dev->bus == efx->pci_dev->bus &&
  2456. dev->devfn == efx->pci_dev->devfn + 1) {
  2457. nic_data->pci_dev2 = dev;
  2458. break;
  2459. }
  2460. }
  2461. if (!nic_data->pci_dev2) {
  2462. EFX_ERR(efx, "failed to find secondary function\n");
  2463. rc = -ENODEV;
  2464. goto fail2;
  2465. }
  2466. }
  2467. /* Now we can reset the NIC */
  2468. rc = falcon_reset_hw(efx, RESET_TYPE_ALL);
  2469. if (rc) {
  2470. EFX_ERR(efx, "failed to reset NIC\n");
  2471. goto fail3;
  2472. }
  2473. /* Allocate memory for INT_KER */
  2474. rc = falcon_alloc_buffer(efx, &efx->irq_status, sizeof(efx_oword_t));
  2475. if (rc)
  2476. goto fail4;
  2477. BUG_ON(efx->irq_status.dma_addr & 0x0f);
  2478. EFX_LOG(efx, "INT_KER at %llx (virt %p phys %llx)\n",
  2479. (u64)efx->irq_status.dma_addr,
  2480. efx->irq_status.addr, (u64)virt_to_phys(efx->irq_status.addr));
  2481. falcon_probe_spi_devices(efx);
  2482. /* Read in the non-volatile configuration */
  2483. rc = falcon_probe_nvconfig(efx);
  2484. if (rc)
  2485. goto fail5;
  2486. /* Initialise I2C adapter */
  2487. board = falcon_board(efx);
  2488. board->i2c_adap.owner = THIS_MODULE;
  2489. board->i2c_data = falcon_i2c_bit_operations;
  2490. board->i2c_data.data = efx;
  2491. board->i2c_adap.algo_data = &board->i2c_data;
  2492. board->i2c_adap.dev.parent = &efx->pci_dev->dev;
  2493. strlcpy(board->i2c_adap.name, "SFC4000 GPIO",
  2494. sizeof(board->i2c_adap.name));
  2495. rc = i2c_bit_add_bus(&board->i2c_adap);
  2496. if (rc)
  2497. goto fail5;
  2498. rc = falcon_board(efx)->type->init(efx);
  2499. if (rc) {
  2500. EFX_ERR(efx, "failed to initialise board\n");
  2501. goto fail6;
  2502. }
  2503. nic_data->stats_disable_count = 1;
  2504. setup_timer(&nic_data->stats_timer, &falcon_stats_timer_func,
  2505. (unsigned long)efx);
  2506. return 0;
  2507. fail6:
  2508. BUG_ON(i2c_del_adapter(&board->i2c_adap));
  2509. memset(&board->i2c_adap, 0, sizeof(board->i2c_adap));
  2510. fail5:
  2511. falcon_remove_spi_devices(efx);
  2512. falcon_free_buffer(efx, &efx->irq_status);
  2513. fail4:
  2514. fail3:
  2515. if (nic_data->pci_dev2) {
  2516. pci_dev_put(nic_data->pci_dev2);
  2517. nic_data->pci_dev2 = NULL;
  2518. }
  2519. fail2:
  2520. fail1:
  2521. kfree(efx->nic_data);
  2522. return rc;
  2523. }
  2524. static void falcon_init_rx_cfg(struct efx_nic *efx)
  2525. {
  2526. /* Prior to Siena the RX DMA engine will split each frame at
  2527. * intervals of RX_USR_BUF_SIZE (32-byte units). We set it to
  2528. * be so large that that never happens. */
  2529. const unsigned huge_buf_size = (3 * 4096) >> 5;
  2530. /* RX control FIFO thresholds (32 entries) */
  2531. const unsigned ctrl_xon_thr = 20;
  2532. const unsigned ctrl_xoff_thr = 25;
  2533. /* RX data FIFO thresholds (256-byte units; size varies) */
  2534. int data_xon_thr = rx_xon_thresh_bytes >> 8;
  2535. int data_xoff_thr = rx_xoff_thresh_bytes >> 8;
  2536. efx_oword_t reg;
  2537. efx_reado(efx, &reg, FR_AZ_RX_CFG);
  2538. if (falcon_rev(efx) <= FALCON_REV_A1) {
  2539. /* Data FIFO size is 5.5K */
  2540. if (data_xon_thr < 0)
  2541. data_xon_thr = 512 >> 8;
  2542. if (data_xoff_thr < 0)
  2543. data_xoff_thr = 2048 >> 8;
  2544. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_DESC_PUSH_EN, 0);
  2545. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_USR_BUF_SIZE,
  2546. huge_buf_size);
  2547. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XON_MAC_TH, data_xon_thr);
  2548. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XOFF_MAC_TH, data_xoff_thr);
  2549. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XON_TX_TH, ctrl_xon_thr);
  2550. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XOFF_TX_TH, ctrl_xoff_thr);
  2551. } else {
  2552. /* Data FIFO size is 80K; register fields moved */
  2553. if (data_xon_thr < 0)
  2554. data_xon_thr = 27648 >> 8; /* ~3*max MTU */
  2555. if (data_xoff_thr < 0)
  2556. data_xoff_thr = 54272 >> 8; /* ~80Kb - 3*max MTU */
  2557. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_DESC_PUSH_EN, 0);
  2558. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_USR_BUF_SIZE,
  2559. huge_buf_size);
  2560. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XON_MAC_TH, data_xon_thr);
  2561. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XOFF_MAC_TH, data_xoff_thr);
  2562. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XON_TX_TH, ctrl_xon_thr);
  2563. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XOFF_TX_TH, ctrl_xoff_thr);
  2564. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_INGR_EN, 1);
  2565. }
  2566. efx_writeo(efx, &reg, FR_AZ_RX_CFG);
  2567. }
  2568. /* This call performs hardware-specific global initialisation, such as
  2569. * defining the descriptor cache sizes and number of RSS channels.
  2570. * It does not set up any buffers, descriptor rings or event queues.
  2571. */
  2572. int falcon_init_nic(struct efx_nic *efx)
  2573. {
  2574. efx_oword_t temp;
  2575. int rc;
  2576. /* Use on-chip SRAM */
  2577. efx_reado(efx, &temp, FR_AB_NIC_STAT);
  2578. EFX_SET_OWORD_FIELD(temp, FRF_AB_ONCHIP_SRAM, 1);
  2579. efx_writeo(efx, &temp, FR_AB_NIC_STAT);
  2580. /* Set the source of the GMAC clock */
  2581. if (falcon_rev(efx) == FALCON_REV_B0) {
  2582. efx_reado(efx, &temp, FR_AB_GPIO_CTL);
  2583. EFX_SET_OWORD_FIELD(temp, FRF_AB_USE_NIC_CLK, true);
  2584. efx_writeo(efx, &temp, FR_AB_GPIO_CTL);
  2585. }
  2586. /* Select the correct MAC */
  2587. falcon_clock_mac(efx);
  2588. rc = falcon_reset_sram(efx);
  2589. if (rc)
  2590. return rc;
  2591. /* Set positions of descriptor caches in SRAM. */
  2592. EFX_POPULATE_OWORD_1(temp, FRF_AZ_SRM_TX_DC_BASE_ADR, TX_DC_BASE / 8);
  2593. efx_writeo(efx, &temp, FR_AZ_SRM_TX_DC_CFG);
  2594. EFX_POPULATE_OWORD_1(temp, FRF_AZ_SRM_RX_DC_BASE_ADR, RX_DC_BASE / 8);
  2595. efx_writeo(efx, &temp, FR_AZ_SRM_RX_DC_CFG);
  2596. /* Set TX descriptor cache size. */
  2597. BUILD_BUG_ON(TX_DC_ENTRIES != (8 << TX_DC_ENTRIES_ORDER));
  2598. EFX_POPULATE_OWORD_1(temp, FRF_AZ_TX_DC_SIZE, TX_DC_ENTRIES_ORDER);
  2599. efx_writeo(efx, &temp, FR_AZ_TX_DC_CFG);
  2600. /* Set RX descriptor cache size. Set low watermark to size-8, as
  2601. * this allows most efficient prefetching.
  2602. */
  2603. BUILD_BUG_ON(RX_DC_ENTRIES != (8 << RX_DC_ENTRIES_ORDER));
  2604. EFX_POPULATE_OWORD_1(temp, FRF_AZ_RX_DC_SIZE, RX_DC_ENTRIES_ORDER);
  2605. efx_writeo(efx, &temp, FR_AZ_RX_DC_CFG);
  2606. EFX_POPULATE_OWORD_1(temp, FRF_AZ_RX_DC_PF_LWM, RX_DC_ENTRIES - 8);
  2607. efx_writeo(efx, &temp, FR_AZ_RX_DC_PF_WM);
  2608. /* Clear the parity enables on the TX data fifos as
  2609. * they produce false parity errors because of timing issues
  2610. */
  2611. if (EFX_WORKAROUND_5129(efx)) {
  2612. efx_reado(efx, &temp, FR_AZ_CSR_SPARE);
  2613. EFX_SET_OWORD_FIELD(temp, FRF_AB_MEM_PERR_EN_TX_DATA, 0);
  2614. efx_writeo(efx, &temp, FR_AZ_CSR_SPARE);
  2615. }
  2616. /* Enable all the genuinely fatal interrupts. (They are still
  2617. * masked by the overall interrupt mask, controlled by
  2618. * falcon_interrupts()).
  2619. *
  2620. * Note: All other fatal interrupts are enabled
  2621. */
  2622. EFX_POPULATE_OWORD_3(temp,
  2623. FRF_AZ_ILL_ADR_INT_KER_EN, 1,
  2624. FRF_AZ_RBUF_OWN_INT_KER_EN, 1,
  2625. FRF_AZ_TBUF_OWN_INT_KER_EN, 1);
  2626. EFX_INVERT_OWORD(temp);
  2627. efx_writeo(efx, &temp, FR_AZ_FATAL_INTR_KER);
  2628. if (EFX_WORKAROUND_7244(efx)) {
  2629. efx_reado(efx, &temp, FR_BZ_RX_FILTER_CTL);
  2630. EFX_SET_OWORD_FIELD(temp, FRF_BZ_UDP_FULL_SRCH_LIMIT, 8);
  2631. EFX_SET_OWORD_FIELD(temp, FRF_BZ_UDP_WILD_SRCH_LIMIT, 8);
  2632. EFX_SET_OWORD_FIELD(temp, FRF_BZ_TCP_FULL_SRCH_LIMIT, 8);
  2633. EFX_SET_OWORD_FIELD(temp, FRF_BZ_TCP_WILD_SRCH_LIMIT, 8);
  2634. efx_writeo(efx, &temp, FR_BZ_RX_FILTER_CTL);
  2635. }
  2636. falcon_setup_rss_indir_table(efx);
  2637. /* XXX This is documented only for Falcon A0/A1 */
  2638. /* Setup RX. Wait for descriptor is broken and must
  2639. * be disabled. RXDP recovery shouldn't be needed, but is.
  2640. */
  2641. efx_reado(efx, &temp, FR_AA_RX_SELF_RST);
  2642. EFX_SET_OWORD_FIELD(temp, FRF_AA_RX_NODESC_WAIT_DIS, 1);
  2643. EFX_SET_OWORD_FIELD(temp, FRF_AA_RX_SELF_RST_EN, 1);
  2644. if (EFX_WORKAROUND_5583(efx))
  2645. EFX_SET_OWORD_FIELD(temp, FRF_AA_RX_ISCSI_DIS, 1);
  2646. efx_writeo(efx, &temp, FR_AA_RX_SELF_RST);
  2647. /* Disable the ugly timer-based TX DMA backoff and allow TX DMA to be
  2648. * controlled by the RX FIFO fill level. Set arbitration to one pkt/Q.
  2649. */
  2650. efx_reado(efx, &temp, FR_AZ_TX_RESERVED);
  2651. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_RX_SPACER, 0xfe);
  2652. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_RX_SPACER_EN, 1);
  2653. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_ONE_PKT_PER_Q, 1);
  2654. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_PUSH_EN, 0);
  2655. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_DIS_NON_IP_EV, 1);
  2656. /* Enable SW_EV to inherit in char driver - assume harmless here */
  2657. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_SOFT_EVT_EN, 1);
  2658. /* Prefetch threshold 2 => fetch when descriptor cache half empty */
  2659. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_PREF_THRESHOLD, 2);
  2660. /* Squash TX of packets of 16 bytes or less */
  2661. if (falcon_rev(efx) >= FALCON_REV_B0 && EFX_WORKAROUND_9141(efx))
  2662. EFX_SET_OWORD_FIELD(temp, FRF_BZ_TX_FLUSH_MIN_LEN_EN, 1);
  2663. efx_writeo(efx, &temp, FR_AZ_TX_RESERVED);
  2664. /* Do not enable TX_NO_EOP_DISC_EN, since it limits packets to 16
  2665. * descriptors (which is bad).
  2666. */
  2667. efx_reado(efx, &temp, FR_AZ_TX_CFG);
  2668. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_NO_EOP_DISC_EN, 0);
  2669. efx_writeo(efx, &temp, FR_AZ_TX_CFG);
  2670. falcon_init_rx_cfg(efx);
  2671. /* Set destination of both TX and RX Flush events */
  2672. if (falcon_rev(efx) >= FALCON_REV_B0) {
  2673. EFX_POPULATE_OWORD_1(temp, FRF_BZ_FLS_EVQ_ID, 0);
  2674. efx_writeo(efx, &temp, FR_BZ_DP_CTRL);
  2675. }
  2676. return 0;
  2677. }
  2678. void falcon_remove_nic(struct efx_nic *efx)
  2679. {
  2680. struct falcon_nic_data *nic_data = efx->nic_data;
  2681. struct falcon_board *board = falcon_board(efx);
  2682. int rc;
  2683. board->type->fini(efx);
  2684. /* Remove I2C adapter and clear it in preparation for a retry */
  2685. rc = i2c_del_adapter(&board->i2c_adap);
  2686. BUG_ON(rc);
  2687. memset(&board->i2c_adap, 0, sizeof(board->i2c_adap));
  2688. falcon_remove_spi_devices(efx);
  2689. falcon_free_buffer(efx, &efx->irq_status);
  2690. falcon_reset_hw(efx, RESET_TYPE_ALL);
  2691. /* Release the second function after the reset */
  2692. if (nic_data->pci_dev2) {
  2693. pci_dev_put(nic_data->pci_dev2);
  2694. nic_data->pci_dev2 = NULL;
  2695. }
  2696. /* Tear down the private nic state */
  2697. kfree(efx->nic_data);
  2698. efx->nic_data = NULL;
  2699. }
  2700. void falcon_update_nic_stats(struct efx_nic *efx)
  2701. {
  2702. struct falcon_nic_data *nic_data = efx->nic_data;
  2703. efx_oword_t cnt;
  2704. if (nic_data->stats_disable_count)
  2705. return;
  2706. efx_reado(efx, &cnt, FR_AZ_RX_NODESC_DROP);
  2707. efx->n_rx_nodesc_drop_cnt +=
  2708. EFX_OWORD_FIELD(cnt, FRF_AB_RX_NODESC_DROP_CNT);
  2709. if (nic_data->stats_pending &&
  2710. *nic_data->stats_dma_done == FALCON_STATS_DONE) {
  2711. nic_data->stats_pending = false;
  2712. rmb(); /* read the done flag before the stats */
  2713. efx->mac_op->update_stats(efx);
  2714. }
  2715. }
  2716. void falcon_start_nic_stats(struct efx_nic *efx)
  2717. {
  2718. struct falcon_nic_data *nic_data = efx->nic_data;
  2719. spin_lock_bh(&efx->stats_lock);
  2720. if (--nic_data->stats_disable_count == 0)
  2721. falcon_stats_request(efx);
  2722. spin_unlock_bh(&efx->stats_lock);
  2723. }
  2724. void falcon_stop_nic_stats(struct efx_nic *efx)
  2725. {
  2726. struct falcon_nic_data *nic_data = efx->nic_data;
  2727. int i;
  2728. might_sleep();
  2729. spin_lock_bh(&efx->stats_lock);
  2730. ++nic_data->stats_disable_count;
  2731. spin_unlock_bh(&efx->stats_lock);
  2732. del_timer_sync(&nic_data->stats_timer);
  2733. /* Wait enough time for the most recent transfer to
  2734. * complete. */
  2735. for (i = 0; i < 4 && nic_data->stats_pending; i++) {
  2736. if (*nic_data->stats_dma_done == FALCON_STATS_DONE)
  2737. break;
  2738. msleep(1);
  2739. }
  2740. spin_lock_bh(&efx->stats_lock);
  2741. falcon_stats_complete(efx);
  2742. spin_unlock_bh(&efx->stats_lock);
  2743. }
  2744. /**************************************************************************
  2745. *
  2746. * Revision-dependent attributes used by efx.c
  2747. *
  2748. **************************************************************************
  2749. */
  2750. struct efx_nic_type falcon_a_nic_type = {
  2751. .mem_map_size = 0x20000,
  2752. .txd_ptr_tbl_base = FR_AA_TX_DESC_PTR_TBL_KER,
  2753. .rxd_ptr_tbl_base = FR_AA_RX_DESC_PTR_TBL_KER,
  2754. .buf_tbl_base = FR_AA_BUF_FULL_TBL_KER,
  2755. .evq_ptr_tbl_base = FR_AA_EVQ_PTR_TBL_KER,
  2756. .evq_rptr_tbl_base = FR_AA_EVQ_RPTR_KER,
  2757. .max_dma_mask = DMA_BIT_MASK(FSF_AZ_TX_KER_BUF_ADDR_WIDTH),
  2758. .rx_buffer_padding = 0x24,
  2759. .max_interrupt_mode = EFX_INT_MODE_MSI,
  2760. .phys_addr_channels = 4,
  2761. };
  2762. struct efx_nic_type falcon_b_nic_type = {
  2763. /* Map everything up to and including the RSS indirection
  2764. * table. Don't map MSI-X table, MSI-X PBA since Linux
  2765. * requires that they not be mapped. */
  2766. .mem_map_size = (FR_BZ_RX_INDIRECTION_TBL +
  2767. FR_BZ_RX_INDIRECTION_TBL_STEP *
  2768. FR_BZ_RX_INDIRECTION_TBL_ROWS),
  2769. .txd_ptr_tbl_base = FR_BZ_TX_DESC_PTR_TBL,
  2770. .rxd_ptr_tbl_base = FR_BZ_RX_DESC_PTR_TBL,
  2771. .buf_tbl_base = FR_BZ_BUF_FULL_TBL,
  2772. .evq_ptr_tbl_base = FR_BZ_EVQ_PTR_TBL,
  2773. .evq_rptr_tbl_base = FR_BZ_EVQ_RPTR,
  2774. .max_dma_mask = DMA_BIT_MASK(FSF_AZ_TX_KER_BUF_ADDR_WIDTH),
  2775. .rx_buffer_padding = 0,
  2776. .max_interrupt_mode = EFX_INT_MODE_MSIX,
  2777. .phys_addr_channels = 32, /* Hardware limit is 64, but the legacy
  2778. * interrupt handler only supports 32
  2779. * channels */
  2780. };