falcon.c 92 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257
  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. efx->phy_op->clear_interrupt(efx);
  772. queue_work(efx->workqueue, &efx->phy_work);
  773. handled = true;
  774. }
  775. if ((falcon_rev(efx) >= FALCON_REV_B0) &&
  776. EFX_QWORD_FIELD(*event, FSF_BB_GLB_EV_XG_MGT_INTR)) {
  777. efx->xmac_poll_required = true;
  778. handled = true;
  779. }
  780. if (falcon_rev(efx) <= FALCON_REV_A1 ?
  781. EFX_QWORD_FIELD(*event, FSF_AA_GLB_EV_RX_RECOVERY) :
  782. EFX_QWORD_FIELD(*event, FSF_BB_GLB_EV_RX_RECOVERY)) {
  783. EFX_ERR(efx, "channel %d seen global RX_RESET "
  784. "event. Resetting.\n", channel->channel);
  785. atomic_inc(&efx->rx_reset);
  786. efx_schedule_reset(efx, EFX_WORKAROUND_6555(efx) ?
  787. RESET_TYPE_RX_RECOVERY : RESET_TYPE_DISABLE);
  788. handled = true;
  789. }
  790. if (!handled)
  791. EFX_ERR(efx, "channel %d unknown global event "
  792. EFX_QWORD_FMT "\n", channel->channel,
  793. EFX_QWORD_VAL(*event));
  794. }
  795. static void falcon_handle_driver_event(struct efx_channel *channel,
  796. efx_qword_t *event)
  797. {
  798. struct efx_nic *efx = channel->efx;
  799. unsigned int ev_sub_code;
  800. unsigned int ev_sub_data;
  801. ev_sub_code = EFX_QWORD_FIELD(*event, FSF_AZ_DRIVER_EV_SUBCODE);
  802. ev_sub_data = EFX_QWORD_FIELD(*event, FSF_AZ_DRIVER_EV_SUBDATA);
  803. switch (ev_sub_code) {
  804. case FSE_AZ_TX_DESCQ_FLS_DONE_EV:
  805. EFX_TRACE(efx, "channel %d TXQ %d flushed\n",
  806. channel->channel, ev_sub_data);
  807. break;
  808. case FSE_AZ_RX_DESCQ_FLS_DONE_EV:
  809. EFX_TRACE(efx, "channel %d RXQ %d flushed\n",
  810. channel->channel, ev_sub_data);
  811. break;
  812. case FSE_AZ_EVQ_INIT_DONE_EV:
  813. EFX_LOG(efx, "channel %d EVQ %d initialised\n",
  814. channel->channel, ev_sub_data);
  815. break;
  816. case FSE_AZ_SRM_UPD_DONE_EV:
  817. EFX_TRACE(efx, "channel %d SRAM update done\n",
  818. channel->channel);
  819. break;
  820. case FSE_AZ_WAKE_UP_EV:
  821. EFX_TRACE(efx, "channel %d RXQ %d wakeup event\n",
  822. channel->channel, ev_sub_data);
  823. break;
  824. case FSE_AZ_TIMER_EV:
  825. EFX_TRACE(efx, "channel %d RX queue %d timer expired\n",
  826. channel->channel, ev_sub_data);
  827. break;
  828. case FSE_AA_RX_RECOVER_EV:
  829. EFX_ERR(efx, "channel %d seen DRIVER RX_RESET event. "
  830. "Resetting.\n", channel->channel);
  831. atomic_inc(&efx->rx_reset);
  832. efx_schedule_reset(efx,
  833. EFX_WORKAROUND_6555(efx) ?
  834. RESET_TYPE_RX_RECOVERY :
  835. RESET_TYPE_DISABLE);
  836. break;
  837. case FSE_BZ_RX_DSC_ERROR_EV:
  838. EFX_ERR(efx, "RX DMA Q %d reports descriptor fetch error."
  839. " RX Q %d is disabled.\n", ev_sub_data, ev_sub_data);
  840. efx_schedule_reset(efx, RESET_TYPE_RX_DESC_FETCH);
  841. break;
  842. case FSE_BZ_TX_DSC_ERROR_EV:
  843. EFX_ERR(efx, "TX DMA Q %d reports descriptor fetch error."
  844. " TX Q %d is disabled.\n", ev_sub_data, ev_sub_data);
  845. efx_schedule_reset(efx, RESET_TYPE_TX_DESC_FETCH);
  846. break;
  847. default:
  848. EFX_TRACE(efx, "channel %d unknown driver event code %d "
  849. "data %04x\n", channel->channel, ev_sub_code,
  850. ev_sub_data);
  851. break;
  852. }
  853. }
  854. int falcon_process_eventq(struct efx_channel *channel, int rx_quota)
  855. {
  856. unsigned int read_ptr;
  857. efx_qword_t event, *p_event;
  858. int ev_code;
  859. int rx_packets = 0;
  860. read_ptr = channel->eventq_read_ptr;
  861. do {
  862. p_event = falcon_event(channel, read_ptr);
  863. event = *p_event;
  864. if (!falcon_event_present(&event))
  865. /* End of events */
  866. break;
  867. EFX_TRACE(channel->efx, "channel %d event is "EFX_QWORD_FMT"\n",
  868. channel->channel, EFX_QWORD_VAL(event));
  869. /* Clear this event by marking it all ones */
  870. EFX_SET_QWORD(*p_event);
  871. ev_code = EFX_QWORD_FIELD(event, FSF_AZ_EV_CODE);
  872. switch (ev_code) {
  873. case FSE_AZ_EV_CODE_RX_EV:
  874. falcon_handle_rx_event(channel, &event);
  875. ++rx_packets;
  876. break;
  877. case FSE_AZ_EV_CODE_TX_EV:
  878. falcon_handle_tx_event(channel, &event);
  879. break;
  880. case FSE_AZ_EV_CODE_DRV_GEN_EV:
  881. channel->eventq_magic = EFX_QWORD_FIELD(
  882. event, FSF_AZ_DRV_GEN_EV_MAGIC);
  883. EFX_LOG(channel->efx, "channel %d received generated "
  884. "event "EFX_QWORD_FMT"\n", channel->channel,
  885. EFX_QWORD_VAL(event));
  886. break;
  887. case FSE_AZ_EV_CODE_GLOBAL_EV:
  888. falcon_handle_global_event(channel, &event);
  889. break;
  890. case FSE_AZ_EV_CODE_DRIVER_EV:
  891. falcon_handle_driver_event(channel, &event);
  892. break;
  893. default:
  894. EFX_ERR(channel->efx, "channel %d unknown event type %d"
  895. " (data " EFX_QWORD_FMT ")\n", channel->channel,
  896. ev_code, EFX_QWORD_VAL(event));
  897. }
  898. /* Increment read pointer */
  899. read_ptr = (read_ptr + 1) & EFX_EVQ_MASK;
  900. } while (rx_packets < rx_quota);
  901. channel->eventq_read_ptr = read_ptr;
  902. return rx_packets;
  903. }
  904. void falcon_set_int_moderation(struct efx_channel *channel)
  905. {
  906. efx_dword_t timer_cmd;
  907. struct efx_nic *efx = channel->efx;
  908. /* Set timer register */
  909. if (channel->irq_moderation) {
  910. EFX_POPULATE_DWORD_2(timer_cmd,
  911. FRF_AB_TC_TIMER_MODE,
  912. FFE_BB_TIMER_MODE_INT_HLDOFF,
  913. FRF_AB_TC_TIMER_VAL,
  914. channel->irq_moderation - 1);
  915. } else {
  916. EFX_POPULATE_DWORD_2(timer_cmd,
  917. FRF_AB_TC_TIMER_MODE,
  918. FFE_BB_TIMER_MODE_DIS,
  919. FRF_AB_TC_TIMER_VAL, 0);
  920. }
  921. BUILD_BUG_ON(FR_AA_TIMER_COMMAND_KER != FR_BZ_TIMER_COMMAND_P0);
  922. efx_writed_page_locked(efx, &timer_cmd, FR_BZ_TIMER_COMMAND_P0,
  923. channel->channel);
  924. }
  925. /* Allocate buffer table entries for event queue */
  926. int falcon_probe_eventq(struct efx_channel *channel)
  927. {
  928. struct efx_nic *efx = channel->efx;
  929. BUILD_BUG_ON(EFX_EVQ_SIZE < 512 || EFX_EVQ_SIZE > 32768 ||
  930. EFX_EVQ_SIZE & EFX_EVQ_MASK);
  931. return falcon_alloc_special_buffer(efx, &channel->eventq,
  932. EFX_EVQ_SIZE * sizeof(efx_qword_t));
  933. }
  934. void falcon_init_eventq(struct efx_channel *channel)
  935. {
  936. efx_oword_t evq_ptr;
  937. struct efx_nic *efx = channel->efx;
  938. EFX_LOG(efx, "channel %d event queue in special buffers %d-%d\n",
  939. channel->channel, channel->eventq.index,
  940. channel->eventq.index + channel->eventq.entries - 1);
  941. /* Pin event queue buffer */
  942. falcon_init_special_buffer(efx, &channel->eventq);
  943. /* Fill event queue with all ones (i.e. empty events) */
  944. memset(channel->eventq.addr, 0xff, channel->eventq.len);
  945. /* Push event queue to card */
  946. EFX_POPULATE_OWORD_3(evq_ptr,
  947. FRF_AZ_EVQ_EN, 1,
  948. FRF_AZ_EVQ_SIZE, __ffs(channel->eventq.entries),
  949. FRF_AZ_EVQ_BUF_BASE_ID, channel->eventq.index);
  950. efx_writeo_table(efx, &evq_ptr, efx->type->evq_ptr_tbl_base,
  951. channel->channel);
  952. falcon_set_int_moderation(channel);
  953. }
  954. void falcon_fini_eventq(struct efx_channel *channel)
  955. {
  956. efx_oword_t eventq_ptr;
  957. struct efx_nic *efx = channel->efx;
  958. /* Remove event queue from card */
  959. EFX_ZERO_OWORD(eventq_ptr);
  960. efx_writeo_table(efx, &eventq_ptr, efx->type->evq_ptr_tbl_base,
  961. channel->channel);
  962. /* Unpin event queue */
  963. falcon_fini_special_buffer(efx, &channel->eventq);
  964. }
  965. /* Free buffers backing event queue */
  966. void falcon_remove_eventq(struct efx_channel *channel)
  967. {
  968. falcon_free_special_buffer(channel->efx, &channel->eventq);
  969. }
  970. /* Generates a test event on the event queue. A subsequent call to
  971. * process_eventq() should pick up the event and place the value of
  972. * "magic" into channel->eventq_magic;
  973. */
  974. void falcon_generate_test_event(struct efx_channel *channel, unsigned int magic)
  975. {
  976. efx_qword_t test_event;
  977. EFX_POPULATE_QWORD_2(test_event, FSF_AZ_EV_CODE,
  978. FSE_AZ_EV_CODE_DRV_GEN_EV,
  979. FSF_AZ_DRV_GEN_EV_MAGIC, magic);
  980. falcon_generate_event(channel, &test_event);
  981. }
  982. void falcon_sim_phy_event(struct efx_nic *efx)
  983. {
  984. efx_qword_t phy_event;
  985. EFX_POPULATE_QWORD_1(phy_event, FSF_AZ_EV_CODE,
  986. FSE_AZ_EV_CODE_GLOBAL_EV);
  987. if (EFX_IS10G(efx))
  988. EFX_SET_QWORD_FIELD(phy_event, FSF_AB_GLB_EV_XG_PHY0_INTR, 1);
  989. else
  990. EFX_SET_QWORD_FIELD(phy_event, FSF_AB_GLB_EV_G_PHY0_INTR, 1);
  991. falcon_generate_event(&efx->channel[0], &phy_event);
  992. }
  993. /**************************************************************************
  994. *
  995. * Flush handling
  996. *
  997. **************************************************************************/
  998. static void falcon_poll_flush_events(struct efx_nic *efx)
  999. {
  1000. struct efx_channel *channel = &efx->channel[0];
  1001. struct efx_tx_queue *tx_queue;
  1002. struct efx_rx_queue *rx_queue;
  1003. unsigned int read_ptr = channel->eventq_read_ptr;
  1004. unsigned int end_ptr = (read_ptr - 1) & EFX_EVQ_MASK;
  1005. do {
  1006. efx_qword_t *event = falcon_event(channel, read_ptr);
  1007. int ev_code, ev_sub_code, ev_queue;
  1008. bool ev_failed;
  1009. if (!falcon_event_present(event))
  1010. break;
  1011. ev_code = EFX_QWORD_FIELD(*event, FSF_AZ_EV_CODE);
  1012. ev_sub_code = EFX_QWORD_FIELD(*event,
  1013. FSF_AZ_DRIVER_EV_SUBCODE);
  1014. if (ev_code == FSE_AZ_EV_CODE_DRIVER_EV &&
  1015. ev_sub_code == FSE_AZ_TX_DESCQ_FLS_DONE_EV) {
  1016. ev_queue = EFX_QWORD_FIELD(*event,
  1017. FSF_AZ_DRIVER_EV_SUBDATA);
  1018. if (ev_queue < EFX_TX_QUEUE_COUNT) {
  1019. tx_queue = efx->tx_queue + ev_queue;
  1020. tx_queue->flushed = FLUSH_DONE;
  1021. }
  1022. } else if (ev_code == FSE_AZ_EV_CODE_DRIVER_EV &&
  1023. ev_sub_code == FSE_AZ_RX_DESCQ_FLS_DONE_EV) {
  1024. ev_queue = EFX_QWORD_FIELD(
  1025. *event, FSF_AZ_DRIVER_EV_RX_DESCQ_ID);
  1026. ev_failed = EFX_QWORD_FIELD(
  1027. *event, FSF_AZ_DRIVER_EV_RX_FLUSH_FAIL);
  1028. if (ev_queue < efx->n_rx_queues) {
  1029. rx_queue = efx->rx_queue + ev_queue;
  1030. rx_queue->flushed =
  1031. ev_failed ? FLUSH_FAILED : FLUSH_DONE;
  1032. }
  1033. }
  1034. /* We're about to destroy the queue anyway, so
  1035. * it's ok to throw away every non-flush event */
  1036. EFX_SET_QWORD(*event);
  1037. read_ptr = (read_ptr + 1) & EFX_EVQ_MASK;
  1038. } while (read_ptr != end_ptr);
  1039. channel->eventq_read_ptr = read_ptr;
  1040. }
  1041. static void falcon_prepare_flush(struct efx_nic *efx)
  1042. {
  1043. falcon_deconfigure_mac_wrapper(efx);
  1044. /* Wait for the tx and rx fifo's to get to the next packet boundary
  1045. * (~1ms without back-pressure), then to drain the remainder of the
  1046. * fifo's at data path speeds (negligible), with a healthy margin. */
  1047. msleep(10);
  1048. }
  1049. /* Handle tx and rx flushes at the same time, since they run in
  1050. * parallel in the hardware and there's no reason for us to
  1051. * serialise them */
  1052. int falcon_flush_queues(struct efx_nic *efx)
  1053. {
  1054. struct efx_rx_queue *rx_queue;
  1055. struct efx_tx_queue *tx_queue;
  1056. int i, tx_pending, rx_pending;
  1057. falcon_prepare_flush(efx);
  1058. /* Flush all tx queues in parallel */
  1059. efx_for_each_tx_queue(tx_queue, efx)
  1060. falcon_flush_tx_queue(tx_queue);
  1061. /* The hardware supports four concurrent rx flushes, each of which may
  1062. * need to be retried if there is an outstanding descriptor fetch */
  1063. for (i = 0; i < FALCON_FLUSH_POLL_COUNT; ++i) {
  1064. rx_pending = tx_pending = 0;
  1065. efx_for_each_rx_queue(rx_queue, efx) {
  1066. if (rx_queue->flushed == FLUSH_PENDING)
  1067. ++rx_pending;
  1068. }
  1069. efx_for_each_rx_queue(rx_queue, efx) {
  1070. if (rx_pending == FALCON_RX_FLUSH_COUNT)
  1071. break;
  1072. if (rx_queue->flushed == FLUSH_FAILED ||
  1073. rx_queue->flushed == FLUSH_NONE) {
  1074. falcon_flush_rx_queue(rx_queue);
  1075. ++rx_pending;
  1076. }
  1077. }
  1078. efx_for_each_tx_queue(tx_queue, efx) {
  1079. if (tx_queue->flushed != FLUSH_DONE)
  1080. ++tx_pending;
  1081. }
  1082. if (rx_pending == 0 && tx_pending == 0)
  1083. return 0;
  1084. msleep(FALCON_FLUSH_INTERVAL);
  1085. falcon_poll_flush_events(efx);
  1086. }
  1087. /* Mark the queues as all flushed. We're going to return failure
  1088. * leading to a reset, or fake up success anyway */
  1089. efx_for_each_tx_queue(tx_queue, efx) {
  1090. if (tx_queue->flushed != FLUSH_DONE)
  1091. EFX_ERR(efx, "tx queue %d flush command timed out\n",
  1092. tx_queue->queue);
  1093. tx_queue->flushed = FLUSH_DONE;
  1094. }
  1095. efx_for_each_rx_queue(rx_queue, efx) {
  1096. if (rx_queue->flushed != FLUSH_DONE)
  1097. EFX_ERR(efx, "rx queue %d flush command timed out\n",
  1098. rx_queue->queue);
  1099. rx_queue->flushed = FLUSH_DONE;
  1100. }
  1101. if (EFX_WORKAROUND_7803(efx))
  1102. return 0;
  1103. return -ETIMEDOUT;
  1104. }
  1105. /**************************************************************************
  1106. *
  1107. * Falcon hardware interrupts
  1108. * The hardware interrupt handler does very little work; all the event
  1109. * queue processing is carried out by per-channel tasklets.
  1110. *
  1111. **************************************************************************/
  1112. /* Enable/disable/generate Falcon interrupts */
  1113. static inline void falcon_interrupts(struct efx_nic *efx, int enabled,
  1114. int force)
  1115. {
  1116. efx_oword_t int_en_reg_ker;
  1117. EFX_POPULATE_OWORD_2(int_en_reg_ker,
  1118. FRF_AZ_KER_INT_KER, force,
  1119. FRF_AZ_DRV_INT_EN_KER, enabled);
  1120. efx_writeo(efx, &int_en_reg_ker, FR_AZ_INT_EN_KER);
  1121. }
  1122. void falcon_enable_interrupts(struct efx_nic *efx)
  1123. {
  1124. efx_oword_t int_adr_reg_ker;
  1125. struct efx_channel *channel;
  1126. EFX_ZERO_OWORD(*((efx_oword_t *) efx->irq_status.addr));
  1127. wmb(); /* Ensure interrupt vector is clear before interrupts enabled */
  1128. /* Program address */
  1129. EFX_POPULATE_OWORD_2(int_adr_reg_ker,
  1130. FRF_AZ_NORM_INT_VEC_DIS_KER,
  1131. EFX_INT_MODE_USE_MSI(efx),
  1132. FRF_AZ_INT_ADR_KER, efx->irq_status.dma_addr);
  1133. efx_writeo(efx, &int_adr_reg_ker, FR_AZ_INT_ADR_KER);
  1134. /* Enable interrupts */
  1135. falcon_interrupts(efx, 1, 0);
  1136. /* Force processing of all the channels to get the EVQ RPTRs up to
  1137. date */
  1138. efx_for_each_channel(channel, efx)
  1139. efx_schedule_channel(channel);
  1140. }
  1141. void falcon_disable_interrupts(struct efx_nic *efx)
  1142. {
  1143. /* Disable interrupts */
  1144. falcon_interrupts(efx, 0, 0);
  1145. }
  1146. /* Generate a Falcon test interrupt
  1147. * Interrupt must already have been enabled, otherwise nasty things
  1148. * may happen.
  1149. */
  1150. void falcon_generate_interrupt(struct efx_nic *efx)
  1151. {
  1152. falcon_interrupts(efx, 1, 1);
  1153. }
  1154. /* Acknowledge a legacy interrupt from Falcon
  1155. *
  1156. * This acknowledges a legacy (not MSI) interrupt via INT_ACK_KER_REG.
  1157. *
  1158. * Due to SFC bug 3706 (silicon revision <=A1) reads can be duplicated in the
  1159. * BIU. Interrupt acknowledge is read sensitive so must write instead
  1160. * (then read to ensure the BIU collector is flushed)
  1161. *
  1162. * NB most hardware supports MSI interrupts
  1163. */
  1164. static inline void falcon_irq_ack_a1(struct efx_nic *efx)
  1165. {
  1166. efx_dword_t reg;
  1167. EFX_POPULATE_DWORD_1(reg, FRF_AA_INT_ACK_KER_FIELD, 0xb7eb7e);
  1168. efx_writed(efx, &reg, FR_AA_INT_ACK_KER);
  1169. efx_readd(efx, &reg, FR_AA_WORK_AROUND_BROKEN_PCI_READS);
  1170. }
  1171. /* Process a fatal interrupt
  1172. * Disable bus mastering ASAP and schedule a reset
  1173. */
  1174. static irqreturn_t falcon_fatal_interrupt(struct efx_nic *efx)
  1175. {
  1176. struct falcon_nic_data *nic_data = efx->nic_data;
  1177. efx_oword_t *int_ker = efx->irq_status.addr;
  1178. efx_oword_t fatal_intr;
  1179. int error, mem_perr;
  1180. efx_reado(efx, &fatal_intr, FR_AZ_FATAL_INTR_KER);
  1181. error = EFX_OWORD_FIELD(fatal_intr, FRF_AZ_FATAL_INTR);
  1182. EFX_ERR(efx, "SYSTEM ERROR " EFX_OWORD_FMT " status "
  1183. EFX_OWORD_FMT ": %s\n", EFX_OWORD_VAL(*int_ker),
  1184. EFX_OWORD_VAL(fatal_intr),
  1185. error ? "disabling bus mastering" : "no recognised error");
  1186. if (error == 0)
  1187. goto out;
  1188. /* If this is a memory parity error dump which blocks are offending */
  1189. mem_perr = EFX_OWORD_FIELD(fatal_intr, FRF_AZ_MEM_PERR_INT_KER);
  1190. if (mem_perr) {
  1191. efx_oword_t reg;
  1192. efx_reado(efx, &reg, FR_AZ_MEM_STAT);
  1193. EFX_ERR(efx, "SYSTEM ERROR: memory parity error "
  1194. EFX_OWORD_FMT "\n", EFX_OWORD_VAL(reg));
  1195. }
  1196. /* Disable both devices */
  1197. pci_clear_master(efx->pci_dev);
  1198. if (FALCON_IS_DUAL_FUNC(efx))
  1199. pci_clear_master(nic_data->pci_dev2);
  1200. falcon_disable_interrupts(efx);
  1201. /* Count errors and reset or disable the NIC accordingly */
  1202. if (efx->int_error_count == 0 ||
  1203. time_after(jiffies, efx->int_error_expire)) {
  1204. efx->int_error_count = 0;
  1205. efx->int_error_expire =
  1206. jiffies + FALCON_INT_ERROR_EXPIRE * HZ;
  1207. }
  1208. if (++efx->int_error_count < FALCON_MAX_INT_ERRORS) {
  1209. EFX_ERR(efx, "SYSTEM ERROR - reset scheduled\n");
  1210. efx_schedule_reset(efx, RESET_TYPE_INT_ERROR);
  1211. } else {
  1212. EFX_ERR(efx, "SYSTEM ERROR - max number of errors seen."
  1213. "NIC will be disabled\n");
  1214. efx_schedule_reset(efx, RESET_TYPE_DISABLE);
  1215. }
  1216. out:
  1217. return IRQ_HANDLED;
  1218. }
  1219. /* Handle a legacy interrupt from Falcon
  1220. * Acknowledges the interrupt and schedule event queue processing.
  1221. */
  1222. static irqreturn_t falcon_legacy_interrupt_b0(int irq, void *dev_id)
  1223. {
  1224. struct efx_nic *efx = dev_id;
  1225. efx_oword_t *int_ker = efx->irq_status.addr;
  1226. irqreturn_t result = IRQ_NONE;
  1227. struct efx_channel *channel;
  1228. efx_dword_t reg;
  1229. u32 queues;
  1230. int syserr;
  1231. /* Read the ISR which also ACKs the interrupts */
  1232. efx_readd(efx, &reg, FR_BZ_INT_ISR0);
  1233. queues = EFX_EXTRACT_DWORD(reg, 0, 31);
  1234. /* Check to see if we have a serious error condition */
  1235. syserr = EFX_OWORD_FIELD(*int_ker, FSF_AZ_NET_IVEC_FATAL_INT);
  1236. if (unlikely(syserr))
  1237. return falcon_fatal_interrupt(efx);
  1238. /* Schedule processing of any interrupting queues */
  1239. efx_for_each_channel(channel, efx) {
  1240. if ((queues & 1) ||
  1241. falcon_event_present(
  1242. falcon_event(channel, channel->eventq_read_ptr))) {
  1243. efx_schedule_channel(channel);
  1244. result = IRQ_HANDLED;
  1245. }
  1246. queues >>= 1;
  1247. }
  1248. if (result == IRQ_HANDLED) {
  1249. efx->last_irq_cpu = raw_smp_processor_id();
  1250. EFX_TRACE(efx, "IRQ %d on CPU %d status " EFX_DWORD_FMT "\n",
  1251. irq, raw_smp_processor_id(), EFX_DWORD_VAL(reg));
  1252. }
  1253. return result;
  1254. }
  1255. static irqreturn_t falcon_legacy_interrupt_a1(int irq, void *dev_id)
  1256. {
  1257. struct efx_nic *efx = dev_id;
  1258. efx_oword_t *int_ker = efx->irq_status.addr;
  1259. struct efx_channel *channel;
  1260. int syserr;
  1261. int queues;
  1262. /* Check to see if this is our interrupt. If it isn't, we
  1263. * exit without having touched the hardware.
  1264. */
  1265. if (unlikely(EFX_OWORD_IS_ZERO(*int_ker))) {
  1266. EFX_TRACE(efx, "IRQ %d on CPU %d not for me\n", irq,
  1267. raw_smp_processor_id());
  1268. return IRQ_NONE;
  1269. }
  1270. efx->last_irq_cpu = raw_smp_processor_id();
  1271. EFX_TRACE(efx, "IRQ %d on CPU %d status " EFX_OWORD_FMT "\n",
  1272. irq, raw_smp_processor_id(), EFX_OWORD_VAL(*int_ker));
  1273. /* Check to see if we have a serious error condition */
  1274. syserr = EFX_OWORD_FIELD(*int_ker, FSF_AZ_NET_IVEC_FATAL_INT);
  1275. if (unlikely(syserr))
  1276. return falcon_fatal_interrupt(efx);
  1277. /* Determine interrupting queues, clear interrupt status
  1278. * register and acknowledge the device interrupt.
  1279. */
  1280. BUILD_BUG_ON(INT_EVQS_WIDTH > EFX_MAX_CHANNELS);
  1281. queues = EFX_OWORD_FIELD(*int_ker, INT_EVQS);
  1282. EFX_ZERO_OWORD(*int_ker);
  1283. wmb(); /* Ensure the vector is cleared before interrupt ack */
  1284. falcon_irq_ack_a1(efx);
  1285. /* Schedule processing of any interrupting queues */
  1286. channel = &efx->channel[0];
  1287. while (queues) {
  1288. if (queues & 0x01)
  1289. efx_schedule_channel(channel);
  1290. channel++;
  1291. queues >>= 1;
  1292. }
  1293. return IRQ_HANDLED;
  1294. }
  1295. /* Handle an MSI interrupt from Falcon
  1296. *
  1297. * Handle an MSI hardware interrupt. This routine schedules event
  1298. * queue processing. No interrupt acknowledgement cycle is necessary.
  1299. * Also, we never need to check that the interrupt is for us, since
  1300. * MSI interrupts cannot be shared.
  1301. */
  1302. static irqreturn_t falcon_msi_interrupt(int irq, void *dev_id)
  1303. {
  1304. struct efx_channel *channel = dev_id;
  1305. struct efx_nic *efx = channel->efx;
  1306. efx_oword_t *int_ker = efx->irq_status.addr;
  1307. int syserr;
  1308. efx->last_irq_cpu = raw_smp_processor_id();
  1309. EFX_TRACE(efx, "IRQ %d on CPU %d status " EFX_OWORD_FMT "\n",
  1310. irq, raw_smp_processor_id(), EFX_OWORD_VAL(*int_ker));
  1311. /* Check to see if we have a serious error condition */
  1312. syserr = EFX_OWORD_FIELD(*int_ker, FATAL_INT);
  1313. if (unlikely(syserr))
  1314. return falcon_fatal_interrupt(efx);
  1315. /* Schedule processing of the channel */
  1316. efx_schedule_channel(channel);
  1317. return IRQ_HANDLED;
  1318. }
  1319. /* Setup RSS indirection table.
  1320. * This maps from the hash value of the packet to RXQ
  1321. */
  1322. static void falcon_setup_rss_indir_table(struct efx_nic *efx)
  1323. {
  1324. int i = 0;
  1325. unsigned long offset;
  1326. efx_dword_t dword;
  1327. if (falcon_rev(efx) < FALCON_REV_B0)
  1328. return;
  1329. for (offset = FR_BZ_RX_INDIRECTION_TBL;
  1330. offset < FR_BZ_RX_INDIRECTION_TBL + 0x800;
  1331. offset += 0x10) {
  1332. EFX_POPULATE_DWORD_1(dword, FRF_BZ_IT_QUEUE,
  1333. i % efx->n_rx_queues);
  1334. efx_writed(efx, &dword, offset);
  1335. i++;
  1336. }
  1337. }
  1338. /* Hook interrupt handler(s)
  1339. * Try MSI and then legacy interrupts.
  1340. */
  1341. int falcon_init_interrupt(struct efx_nic *efx)
  1342. {
  1343. struct efx_channel *channel;
  1344. int rc;
  1345. if (!EFX_INT_MODE_USE_MSI(efx)) {
  1346. irq_handler_t handler;
  1347. if (falcon_rev(efx) >= FALCON_REV_B0)
  1348. handler = falcon_legacy_interrupt_b0;
  1349. else
  1350. handler = falcon_legacy_interrupt_a1;
  1351. rc = request_irq(efx->legacy_irq, handler, IRQF_SHARED,
  1352. efx->name, efx);
  1353. if (rc) {
  1354. EFX_ERR(efx, "failed to hook legacy IRQ %d\n",
  1355. efx->pci_dev->irq);
  1356. goto fail1;
  1357. }
  1358. return 0;
  1359. }
  1360. /* Hook MSI or MSI-X interrupt */
  1361. efx_for_each_channel(channel, efx) {
  1362. rc = request_irq(channel->irq, falcon_msi_interrupt,
  1363. IRQF_PROBE_SHARED, /* Not shared */
  1364. channel->name, channel);
  1365. if (rc) {
  1366. EFX_ERR(efx, "failed to hook IRQ %d\n", channel->irq);
  1367. goto fail2;
  1368. }
  1369. }
  1370. return 0;
  1371. fail2:
  1372. efx_for_each_channel(channel, efx)
  1373. free_irq(channel->irq, channel);
  1374. fail1:
  1375. return rc;
  1376. }
  1377. void falcon_fini_interrupt(struct efx_nic *efx)
  1378. {
  1379. struct efx_channel *channel;
  1380. efx_oword_t reg;
  1381. /* Disable MSI/MSI-X interrupts */
  1382. efx_for_each_channel(channel, efx) {
  1383. if (channel->irq)
  1384. free_irq(channel->irq, channel);
  1385. }
  1386. /* ACK legacy interrupt */
  1387. if (falcon_rev(efx) >= FALCON_REV_B0)
  1388. efx_reado(efx, &reg, FR_BZ_INT_ISR0);
  1389. else
  1390. falcon_irq_ack_a1(efx);
  1391. /* Disable legacy interrupt */
  1392. if (efx->legacy_irq)
  1393. free_irq(efx->legacy_irq, efx);
  1394. }
  1395. /**************************************************************************
  1396. *
  1397. * EEPROM/flash
  1398. *
  1399. **************************************************************************
  1400. */
  1401. #define FALCON_SPI_MAX_LEN sizeof(efx_oword_t)
  1402. static int falcon_spi_poll(struct efx_nic *efx)
  1403. {
  1404. efx_oword_t reg;
  1405. efx_reado(efx, &reg, FR_AB_EE_SPI_HCMD);
  1406. return EFX_OWORD_FIELD(reg, FRF_AB_EE_SPI_HCMD_CMD_EN) ? -EBUSY : 0;
  1407. }
  1408. /* Wait for SPI command completion */
  1409. static int falcon_spi_wait(struct efx_nic *efx)
  1410. {
  1411. /* Most commands will finish quickly, so we start polling at
  1412. * very short intervals. Sometimes the command may have to
  1413. * wait for VPD or expansion ROM access outside of our
  1414. * control, so we allow up to 100 ms. */
  1415. unsigned long timeout = jiffies + 1 + DIV_ROUND_UP(HZ, 10);
  1416. int i;
  1417. for (i = 0; i < 10; i++) {
  1418. if (!falcon_spi_poll(efx))
  1419. return 0;
  1420. udelay(10);
  1421. }
  1422. for (;;) {
  1423. if (!falcon_spi_poll(efx))
  1424. return 0;
  1425. if (time_after_eq(jiffies, timeout)) {
  1426. EFX_ERR(efx, "timed out waiting for SPI\n");
  1427. return -ETIMEDOUT;
  1428. }
  1429. schedule_timeout_uninterruptible(1);
  1430. }
  1431. }
  1432. int falcon_spi_cmd(const struct efx_spi_device *spi,
  1433. unsigned int command, int address,
  1434. const void *in, void *out, size_t len)
  1435. {
  1436. struct efx_nic *efx = spi->efx;
  1437. bool addressed = (address >= 0);
  1438. bool reading = (out != NULL);
  1439. efx_oword_t reg;
  1440. int rc;
  1441. /* Input validation */
  1442. if (len > FALCON_SPI_MAX_LEN)
  1443. return -EINVAL;
  1444. BUG_ON(!mutex_is_locked(&efx->spi_lock));
  1445. /* Check that previous command is not still running */
  1446. rc = falcon_spi_poll(efx);
  1447. if (rc)
  1448. return rc;
  1449. /* Program address register, if we have an address */
  1450. if (addressed) {
  1451. EFX_POPULATE_OWORD_1(reg, FRF_AB_EE_SPI_HADR_ADR, address);
  1452. efx_writeo(efx, &reg, FR_AB_EE_SPI_HADR);
  1453. }
  1454. /* Program data register, if we have data */
  1455. if (in != NULL) {
  1456. memcpy(&reg, in, len);
  1457. efx_writeo(efx, &reg, FR_AB_EE_SPI_HDATA);
  1458. }
  1459. /* Issue read/write command */
  1460. EFX_POPULATE_OWORD_7(reg,
  1461. FRF_AB_EE_SPI_HCMD_CMD_EN, 1,
  1462. FRF_AB_EE_SPI_HCMD_SF_SEL, spi->device_id,
  1463. FRF_AB_EE_SPI_HCMD_DABCNT, len,
  1464. FRF_AB_EE_SPI_HCMD_READ, reading,
  1465. FRF_AB_EE_SPI_HCMD_DUBCNT, 0,
  1466. FRF_AB_EE_SPI_HCMD_ADBCNT,
  1467. (addressed ? spi->addr_len : 0),
  1468. FRF_AB_EE_SPI_HCMD_ENC, command);
  1469. efx_writeo(efx, &reg, FR_AB_EE_SPI_HCMD);
  1470. /* Wait for read/write to complete */
  1471. rc = falcon_spi_wait(efx);
  1472. if (rc)
  1473. return rc;
  1474. /* Read data */
  1475. if (out != NULL) {
  1476. efx_reado(efx, &reg, FR_AB_EE_SPI_HDATA);
  1477. memcpy(out, &reg, len);
  1478. }
  1479. return 0;
  1480. }
  1481. static size_t
  1482. falcon_spi_write_limit(const struct efx_spi_device *spi, size_t start)
  1483. {
  1484. return min(FALCON_SPI_MAX_LEN,
  1485. (spi->block_size - (start & (spi->block_size - 1))));
  1486. }
  1487. static inline u8
  1488. efx_spi_munge_command(const struct efx_spi_device *spi,
  1489. const u8 command, const unsigned int address)
  1490. {
  1491. return command | (((address >> 8) & spi->munge_address) << 3);
  1492. }
  1493. /* Wait up to 10 ms for buffered write completion */
  1494. int falcon_spi_wait_write(const struct efx_spi_device *spi)
  1495. {
  1496. struct efx_nic *efx = spi->efx;
  1497. unsigned long timeout = jiffies + 1 + DIV_ROUND_UP(HZ, 100);
  1498. u8 status;
  1499. int rc;
  1500. for (;;) {
  1501. rc = falcon_spi_cmd(spi, SPI_RDSR, -1, NULL,
  1502. &status, sizeof(status));
  1503. if (rc)
  1504. return rc;
  1505. if (!(status & SPI_STATUS_NRDY))
  1506. return 0;
  1507. if (time_after_eq(jiffies, timeout)) {
  1508. EFX_ERR(efx, "SPI write timeout on device %d"
  1509. " last status=0x%02x\n",
  1510. spi->device_id, status);
  1511. return -ETIMEDOUT;
  1512. }
  1513. schedule_timeout_uninterruptible(1);
  1514. }
  1515. }
  1516. int falcon_spi_read(const struct efx_spi_device *spi, loff_t start,
  1517. size_t len, size_t *retlen, u8 *buffer)
  1518. {
  1519. size_t block_len, pos = 0;
  1520. unsigned int command;
  1521. int rc = 0;
  1522. while (pos < len) {
  1523. block_len = min(len - pos, FALCON_SPI_MAX_LEN);
  1524. command = efx_spi_munge_command(spi, SPI_READ, start + pos);
  1525. rc = falcon_spi_cmd(spi, command, start + pos, NULL,
  1526. buffer + pos, block_len);
  1527. if (rc)
  1528. break;
  1529. pos += block_len;
  1530. /* Avoid locking up the system */
  1531. cond_resched();
  1532. if (signal_pending(current)) {
  1533. rc = -EINTR;
  1534. break;
  1535. }
  1536. }
  1537. if (retlen)
  1538. *retlen = pos;
  1539. return rc;
  1540. }
  1541. int falcon_spi_write(const struct efx_spi_device *spi, loff_t start,
  1542. size_t len, size_t *retlen, const u8 *buffer)
  1543. {
  1544. u8 verify_buffer[FALCON_SPI_MAX_LEN];
  1545. size_t block_len, pos = 0;
  1546. unsigned int command;
  1547. int rc = 0;
  1548. while (pos < len) {
  1549. rc = falcon_spi_cmd(spi, SPI_WREN, -1, NULL, NULL, 0);
  1550. if (rc)
  1551. break;
  1552. block_len = min(len - pos,
  1553. falcon_spi_write_limit(spi, start + pos));
  1554. command = efx_spi_munge_command(spi, SPI_WRITE, start + pos);
  1555. rc = falcon_spi_cmd(spi, command, start + pos,
  1556. buffer + pos, NULL, block_len);
  1557. if (rc)
  1558. break;
  1559. rc = falcon_spi_wait_write(spi);
  1560. if (rc)
  1561. break;
  1562. command = efx_spi_munge_command(spi, SPI_READ, start + pos);
  1563. rc = falcon_spi_cmd(spi, command, start + pos,
  1564. NULL, verify_buffer, block_len);
  1565. if (memcmp(verify_buffer, buffer + pos, block_len)) {
  1566. rc = -EIO;
  1567. break;
  1568. }
  1569. pos += block_len;
  1570. /* Avoid locking up the system */
  1571. cond_resched();
  1572. if (signal_pending(current)) {
  1573. rc = -EINTR;
  1574. break;
  1575. }
  1576. }
  1577. if (retlen)
  1578. *retlen = pos;
  1579. return rc;
  1580. }
  1581. /**************************************************************************
  1582. *
  1583. * MAC wrapper
  1584. *
  1585. **************************************************************************
  1586. */
  1587. static int falcon_reset_macs(struct efx_nic *efx)
  1588. {
  1589. efx_oword_t reg;
  1590. int count;
  1591. if (falcon_rev(efx) < FALCON_REV_B0) {
  1592. /* It's not safe to use GLB_CTL_REG to reset the
  1593. * macs, so instead use the internal MAC resets
  1594. */
  1595. if (!EFX_IS10G(efx)) {
  1596. EFX_POPULATE_OWORD_1(reg, FRF_AB_GM_SW_RST, 1);
  1597. efx_writeo(efx, &reg, FR_AB_GM_CFG1);
  1598. udelay(1000);
  1599. EFX_POPULATE_OWORD_1(reg, FRF_AB_GM_SW_RST, 0);
  1600. efx_writeo(efx, &reg, FR_AB_GM_CFG1);
  1601. udelay(1000);
  1602. return 0;
  1603. } else {
  1604. EFX_POPULATE_OWORD_1(reg, FRF_AB_XM_CORE_RST, 1);
  1605. efx_writeo(efx, &reg, FR_AB_XM_GLB_CFG);
  1606. for (count = 0; count < 10000; count++) {
  1607. efx_reado(efx, &reg, FR_AB_XM_GLB_CFG);
  1608. if (EFX_OWORD_FIELD(reg, FRF_AB_XM_CORE_RST) ==
  1609. 0)
  1610. return 0;
  1611. udelay(10);
  1612. }
  1613. EFX_ERR(efx, "timed out waiting for XMAC core reset\n");
  1614. return -ETIMEDOUT;
  1615. }
  1616. }
  1617. /* MAC stats will fail whilst the TX fifo is draining. Serialise
  1618. * the drain sequence with the statistics fetch */
  1619. falcon_stop_nic_stats(efx);
  1620. efx_reado(efx, &reg, FR_AB_MAC_CTRL);
  1621. EFX_SET_OWORD_FIELD(reg, FRF_BB_TXFIFO_DRAIN_EN, 1);
  1622. efx_writeo(efx, &reg, FR_AB_MAC_CTRL);
  1623. efx_reado(efx, &reg, FR_AB_GLB_CTL);
  1624. EFX_SET_OWORD_FIELD(reg, FRF_AB_RST_XGTX, 1);
  1625. EFX_SET_OWORD_FIELD(reg, FRF_AB_RST_XGRX, 1);
  1626. EFX_SET_OWORD_FIELD(reg, FRF_AB_RST_EM, 1);
  1627. efx_writeo(efx, &reg, FR_AB_GLB_CTL);
  1628. count = 0;
  1629. while (1) {
  1630. efx_reado(efx, &reg, FR_AB_GLB_CTL);
  1631. if (!EFX_OWORD_FIELD(reg, FRF_AB_RST_XGTX) &&
  1632. !EFX_OWORD_FIELD(reg, FRF_AB_RST_XGRX) &&
  1633. !EFX_OWORD_FIELD(reg, FRF_AB_RST_EM)) {
  1634. EFX_LOG(efx, "Completed MAC reset after %d loops\n",
  1635. count);
  1636. break;
  1637. }
  1638. if (count > 20) {
  1639. EFX_ERR(efx, "MAC reset failed\n");
  1640. break;
  1641. }
  1642. count++;
  1643. udelay(10);
  1644. }
  1645. /* If we've reset the EM block and the link is up, then
  1646. * we'll have to kick the XAUI link so the PHY can recover */
  1647. if (efx->link_state.up && EFX_IS10G(efx) && EFX_WORKAROUND_5147(efx))
  1648. falcon_reset_xaui(efx);
  1649. falcon_start_nic_stats(efx);
  1650. return 0;
  1651. }
  1652. void falcon_drain_tx_fifo(struct efx_nic *efx)
  1653. {
  1654. efx_oword_t reg;
  1655. if ((falcon_rev(efx) < FALCON_REV_B0) ||
  1656. (efx->loopback_mode != LOOPBACK_NONE))
  1657. return;
  1658. efx_reado(efx, &reg, FR_AB_MAC_CTRL);
  1659. /* There is no point in draining more than once */
  1660. if (EFX_OWORD_FIELD(reg, FRF_BB_TXFIFO_DRAIN_EN))
  1661. return;
  1662. falcon_reset_macs(efx);
  1663. }
  1664. void falcon_deconfigure_mac_wrapper(struct efx_nic *efx)
  1665. {
  1666. efx_oword_t reg;
  1667. if (falcon_rev(efx) < FALCON_REV_B0)
  1668. return;
  1669. /* Isolate the MAC -> RX */
  1670. efx_reado(efx, &reg, FR_AZ_RX_CFG);
  1671. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_INGR_EN, 0);
  1672. efx_writeo(efx, &reg, FR_AZ_RX_CFG);
  1673. if (!efx->link_state.up)
  1674. falcon_drain_tx_fifo(efx);
  1675. }
  1676. void falcon_reconfigure_mac_wrapper(struct efx_nic *efx)
  1677. {
  1678. struct efx_link_state *link_state = &efx->link_state;
  1679. efx_oword_t reg;
  1680. int link_speed;
  1681. bool tx_fc;
  1682. switch (link_state->speed) {
  1683. case 10000: link_speed = 3; break;
  1684. case 1000: link_speed = 2; break;
  1685. case 100: link_speed = 1; break;
  1686. default: link_speed = 0; break;
  1687. }
  1688. /* MAC_LINK_STATUS controls MAC backpressure but doesn't work
  1689. * as advertised. Disable to ensure packets are not
  1690. * indefinitely held and TX queue can be flushed at any point
  1691. * while the link is down. */
  1692. EFX_POPULATE_OWORD_5(reg,
  1693. FRF_AB_MAC_XOFF_VAL, 0xffff /* max pause time */,
  1694. FRF_AB_MAC_BCAD_ACPT, 1,
  1695. FRF_AB_MAC_UC_PROM, efx->promiscuous,
  1696. FRF_AB_MAC_LINK_STATUS, 1, /* always set */
  1697. FRF_AB_MAC_SPEED, link_speed);
  1698. /* On B0, MAC backpressure can be disabled and packets get
  1699. * discarded. */
  1700. if (falcon_rev(efx) >= FALCON_REV_B0) {
  1701. EFX_SET_OWORD_FIELD(reg, FRF_BB_TXFIFO_DRAIN_EN,
  1702. !link_state->up);
  1703. }
  1704. efx_writeo(efx, &reg, FR_AB_MAC_CTRL);
  1705. /* Restore the multicast hash registers. */
  1706. falcon_push_multicast_hash(efx);
  1707. /* Transmission of pause frames when RX crosses the threshold is
  1708. * covered by RX_XOFF_MAC_EN and XM_TX_CFG_REG:XM_FCNTL.
  1709. * Action on receipt of pause frames is controller by XM_DIS_FCNTL */
  1710. tx_fc = !!(efx->link_state.fc & EFX_FC_TX);
  1711. efx_reado(efx, &reg, FR_AZ_RX_CFG);
  1712. EFX_SET_OWORD_FIELD(reg, FRF_AZ_RX_XOFF_MAC_EN, tx_fc);
  1713. /* Unisolate the MAC -> RX */
  1714. if (falcon_rev(efx) >= FALCON_REV_B0)
  1715. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_INGR_EN, 1);
  1716. efx_writeo(efx, &reg, FR_AZ_RX_CFG);
  1717. }
  1718. static void falcon_stats_request(struct efx_nic *efx)
  1719. {
  1720. struct falcon_nic_data *nic_data = efx->nic_data;
  1721. efx_oword_t reg;
  1722. WARN_ON(nic_data->stats_pending);
  1723. WARN_ON(nic_data->stats_disable_count);
  1724. if (nic_data->stats_dma_done == NULL)
  1725. return; /* no mac selected */
  1726. *nic_data->stats_dma_done = FALCON_STATS_NOT_DONE;
  1727. nic_data->stats_pending = true;
  1728. wmb(); /* ensure done flag is clear */
  1729. /* Initiate DMA transfer of stats */
  1730. EFX_POPULATE_OWORD_2(reg,
  1731. FRF_AB_MAC_STAT_DMA_CMD, 1,
  1732. FRF_AB_MAC_STAT_DMA_ADR,
  1733. efx->stats_buffer.dma_addr);
  1734. efx_writeo(efx, &reg, FR_AB_MAC_STAT_DMA);
  1735. mod_timer(&nic_data->stats_timer, round_jiffies_up(jiffies + HZ / 2));
  1736. }
  1737. static void falcon_stats_complete(struct efx_nic *efx)
  1738. {
  1739. struct falcon_nic_data *nic_data = efx->nic_data;
  1740. if (!nic_data->stats_pending)
  1741. return;
  1742. nic_data->stats_pending = 0;
  1743. if (*nic_data->stats_dma_done == FALCON_STATS_DONE) {
  1744. rmb(); /* read the done flag before the stats */
  1745. efx->mac_op->update_stats(efx);
  1746. } else {
  1747. EFX_ERR(efx, "timed out waiting for statistics\n");
  1748. }
  1749. }
  1750. static void falcon_stats_timer_func(unsigned long context)
  1751. {
  1752. struct efx_nic *efx = (struct efx_nic *)context;
  1753. struct falcon_nic_data *nic_data = efx->nic_data;
  1754. spin_lock(&efx->stats_lock);
  1755. falcon_stats_complete(efx);
  1756. if (nic_data->stats_disable_count == 0)
  1757. falcon_stats_request(efx);
  1758. spin_unlock(&efx->stats_lock);
  1759. }
  1760. /**************************************************************************
  1761. *
  1762. * PHY access via GMII
  1763. *
  1764. **************************************************************************
  1765. */
  1766. /* Wait for GMII access to complete */
  1767. static int falcon_gmii_wait(struct efx_nic *efx)
  1768. {
  1769. efx_oword_t md_stat;
  1770. int count;
  1771. /* wait upto 50ms - taken max from datasheet */
  1772. for (count = 0; count < 5000; count++) {
  1773. efx_reado(efx, &md_stat, FR_AB_MD_STAT);
  1774. if (EFX_OWORD_FIELD(md_stat, FRF_AB_MD_BSY) == 0) {
  1775. if (EFX_OWORD_FIELD(md_stat, FRF_AB_MD_LNFL) != 0 ||
  1776. EFX_OWORD_FIELD(md_stat, FRF_AB_MD_BSERR) != 0) {
  1777. EFX_ERR(efx, "error from GMII access "
  1778. EFX_OWORD_FMT"\n",
  1779. EFX_OWORD_VAL(md_stat));
  1780. return -EIO;
  1781. }
  1782. return 0;
  1783. }
  1784. udelay(10);
  1785. }
  1786. EFX_ERR(efx, "timed out waiting for GMII\n");
  1787. return -ETIMEDOUT;
  1788. }
  1789. /* Write an MDIO register of a PHY connected to Falcon. */
  1790. static int falcon_mdio_write(struct net_device *net_dev,
  1791. int prtad, int devad, u16 addr, u16 value)
  1792. {
  1793. struct efx_nic *efx = netdev_priv(net_dev);
  1794. efx_oword_t reg;
  1795. int rc;
  1796. EFX_REGDUMP(efx, "writing MDIO %d register %d.%d with 0x%04x\n",
  1797. prtad, devad, addr, value);
  1798. spin_lock_bh(&efx->phy_lock);
  1799. /* Check MDIO not currently being accessed */
  1800. rc = falcon_gmii_wait(efx);
  1801. if (rc)
  1802. goto out;
  1803. /* Write the address/ID register */
  1804. EFX_POPULATE_OWORD_1(reg, FRF_AB_MD_PHY_ADR, addr);
  1805. efx_writeo(efx, &reg, FR_AB_MD_PHY_ADR);
  1806. EFX_POPULATE_OWORD_2(reg, FRF_AB_MD_PRT_ADR, prtad,
  1807. FRF_AB_MD_DEV_ADR, devad);
  1808. efx_writeo(efx, &reg, FR_AB_MD_ID);
  1809. /* Write data */
  1810. EFX_POPULATE_OWORD_1(reg, FRF_AB_MD_TXD, value);
  1811. efx_writeo(efx, &reg, FR_AB_MD_TXD);
  1812. EFX_POPULATE_OWORD_2(reg,
  1813. FRF_AB_MD_WRC, 1,
  1814. FRF_AB_MD_GC, 0);
  1815. efx_writeo(efx, &reg, FR_AB_MD_CS);
  1816. /* Wait for data to be written */
  1817. rc = falcon_gmii_wait(efx);
  1818. if (rc) {
  1819. /* Abort the write operation */
  1820. EFX_POPULATE_OWORD_2(reg,
  1821. FRF_AB_MD_WRC, 0,
  1822. FRF_AB_MD_GC, 1);
  1823. efx_writeo(efx, &reg, FR_AB_MD_CS);
  1824. udelay(10);
  1825. }
  1826. out:
  1827. spin_unlock_bh(&efx->phy_lock);
  1828. return rc;
  1829. }
  1830. /* Read an MDIO register of a PHY connected to Falcon. */
  1831. static int falcon_mdio_read(struct net_device *net_dev,
  1832. int prtad, int devad, u16 addr)
  1833. {
  1834. struct efx_nic *efx = netdev_priv(net_dev);
  1835. efx_oword_t reg;
  1836. int rc;
  1837. spin_lock_bh(&efx->phy_lock);
  1838. /* Check MDIO not currently being accessed */
  1839. rc = falcon_gmii_wait(efx);
  1840. if (rc)
  1841. goto out;
  1842. EFX_POPULATE_OWORD_1(reg, FRF_AB_MD_PHY_ADR, addr);
  1843. efx_writeo(efx, &reg, FR_AB_MD_PHY_ADR);
  1844. EFX_POPULATE_OWORD_2(reg, FRF_AB_MD_PRT_ADR, prtad,
  1845. FRF_AB_MD_DEV_ADR, devad);
  1846. efx_writeo(efx, &reg, FR_AB_MD_ID);
  1847. /* Request data to be read */
  1848. EFX_POPULATE_OWORD_2(reg, FRF_AB_MD_RDC, 1, FRF_AB_MD_GC, 0);
  1849. efx_writeo(efx, &reg, FR_AB_MD_CS);
  1850. /* Wait for data to become available */
  1851. rc = falcon_gmii_wait(efx);
  1852. if (rc == 0) {
  1853. efx_reado(efx, &reg, FR_AB_MD_RXD);
  1854. rc = EFX_OWORD_FIELD(reg, FRF_AB_MD_RXD);
  1855. EFX_REGDUMP(efx, "read from MDIO %d register %d.%d, got %04x\n",
  1856. prtad, devad, addr, rc);
  1857. } else {
  1858. /* Abort the read operation */
  1859. EFX_POPULATE_OWORD_2(reg,
  1860. FRF_AB_MD_RIC, 0,
  1861. FRF_AB_MD_GC, 1);
  1862. efx_writeo(efx, &reg, FR_AB_MD_CS);
  1863. EFX_LOG(efx, "read from MDIO %d register %d.%d, got error %d\n",
  1864. prtad, devad, addr, rc);
  1865. }
  1866. out:
  1867. spin_unlock_bh(&efx->phy_lock);
  1868. return rc;
  1869. }
  1870. static void falcon_clock_mac(struct efx_nic *efx)
  1871. {
  1872. unsigned strap_val;
  1873. efx_oword_t nic_stat;
  1874. /* Configure the NIC generated MAC clock correctly */
  1875. efx_reado(efx, &nic_stat, FR_AB_NIC_STAT);
  1876. strap_val = EFX_IS10G(efx) ? 5 : 3;
  1877. if (falcon_rev(efx) >= FALCON_REV_B0) {
  1878. EFX_SET_OWORD_FIELD(nic_stat, FRF_BB_EE_STRAP_EN, 1);
  1879. EFX_SET_OWORD_FIELD(nic_stat, FRF_BB_EE_STRAP, strap_val);
  1880. efx_writeo(efx, &nic_stat, FR_AB_NIC_STAT);
  1881. } else {
  1882. /* Falcon A1 does not support 1G/10G speed switching
  1883. * and must not be used with a PHY that does. */
  1884. BUG_ON(EFX_OWORD_FIELD(nic_stat, FRF_AB_STRAP_PINS) !=
  1885. strap_val);
  1886. }
  1887. }
  1888. int falcon_switch_mac(struct efx_nic *efx)
  1889. {
  1890. struct efx_mac_operations *old_mac_op = efx->mac_op;
  1891. struct falcon_nic_data *nic_data = efx->nic_data;
  1892. unsigned int stats_done_offset;
  1893. int rc = 0;
  1894. /* Don't try to fetch MAC stats while we're switching MACs */
  1895. falcon_stop_nic_stats(efx);
  1896. /* Internal loopbacks override the phy speed setting */
  1897. if (efx->loopback_mode == LOOPBACK_GMAC) {
  1898. efx->link_state.speed = 1000;
  1899. efx->link_state.fd = true;
  1900. } else if (LOOPBACK_INTERNAL(efx)) {
  1901. efx->link_state.speed = 10000;
  1902. efx->link_state.fd = true;
  1903. }
  1904. WARN_ON(!mutex_is_locked(&efx->mac_lock));
  1905. efx->mac_op = (EFX_IS10G(efx) ?
  1906. &falcon_xmac_operations : &falcon_gmac_operations);
  1907. if (EFX_IS10G(efx))
  1908. stats_done_offset = XgDmaDone_offset;
  1909. else
  1910. stats_done_offset = GDmaDone_offset;
  1911. nic_data->stats_dma_done = efx->stats_buffer.addr + stats_done_offset;
  1912. if (old_mac_op == efx->mac_op)
  1913. goto out;
  1914. falcon_clock_mac(efx);
  1915. EFX_LOG(efx, "selected %cMAC\n", EFX_IS10G(efx) ? 'X' : 'G');
  1916. /* Not all macs support a mac-level link state */
  1917. efx->xmac_poll_required = false;
  1918. rc = falcon_reset_macs(efx);
  1919. out:
  1920. falcon_start_nic_stats(efx);
  1921. return rc;
  1922. }
  1923. /* This call is responsible for hooking in the MAC and PHY operations */
  1924. int falcon_probe_port(struct efx_nic *efx)
  1925. {
  1926. int rc;
  1927. switch (efx->phy_type) {
  1928. case PHY_TYPE_SFX7101:
  1929. efx->phy_op = &falcon_sfx7101_phy_ops;
  1930. break;
  1931. case PHY_TYPE_SFT9001A:
  1932. case PHY_TYPE_SFT9001B:
  1933. efx->phy_op = &falcon_sft9001_phy_ops;
  1934. break;
  1935. case PHY_TYPE_QT2022C2:
  1936. case PHY_TYPE_QT2025C:
  1937. efx->phy_op = &falcon_qt202x_phy_ops;
  1938. break;
  1939. default:
  1940. EFX_ERR(efx, "Unknown PHY type %d\n",
  1941. efx->phy_type);
  1942. return -ENODEV;
  1943. }
  1944. if (efx->phy_op->macs & EFX_XMAC)
  1945. efx->loopback_modes |= ((1 << LOOPBACK_XGMII) |
  1946. (1 << LOOPBACK_XGXS) |
  1947. (1 << LOOPBACK_XAUI));
  1948. if (efx->phy_op->macs & EFX_GMAC)
  1949. efx->loopback_modes |= (1 << LOOPBACK_GMAC);
  1950. efx->loopback_modes |= efx->phy_op->loopbacks;
  1951. /* Set up MDIO structure for PHY */
  1952. efx->mdio.mmds = efx->phy_op->mmds;
  1953. efx->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  1954. efx->mdio.mdio_read = falcon_mdio_read;
  1955. efx->mdio.mdio_write = falcon_mdio_write;
  1956. /* Hardware flow ctrl. FalconA RX FIFO too small for pause generation */
  1957. if (falcon_rev(efx) >= FALCON_REV_B0)
  1958. efx->wanted_fc = EFX_FC_RX | EFX_FC_TX;
  1959. else
  1960. efx->wanted_fc = EFX_FC_RX;
  1961. /* Allocate buffer for stats */
  1962. rc = falcon_alloc_buffer(efx, &efx->stats_buffer,
  1963. FALCON_MAC_STATS_SIZE);
  1964. if (rc)
  1965. return rc;
  1966. EFX_LOG(efx, "stats buffer at %llx (virt %p phys %llx)\n",
  1967. (u64)efx->stats_buffer.dma_addr,
  1968. efx->stats_buffer.addr,
  1969. (u64)virt_to_phys(efx->stats_buffer.addr));
  1970. return 0;
  1971. }
  1972. void falcon_remove_port(struct efx_nic *efx)
  1973. {
  1974. falcon_free_buffer(efx, &efx->stats_buffer);
  1975. }
  1976. /**************************************************************************
  1977. *
  1978. * Multicast filtering
  1979. *
  1980. **************************************************************************
  1981. */
  1982. void falcon_push_multicast_hash(struct efx_nic *efx)
  1983. {
  1984. union efx_multicast_hash *mc_hash = &efx->multicast_hash;
  1985. WARN_ON(!mutex_is_locked(&efx->mac_lock));
  1986. efx_writeo(efx, &mc_hash->oword[0], FR_AB_MAC_MC_HASH_REG0);
  1987. efx_writeo(efx, &mc_hash->oword[1], FR_AB_MAC_MC_HASH_REG1);
  1988. }
  1989. /**************************************************************************
  1990. *
  1991. * Falcon test code
  1992. *
  1993. **************************************************************************/
  1994. int falcon_read_nvram(struct efx_nic *efx, struct falcon_nvconfig *nvconfig_out)
  1995. {
  1996. struct falcon_nvconfig *nvconfig;
  1997. struct efx_spi_device *spi;
  1998. void *region;
  1999. int rc, magic_num, struct_ver;
  2000. __le16 *word, *limit;
  2001. u32 csum;
  2002. spi = efx->spi_flash ? efx->spi_flash : efx->spi_eeprom;
  2003. if (!spi)
  2004. return -EINVAL;
  2005. region = kmalloc(FALCON_NVCONFIG_END, GFP_KERNEL);
  2006. if (!region)
  2007. return -ENOMEM;
  2008. nvconfig = region + FALCON_NVCONFIG_OFFSET;
  2009. mutex_lock(&efx->spi_lock);
  2010. rc = falcon_spi_read(spi, 0, FALCON_NVCONFIG_END, NULL, region);
  2011. mutex_unlock(&efx->spi_lock);
  2012. if (rc) {
  2013. EFX_ERR(efx, "Failed to read %s\n",
  2014. efx->spi_flash ? "flash" : "EEPROM");
  2015. rc = -EIO;
  2016. goto out;
  2017. }
  2018. magic_num = le16_to_cpu(nvconfig->board_magic_num);
  2019. struct_ver = le16_to_cpu(nvconfig->board_struct_ver);
  2020. rc = -EINVAL;
  2021. if (magic_num != FALCON_NVCONFIG_BOARD_MAGIC_NUM) {
  2022. EFX_ERR(efx, "NVRAM bad magic 0x%x\n", magic_num);
  2023. goto out;
  2024. }
  2025. if (struct_ver < 2) {
  2026. EFX_ERR(efx, "NVRAM has ancient version 0x%x\n", struct_ver);
  2027. goto out;
  2028. } else if (struct_ver < 4) {
  2029. word = &nvconfig->board_magic_num;
  2030. limit = (__le16 *) (nvconfig + 1);
  2031. } else {
  2032. word = region;
  2033. limit = region + FALCON_NVCONFIG_END;
  2034. }
  2035. for (csum = 0; word < limit; ++word)
  2036. csum += le16_to_cpu(*word);
  2037. if (~csum & 0xffff) {
  2038. EFX_ERR(efx, "NVRAM has incorrect checksum\n");
  2039. goto out;
  2040. }
  2041. rc = 0;
  2042. if (nvconfig_out)
  2043. memcpy(nvconfig_out, nvconfig, sizeof(*nvconfig));
  2044. out:
  2045. kfree(region);
  2046. return rc;
  2047. }
  2048. /* Registers tested in the falcon register test */
  2049. static struct {
  2050. unsigned address;
  2051. efx_oword_t mask;
  2052. } efx_test_registers[] = {
  2053. { FR_AZ_ADR_REGION,
  2054. EFX_OWORD32(0x0001FFFF, 0x0001FFFF, 0x0001FFFF, 0x0001FFFF) },
  2055. { FR_AZ_RX_CFG,
  2056. EFX_OWORD32(0xFFFFFFFE, 0x00017FFF, 0x00000000, 0x00000000) },
  2057. { FR_AZ_TX_CFG,
  2058. EFX_OWORD32(0x7FFF0037, 0x00000000, 0x00000000, 0x00000000) },
  2059. { FR_AZ_TX_RESERVED,
  2060. EFX_OWORD32(0xFFFEFE80, 0x1FFFFFFF, 0x020000FE, 0x007FFFFF) },
  2061. { FR_AB_MAC_CTRL,
  2062. EFX_OWORD32(0xFFFF0000, 0x00000000, 0x00000000, 0x00000000) },
  2063. { FR_AZ_SRM_TX_DC_CFG,
  2064. EFX_OWORD32(0x001FFFFF, 0x00000000, 0x00000000, 0x00000000) },
  2065. { FR_AZ_RX_DC_CFG,
  2066. EFX_OWORD32(0x0000000F, 0x00000000, 0x00000000, 0x00000000) },
  2067. { FR_AZ_RX_DC_PF_WM,
  2068. EFX_OWORD32(0x000003FF, 0x00000000, 0x00000000, 0x00000000) },
  2069. { FR_BZ_DP_CTRL,
  2070. EFX_OWORD32(0x00000FFF, 0x00000000, 0x00000000, 0x00000000) },
  2071. { FR_AB_GM_CFG2,
  2072. EFX_OWORD32(0x00007337, 0x00000000, 0x00000000, 0x00000000) },
  2073. { FR_AB_GMF_CFG0,
  2074. EFX_OWORD32(0x00001F1F, 0x00000000, 0x00000000, 0x00000000) },
  2075. { FR_AB_XM_GLB_CFG,
  2076. EFX_OWORD32(0x00000C68, 0x00000000, 0x00000000, 0x00000000) },
  2077. { FR_AB_XM_TX_CFG,
  2078. EFX_OWORD32(0x00080164, 0x00000000, 0x00000000, 0x00000000) },
  2079. { FR_AB_XM_RX_CFG,
  2080. EFX_OWORD32(0x07100A0C, 0x00000000, 0x00000000, 0x00000000) },
  2081. { FR_AB_XM_RX_PARAM,
  2082. EFX_OWORD32(0x00001FF8, 0x00000000, 0x00000000, 0x00000000) },
  2083. { FR_AB_XM_FC,
  2084. EFX_OWORD32(0xFFFF0001, 0x00000000, 0x00000000, 0x00000000) },
  2085. { FR_AB_XM_ADR_LO,
  2086. EFX_OWORD32(0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000) },
  2087. { FR_AB_XX_SD_CTL,
  2088. EFX_OWORD32(0x0003FF0F, 0x00000000, 0x00000000, 0x00000000) },
  2089. };
  2090. static bool efx_masked_compare_oword(const efx_oword_t *a, const efx_oword_t *b,
  2091. const efx_oword_t *mask)
  2092. {
  2093. return ((a->u64[0] ^ b->u64[0]) & mask->u64[0]) ||
  2094. ((a->u64[1] ^ b->u64[1]) & mask->u64[1]);
  2095. }
  2096. int falcon_test_registers(struct efx_nic *efx)
  2097. {
  2098. unsigned address = 0, i, j;
  2099. efx_oword_t mask, imask, original, reg, buf;
  2100. /* Falcon should be in loopback to isolate the XMAC from the PHY */
  2101. WARN_ON(!LOOPBACK_INTERNAL(efx));
  2102. for (i = 0; i < ARRAY_SIZE(efx_test_registers); ++i) {
  2103. address = efx_test_registers[i].address;
  2104. mask = imask = efx_test_registers[i].mask;
  2105. EFX_INVERT_OWORD(imask);
  2106. efx_reado(efx, &original, address);
  2107. /* bit sweep on and off */
  2108. for (j = 0; j < 128; j++) {
  2109. if (!EFX_EXTRACT_OWORD32(mask, j, j))
  2110. continue;
  2111. /* Test this testable bit can be set in isolation */
  2112. EFX_AND_OWORD(reg, original, mask);
  2113. EFX_SET_OWORD32(reg, j, j, 1);
  2114. efx_writeo(efx, &reg, address);
  2115. efx_reado(efx, &buf, address);
  2116. if (efx_masked_compare_oword(&reg, &buf, &mask))
  2117. goto fail;
  2118. /* Test this testable bit can be cleared in isolation */
  2119. EFX_OR_OWORD(reg, original, mask);
  2120. EFX_SET_OWORD32(reg, j, j, 0);
  2121. efx_writeo(efx, &reg, address);
  2122. efx_reado(efx, &buf, address);
  2123. if (efx_masked_compare_oword(&reg, &buf, &mask))
  2124. goto fail;
  2125. }
  2126. efx_writeo(efx, &original, address);
  2127. }
  2128. return 0;
  2129. fail:
  2130. EFX_ERR(efx, "wrote "EFX_OWORD_FMT" read "EFX_OWORD_FMT
  2131. " at address 0x%x mask "EFX_OWORD_FMT"\n", EFX_OWORD_VAL(reg),
  2132. EFX_OWORD_VAL(buf), address, EFX_OWORD_VAL(mask));
  2133. return -EIO;
  2134. }
  2135. /**************************************************************************
  2136. *
  2137. * Device reset
  2138. *
  2139. **************************************************************************
  2140. */
  2141. /* Resets NIC to known state. This routine must be called in process
  2142. * context and is allowed to sleep. */
  2143. int falcon_reset_hw(struct efx_nic *efx, enum reset_type method)
  2144. {
  2145. struct falcon_nic_data *nic_data = efx->nic_data;
  2146. efx_oword_t glb_ctl_reg_ker;
  2147. int rc;
  2148. EFX_LOG(efx, "performing %s hardware reset\n", RESET_TYPE(method));
  2149. /* Initiate device reset */
  2150. if (method == RESET_TYPE_WORLD) {
  2151. rc = pci_save_state(efx->pci_dev);
  2152. if (rc) {
  2153. EFX_ERR(efx, "failed to backup PCI state of primary "
  2154. "function prior to hardware reset\n");
  2155. goto fail1;
  2156. }
  2157. if (FALCON_IS_DUAL_FUNC(efx)) {
  2158. rc = pci_save_state(nic_data->pci_dev2);
  2159. if (rc) {
  2160. EFX_ERR(efx, "failed to backup PCI state of "
  2161. "secondary function prior to "
  2162. "hardware reset\n");
  2163. goto fail2;
  2164. }
  2165. }
  2166. EFX_POPULATE_OWORD_2(glb_ctl_reg_ker,
  2167. FRF_AB_EXT_PHY_RST_DUR,
  2168. FFE_AB_EXT_PHY_RST_DUR_10240US,
  2169. FRF_AB_SWRST, 1);
  2170. } else {
  2171. EFX_POPULATE_OWORD_7(glb_ctl_reg_ker,
  2172. /* exclude PHY from "invisible" reset */
  2173. FRF_AB_EXT_PHY_RST_CTL,
  2174. method == RESET_TYPE_INVISIBLE,
  2175. /* exclude EEPROM/flash and PCIe */
  2176. FRF_AB_PCIE_CORE_RST_CTL, 1,
  2177. FRF_AB_PCIE_NSTKY_RST_CTL, 1,
  2178. FRF_AB_PCIE_SD_RST_CTL, 1,
  2179. FRF_AB_EE_RST_CTL, 1,
  2180. FRF_AB_EXT_PHY_RST_DUR,
  2181. FFE_AB_EXT_PHY_RST_DUR_10240US,
  2182. FRF_AB_SWRST, 1);
  2183. }
  2184. efx_writeo(efx, &glb_ctl_reg_ker, FR_AB_GLB_CTL);
  2185. EFX_LOG(efx, "waiting for hardware reset\n");
  2186. schedule_timeout_uninterruptible(HZ / 20);
  2187. /* Restore PCI configuration if needed */
  2188. if (method == RESET_TYPE_WORLD) {
  2189. if (FALCON_IS_DUAL_FUNC(efx)) {
  2190. rc = pci_restore_state(nic_data->pci_dev2);
  2191. if (rc) {
  2192. EFX_ERR(efx, "failed to restore PCI config for "
  2193. "the secondary function\n");
  2194. goto fail3;
  2195. }
  2196. }
  2197. rc = pci_restore_state(efx->pci_dev);
  2198. if (rc) {
  2199. EFX_ERR(efx, "failed to restore PCI config for the "
  2200. "primary function\n");
  2201. goto fail4;
  2202. }
  2203. EFX_LOG(efx, "successfully restored PCI config\n");
  2204. }
  2205. /* Assert that reset complete */
  2206. efx_reado(efx, &glb_ctl_reg_ker, FR_AB_GLB_CTL);
  2207. if (EFX_OWORD_FIELD(glb_ctl_reg_ker, FRF_AB_SWRST) != 0) {
  2208. rc = -ETIMEDOUT;
  2209. EFX_ERR(efx, "timed out waiting for hardware reset\n");
  2210. goto fail5;
  2211. }
  2212. EFX_LOG(efx, "hardware reset complete\n");
  2213. return 0;
  2214. /* pci_save_state() and pci_restore_state() MUST be called in pairs */
  2215. fail2:
  2216. fail3:
  2217. pci_restore_state(efx->pci_dev);
  2218. fail1:
  2219. fail4:
  2220. fail5:
  2221. return rc;
  2222. }
  2223. void falcon_monitor(struct efx_nic *efx)
  2224. {
  2225. int rc;
  2226. rc = falcon_board(efx)->type->monitor(efx);
  2227. if (rc) {
  2228. EFX_ERR(efx, "Board sensor %s; shutting down PHY\n",
  2229. (rc == -ERANGE) ? "reported fault" : "failed");
  2230. efx->phy_mode |= PHY_MODE_LOW_POWER;
  2231. falcon_sim_phy_event(efx);
  2232. }
  2233. efx->phy_op->poll(efx);
  2234. if (EFX_IS10G(efx))
  2235. falcon_poll_xmac(efx);
  2236. }
  2237. /* Zeroes out the SRAM contents. This routine must be called in
  2238. * process context and is allowed to sleep.
  2239. */
  2240. static int falcon_reset_sram(struct efx_nic *efx)
  2241. {
  2242. efx_oword_t srm_cfg_reg_ker, gpio_cfg_reg_ker;
  2243. int count;
  2244. /* Set the SRAM wake/sleep GPIO appropriately. */
  2245. efx_reado(efx, &gpio_cfg_reg_ker, FR_AB_GPIO_CTL);
  2246. EFX_SET_OWORD_FIELD(gpio_cfg_reg_ker, FRF_AB_GPIO1_OEN, 1);
  2247. EFX_SET_OWORD_FIELD(gpio_cfg_reg_ker, FRF_AB_GPIO1_OUT, 1);
  2248. efx_writeo(efx, &gpio_cfg_reg_ker, FR_AB_GPIO_CTL);
  2249. /* Initiate SRAM reset */
  2250. EFX_POPULATE_OWORD_2(srm_cfg_reg_ker,
  2251. FRF_AZ_SRM_INIT_EN, 1,
  2252. FRF_AZ_SRM_NB_SZ, 0);
  2253. efx_writeo(efx, &srm_cfg_reg_ker, FR_AZ_SRM_CFG);
  2254. /* Wait for SRAM reset to complete */
  2255. count = 0;
  2256. do {
  2257. EFX_LOG(efx, "waiting for SRAM reset (attempt %d)...\n", count);
  2258. /* SRAM reset is slow; expect around 16ms */
  2259. schedule_timeout_uninterruptible(HZ / 50);
  2260. /* Check for reset complete */
  2261. efx_reado(efx, &srm_cfg_reg_ker, FR_AZ_SRM_CFG);
  2262. if (!EFX_OWORD_FIELD(srm_cfg_reg_ker, FRF_AZ_SRM_INIT_EN)) {
  2263. EFX_LOG(efx, "SRAM reset complete\n");
  2264. return 0;
  2265. }
  2266. } while (++count < 20); /* wait upto 0.4 sec */
  2267. EFX_ERR(efx, "timed out waiting for SRAM reset\n");
  2268. return -ETIMEDOUT;
  2269. }
  2270. static int falcon_spi_device_init(struct efx_nic *efx,
  2271. struct efx_spi_device **spi_device_ret,
  2272. unsigned int device_id, u32 device_type)
  2273. {
  2274. struct efx_spi_device *spi_device;
  2275. if (device_type != 0) {
  2276. spi_device = kzalloc(sizeof(*spi_device), GFP_KERNEL);
  2277. if (!spi_device)
  2278. return -ENOMEM;
  2279. spi_device->device_id = device_id;
  2280. spi_device->size =
  2281. 1 << SPI_DEV_TYPE_FIELD(device_type, SPI_DEV_TYPE_SIZE);
  2282. spi_device->addr_len =
  2283. SPI_DEV_TYPE_FIELD(device_type, SPI_DEV_TYPE_ADDR_LEN);
  2284. spi_device->munge_address = (spi_device->size == 1 << 9 &&
  2285. spi_device->addr_len == 1);
  2286. spi_device->erase_command =
  2287. SPI_DEV_TYPE_FIELD(device_type, SPI_DEV_TYPE_ERASE_CMD);
  2288. spi_device->erase_size =
  2289. 1 << SPI_DEV_TYPE_FIELD(device_type,
  2290. SPI_DEV_TYPE_ERASE_SIZE);
  2291. spi_device->block_size =
  2292. 1 << SPI_DEV_TYPE_FIELD(device_type,
  2293. SPI_DEV_TYPE_BLOCK_SIZE);
  2294. spi_device->efx = efx;
  2295. } else {
  2296. spi_device = NULL;
  2297. }
  2298. kfree(*spi_device_ret);
  2299. *spi_device_ret = spi_device;
  2300. return 0;
  2301. }
  2302. static void falcon_remove_spi_devices(struct efx_nic *efx)
  2303. {
  2304. kfree(efx->spi_eeprom);
  2305. efx->spi_eeprom = NULL;
  2306. kfree(efx->spi_flash);
  2307. efx->spi_flash = NULL;
  2308. }
  2309. /* Extract non-volatile configuration */
  2310. static int falcon_probe_nvconfig(struct efx_nic *efx)
  2311. {
  2312. struct falcon_nvconfig *nvconfig;
  2313. int board_rev;
  2314. int rc;
  2315. nvconfig = kmalloc(sizeof(*nvconfig), GFP_KERNEL);
  2316. if (!nvconfig)
  2317. return -ENOMEM;
  2318. rc = falcon_read_nvram(efx, nvconfig);
  2319. if (rc == -EINVAL) {
  2320. EFX_ERR(efx, "NVRAM is invalid therefore using defaults\n");
  2321. efx->phy_type = PHY_TYPE_NONE;
  2322. efx->mdio.prtad = MDIO_PRTAD_NONE;
  2323. board_rev = 0;
  2324. rc = 0;
  2325. } else if (rc) {
  2326. goto fail1;
  2327. } else {
  2328. struct falcon_nvconfig_board_v2 *v2 = &nvconfig->board_v2;
  2329. struct falcon_nvconfig_board_v3 *v3 = &nvconfig->board_v3;
  2330. efx->phy_type = v2->port0_phy_type;
  2331. efx->mdio.prtad = v2->port0_phy_addr;
  2332. board_rev = le16_to_cpu(v2->board_revision);
  2333. if (le16_to_cpu(nvconfig->board_struct_ver) >= 3) {
  2334. rc = falcon_spi_device_init(
  2335. efx, &efx->spi_flash, FFE_AB_SPI_DEVICE_FLASH,
  2336. le32_to_cpu(v3->spi_device_type
  2337. [FFE_AB_SPI_DEVICE_FLASH]));
  2338. if (rc)
  2339. goto fail2;
  2340. rc = falcon_spi_device_init(
  2341. efx, &efx->spi_eeprom, FFE_AB_SPI_DEVICE_EEPROM,
  2342. le32_to_cpu(v3->spi_device_type
  2343. [FFE_AB_SPI_DEVICE_EEPROM]));
  2344. if (rc)
  2345. goto fail2;
  2346. }
  2347. }
  2348. /* Read the MAC addresses */
  2349. memcpy(efx->mac_address, nvconfig->mac_address[0], ETH_ALEN);
  2350. EFX_LOG(efx, "PHY is %d phy_id %d\n", efx->phy_type, efx->mdio.prtad);
  2351. falcon_probe_board(efx, board_rev);
  2352. kfree(nvconfig);
  2353. return 0;
  2354. fail2:
  2355. falcon_remove_spi_devices(efx);
  2356. fail1:
  2357. kfree(nvconfig);
  2358. return rc;
  2359. }
  2360. /* Probe the NIC variant (revision, ASIC vs FPGA, function count, port
  2361. * count, port speed). Set workaround and feature flags accordingly.
  2362. */
  2363. static int falcon_probe_nic_variant(struct efx_nic *efx)
  2364. {
  2365. efx_oword_t altera_build;
  2366. efx_oword_t nic_stat;
  2367. efx_reado(efx, &altera_build, FR_AZ_ALTERA_BUILD);
  2368. if (EFX_OWORD_FIELD(altera_build, FRF_AZ_ALTERA_BUILD_VER)) {
  2369. EFX_ERR(efx, "Falcon FPGA not supported\n");
  2370. return -ENODEV;
  2371. }
  2372. efx_reado(efx, &nic_stat, FR_AB_NIC_STAT);
  2373. switch (falcon_rev(efx)) {
  2374. case FALCON_REV_A0:
  2375. case 0xff:
  2376. EFX_ERR(efx, "Falcon rev A0 not supported\n");
  2377. return -ENODEV;
  2378. case FALCON_REV_A1:
  2379. if (EFX_OWORD_FIELD(nic_stat, FRF_AA_STRAP_PCIE) == 0) {
  2380. EFX_ERR(efx, "Falcon rev A1 PCI-X not supported\n");
  2381. return -ENODEV;
  2382. }
  2383. break;
  2384. case FALCON_REV_B0:
  2385. break;
  2386. default:
  2387. EFX_ERR(efx, "Unknown Falcon rev %d\n", falcon_rev(efx));
  2388. return -ENODEV;
  2389. }
  2390. /* Initial assumed speed */
  2391. efx->link_state.speed = EFX_OWORD_FIELD(nic_stat, FRF_AB_STRAP_10G) ? 10000 : 1000;
  2392. return 0;
  2393. }
  2394. /* Probe all SPI devices on the NIC */
  2395. static void falcon_probe_spi_devices(struct efx_nic *efx)
  2396. {
  2397. efx_oword_t nic_stat, gpio_ctl, ee_vpd_cfg;
  2398. int boot_dev;
  2399. efx_reado(efx, &gpio_ctl, FR_AB_GPIO_CTL);
  2400. efx_reado(efx, &nic_stat, FR_AB_NIC_STAT);
  2401. efx_reado(efx, &ee_vpd_cfg, FR_AB_EE_VPD_CFG0);
  2402. if (EFX_OWORD_FIELD(gpio_ctl, FRF_AB_GPIO3_PWRUP_VALUE)) {
  2403. boot_dev = (EFX_OWORD_FIELD(nic_stat, FRF_AB_SF_PRST) ?
  2404. FFE_AB_SPI_DEVICE_FLASH : FFE_AB_SPI_DEVICE_EEPROM);
  2405. EFX_LOG(efx, "Booted from %s\n",
  2406. boot_dev == FFE_AB_SPI_DEVICE_FLASH ? "flash" : "EEPROM");
  2407. } else {
  2408. /* Disable VPD and set clock dividers to safe
  2409. * values for initial programming. */
  2410. boot_dev = -1;
  2411. EFX_LOG(efx, "Booted from internal ASIC settings;"
  2412. " setting SPI config\n");
  2413. EFX_POPULATE_OWORD_3(ee_vpd_cfg, FRF_AB_EE_VPD_EN, 0,
  2414. /* 125 MHz / 7 ~= 20 MHz */
  2415. FRF_AB_EE_SF_CLOCK_DIV, 7,
  2416. /* 125 MHz / 63 ~= 2 MHz */
  2417. FRF_AB_EE_EE_CLOCK_DIV, 63);
  2418. efx_writeo(efx, &ee_vpd_cfg, FR_AB_EE_VPD_CFG0);
  2419. }
  2420. if (boot_dev == FFE_AB_SPI_DEVICE_FLASH)
  2421. falcon_spi_device_init(efx, &efx->spi_flash,
  2422. FFE_AB_SPI_DEVICE_FLASH,
  2423. default_flash_type);
  2424. if (boot_dev == FFE_AB_SPI_DEVICE_EEPROM)
  2425. falcon_spi_device_init(efx, &efx->spi_eeprom,
  2426. FFE_AB_SPI_DEVICE_EEPROM,
  2427. large_eeprom_type);
  2428. }
  2429. int falcon_probe_nic(struct efx_nic *efx)
  2430. {
  2431. struct falcon_nic_data *nic_data;
  2432. struct falcon_board *board;
  2433. int rc;
  2434. /* Allocate storage for hardware specific data */
  2435. nic_data = kzalloc(sizeof(*nic_data), GFP_KERNEL);
  2436. if (!nic_data)
  2437. return -ENOMEM;
  2438. efx->nic_data = nic_data;
  2439. /* Determine number of ports etc. */
  2440. rc = falcon_probe_nic_variant(efx);
  2441. if (rc)
  2442. goto fail1;
  2443. /* Probe secondary function if expected */
  2444. if (FALCON_IS_DUAL_FUNC(efx)) {
  2445. struct pci_dev *dev = pci_dev_get(efx->pci_dev);
  2446. while ((dev = pci_get_device(EFX_VENDID_SFC, FALCON_A_S_DEVID,
  2447. dev))) {
  2448. if (dev->bus == efx->pci_dev->bus &&
  2449. dev->devfn == efx->pci_dev->devfn + 1) {
  2450. nic_data->pci_dev2 = dev;
  2451. break;
  2452. }
  2453. }
  2454. if (!nic_data->pci_dev2) {
  2455. EFX_ERR(efx, "failed to find secondary function\n");
  2456. rc = -ENODEV;
  2457. goto fail2;
  2458. }
  2459. }
  2460. /* Now we can reset the NIC */
  2461. rc = falcon_reset_hw(efx, RESET_TYPE_ALL);
  2462. if (rc) {
  2463. EFX_ERR(efx, "failed to reset NIC\n");
  2464. goto fail3;
  2465. }
  2466. /* Allocate memory for INT_KER */
  2467. rc = falcon_alloc_buffer(efx, &efx->irq_status, sizeof(efx_oword_t));
  2468. if (rc)
  2469. goto fail4;
  2470. BUG_ON(efx->irq_status.dma_addr & 0x0f);
  2471. EFX_LOG(efx, "INT_KER at %llx (virt %p phys %llx)\n",
  2472. (u64)efx->irq_status.dma_addr,
  2473. efx->irq_status.addr, (u64)virt_to_phys(efx->irq_status.addr));
  2474. falcon_probe_spi_devices(efx);
  2475. /* Read in the non-volatile configuration */
  2476. rc = falcon_probe_nvconfig(efx);
  2477. if (rc)
  2478. goto fail5;
  2479. /* Initialise I2C adapter */
  2480. board = falcon_board(efx);
  2481. board->i2c_adap.owner = THIS_MODULE;
  2482. board->i2c_data = falcon_i2c_bit_operations;
  2483. board->i2c_data.data = efx;
  2484. board->i2c_adap.algo_data = &board->i2c_data;
  2485. board->i2c_adap.dev.parent = &efx->pci_dev->dev;
  2486. strlcpy(board->i2c_adap.name, "SFC4000 GPIO",
  2487. sizeof(board->i2c_adap.name));
  2488. rc = i2c_bit_add_bus(&board->i2c_adap);
  2489. if (rc)
  2490. goto fail5;
  2491. rc = falcon_board(efx)->type->init(efx);
  2492. if (rc) {
  2493. EFX_ERR(efx, "failed to initialise board\n");
  2494. goto fail6;
  2495. }
  2496. nic_data->stats_disable_count = 1;
  2497. setup_timer(&nic_data->stats_timer, &falcon_stats_timer_func,
  2498. (unsigned long)efx);
  2499. return 0;
  2500. fail6:
  2501. BUG_ON(i2c_del_adapter(&board->i2c_adap));
  2502. memset(&board->i2c_adap, 0, sizeof(board->i2c_adap));
  2503. fail5:
  2504. falcon_remove_spi_devices(efx);
  2505. falcon_free_buffer(efx, &efx->irq_status);
  2506. fail4:
  2507. fail3:
  2508. if (nic_data->pci_dev2) {
  2509. pci_dev_put(nic_data->pci_dev2);
  2510. nic_data->pci_dev2 = NULL;
  2511. }
  2512. fail2:
  2513. fail1:
  2514. kfree(efx->nic_data);
  2515. return rc;
  2516. }
  2517. static void falcon_init_rx_cfg(struct efx_nic *efx)
  2518. {
  2519. /* Prior to Siena the RX DMA engine will split each frame at
  2520. * intervals of RX_USR_BUF_SIZE (32-byte units). We set it to
  2521. * be so large that that never happens. */
  2522. const unsigned huge_buf_size = (3 * 4096) >> 5;
  2523. /* RX control FIFO thresholds (32 entries) */
  2524. const unsigned ctrl_xon_thr = 20;
  2525. const unsigned ctrl_xoff_thr = 25;
  2526. /* RX data FIFO thresholds (256-byte units; size varies) */
  2527. int data_xon_thr = rx_xon_thresh_bytes >> 8;
  2528. int data_xoff_thr = rx_xoff_thresh_bytes >> 8;
  2529. efx_oword_t reg;
  2530. efx_reado(efx, &reg, FR_AZ_RX_CFG);
  2531. if (falcon_rev(efx) <= FALCON_REV_A1) {
  2532. /* Data FIFO size is 5.5K */
  2533. if (data_xon_thr < 0)
  2534. data_xon_thr = 512 >> 8;
  2535. if (data_xoff_thr < 0)
  2536. data_xoff_thr = 2048 >> 8;
  2537. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_DESC_PUSH_EN, 0);
  2538. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_USR_BUF_SIZE,
  2539. huge_buf_size);
  2540. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XON_MAC_TH, data_xon_thr);
  2541. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XOFF_MAC_TH, data_xoff_thr);
  2542. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XON_TX_TH, ctrl_xon_thr);
  2543. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XOFF_TX_TH, ctrl_xoff_thr);
  2544. } else {
  2545. /* Data FIFO size is 80K; register fields moved */
  2546. if (data_xon_thr < 0)
  2547. data_xon_thr = 27648 >> 8; /* ~3*max MTU */
  2548. if (data_xoff_thr < 0)
  2549. data_xoff_thr = 54272 >> 8; /* ~80Kb - 3*max MTU */
  2550. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_DESC_PUSH_EN, 0);
  2551. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_USR_BUF_SIZE,
  2552. huge_buf_size);
  2553. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XON_MAC_TH, data_xon_thr);
  2554. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XOFF_MAC_TH, data_xoff_thr);
  2555. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XON_TX_TH, ctrl_xon_thr);
  2556. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XOFF_TX_TH, ctrl_xoff_thr);
  2557. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_INGR_EN, 1);
  2558. }
  2559. efx_writeo(efx, &reg, FR_AZ_RX_CFG);
  2560. }
  2561. /* This call performs hardware-specific global initialisation, such as
  2562. * defining the descriptor cache sizes and number of RSS channels.
  2563. * It does not set up any buffers, descriptor rings or event queues.
  2564. */
  2565. int falcon_init_nic(struct efx_nic *efx)
  2566. {
  2567. efx_oword_t temp;
  2568. int rc;
  2569. /* Use on-chip SRAM */
  2570. efx_reado(efx, &temp, FR_AB_NIC_STAT);
  2571. EFX_SET_OWORD_FIELD(temp, FRF_AB_ONCHIP_SRAM, 1);
  2572. efx_writeo(efx, &temp, FR_AB_NIC_STAT);
  2573. /* Set the source of the GMAC clock */
  2574. if (falcon_rev(efx) == FALCON_REV_B0) {
  2575. efx_reado(efx, &temp, FR_AB_GPIO_CTL);
  2576. EFX_SET_OWORD_FIELD(temp, FRF_AB_USE_NIC_CLK, true);
  2577. efx_writeo(efx, &temp, FR_AB_GPIO_CTL);
  2578. }
  2579. /* Select the correct MAC */
  2580. falcon_clock_mac(efx);
  2581. rc = falcon_reset_sram(efx);
  2582. if (rc)
  2583. return rc;
  2584. /* Set positions of descriptor caches in SRAM. */
  2585. EFX_POPULATE_OWORD_1(temp, FRF_AZ_SRM_TX_DC_BASE_ADR, TX_DC_BASE / 8);
  2586. efx_writeo(efx, &temp, FR_AZ_SRM_TX_DC_CFG);
  2587. EFX_POPULATE_OWORD_1(temp, FRF_AZ_SRM_RX_DC_BASE_ADR, RX_DC_BASE / 8);
  2588. efx_writeo(efx, &temp, FR_AZ_SRM_RX_DC_CFG);
  2589. /* Set TX descriptor cache size. */
  2590. BUILD_BUG_ON(TX_DC_ENTRIES != (8 << TX_DC_ENTRIES_ORDER));
  2591. EFX_POPULATE_OWORD_1(temp, FRF_AZ_TX_DC_SIZE, TX_DC_ENTRIES_ORDER);
  2592. efx_writeo(efx, &temp, FR_AZ_TX_DC_CFG);
  2593. /* Set RX descriptor cache size. Set low watermark to size-8, as
  2594. * this allows most efficient prefetching.
  2595. */
  2596. BUILD_BUG_ON(RX_DC_ENTRIES != (8 << RX_DC_ENTRIES_ORDER));
  2597. EFX_POPULATE_OWORD_1(temp, FRF_AZ_RX_DC_SIZE, RX_DC_ENTRIES_ORDER);
  2598. efx_writeo(efx, &temp, FR_AZ_RX_DC_CFG);
  2599. EFX_POPULATE_OWORD_1(temp, FRF_AZ_RX_DC_PF_LWM, RX_DC_ENTRIES - 8);
  2600. efx_writeo(efx, &temp, FR_AZ_RX_DC_PF_WM);
  2601. /* Clear the parity enables on the TX data fifos as
  2602. * they produce false parity errors because of timing issues
  2603. */
  2604. if (EFX_WORKAROUND_5129(efx)) {
  2605. efx_reado(efx, &temp, FR_AZ_CSR_SPARE);
  2606. EFX_SET_OWORD_FIELD(temp, FRF_AB_MEM_PERR_EN_TX_DATA, 0);
  2607. efx_writeo(efx, &temp, FR_AZ_CSR_SPARE);
  2608. }
  2609. /* Enable all the genuinely fatal interrupts. (They are still
  2610. * masked by the overall interrupt mask, controlled by
  2611. * falcon_interrupts()).
  2612. *
  2613. * Note: All other fatal interrupts are enabled
  2614. */
  2615. EFX_POPULATE_OWORD_3(temp,
  2616. FRF_AZ_ILL_ADR_INT_KER_EN, 1,
  2617. FRF_AZ_RBUF_OWN_INT_KER_EN, 1,
  2618. FRF_AZ_TBUF_OWN_INT_KER_EN, 1);
  2619. EFX_INVERT_OWORD(temp);
  2620. efx_writeo(efx, &temp, FR_AZ_FATAL_INTR_KER);
  2621. if (EFX_WORKAROUND_7244(efx)) {
  2622. efx_reado(efx, &temp, FR_BZ_RX_FILTER_CTL);
  2623. EFX_SET_OWORD_FIELD(temp, FRF_BZ_UDP_FULL_SRCH_LIMIT, 8);
  2624. EFX_SET_OWORD_FIELD(temp, FRF_BZ_UDP_WILD_SRCH_LIMIT, 8);
  2625. EFX_SET_OWORD_FIELD(temp, FRF_BZ_TCP_FULL_SRCH_LIMIT, 8);
  2626. EFX_SET_OWORD_FIELD(temp, FRF_BZ_TCP_WILD_SRCH_LIMIT, 8);
  2627. efx_writeo(efx, &temp, FR_BZ_RX_FILTER_CTL);
  2628. }
  2629. falcon_setup_rss_indir_table(efx);
  2630. /* XXX This is documented only for Falcon A0/A1 */
  2631. /* Setup RX. Wait for descriptor is broken and must
  2632. * be disabled. RXDP recovery shouldn't be needed, but is.
  2633. */
  2634. efx_reado(efx, &temp, FR_AA_RX_SELF_RST);
  2635. EFX_SET_OWORD_FIELD(temp, FRF_AA_RX_NODESC_WAIT_DIS, 1);
  2636. EFX_SET_OWORD_FIELD(temp, FRF_AA_RX_SELF_RST_EN, 1);
  2637. if (EFX_WORKAROUND_5583(efx))
  2638. EFX_SET_OWORD_FIELD(temp, FRF_AA_RX_ISCSI_DIS, 1);
  2639. efx_writeo(efx, &temp, FR_AA_RX_SELF_RST);
  2640. /* Disable the ugly timer-based TX DMA backoff and allow TX DMA to be
  2641. * controlled by the RX FIFO fill level. Set arbitration to one pkt/Q.
  2642. */
  2643. efx_reado(efx, &temp, FR_AZ_TX_RESERVED);
  2644. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_RX_SPACER, 0xfe);
  2645. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_RX_SPACER_EN, 1);
  2646. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_ONE_PKT_PER_Q, 1);
  2647. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_PUSH_EN, 0);
  2648. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_DIS_NON_IP_EV, 1);
  2649. /* Enable SW_EV to inherit in char driver - assume harmless here */
  2650. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_SOFT_EVT_EN, 1);
  2651. /* Prefetch threshold 2 => fetch when descriptor cache half empty */
  2652. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_PREF_THRESHOLD, 2);
  2653. /* Squash TX of packets of 16 bytes or less */
  2654. if (falcon_rev(efx) >= FALCON_REV_B0 && EFX_WORKAROUND_9141(efx))
  2655. EFX_SET_OWORD_FIELD(temp, FRF_BZ_TX_FLUSH_MIN_LEN_EN, 1);
  2656. efx_writeo(efx, &temp, FR_AZ_TX_RESERVED);
  2657. /* Do not enable TX_NO_EOP_DISC_EN, since it limits packets to 16
  2658. * descriptors (which is bad).
  2659. */
  2660. efx_reado(efx, &temp, FR_AZ_TX_CFG);
  2661. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_NO_EOP_DISC_EN, 0);
  2662. efx_writeo(efx, &temp, FR_AZ_TX_CFG);
  2663. falcon_init_rx_cfg(efx);
  2664. /* Set destination of both TX and RX Flush events */
  2665. if (falcon_rev(efx) >= FALCON_REV_B0) {
  2666. EFX_POPULATE_OWORD_1(temp, FRF_BZ_FLS_EVQ_ID, 0);
  2667. efx_writeo(efx, &temp, FR_BZ_DP_CTRL);
  2668. }
  2669. return 0;
  2670. }
  2671. void falcon_remove_nic(struct efx_nic *efx)
  2672. {
  2673. struct falcon_nic_data *nic_data = efx->nic_data;
  2674. struct falcon_board *board = falcon_board(efx);
  2675. int rc;
  2676. board->type->fini(efx);
  2677. /* Remove I2C adapter and clear it in preparation for a retry */
  2678. rc = i2c_del_adapter(&board->i2c_adap);
  2679. BUG_ON(rc);
  2680. memset(&board->i2c_adap, 0, sizeof(board->i2c_adap));
  2681. falcon_remove_spi_devices(efx);
  2682. falcon_free_buffer(efx, &efx->irq_status);
  2683. falcon_reset_hw(efx, RESET_TYPE_ALL);
  2684. /* Release the second function after the reset */
  2685. if (nic_data->pci_dev2) {
  2686. pci_dev_put(nic_data->pci_dev2);
  2687. nic_data->pci_dev2 = NULL;
  2688. }
  2689. /* Tear down the private nic state */
  2690. kfree(efx->nic_data);
  2691. efx->nic_data = NULL;
  2692. }
  2693. void falcon_update_nic_stats(struct efx_nic *efx)
  2694. {
  2695. struct falcon_nic_data *nic_data = efx->nic_data;
  2696. efx_oword_t cnt;
  2697. if (nic_data->stats_disable_count)
  2698. return;
  2699. efx_reado(efx, &cnt, FR_AZ_RX_NODESC_DROP);
  2700. efx->n_rx_nodesc_drop_cnt +=
  2701. EFX_OWORD_FIELD(cnt, FRF_AB_RX_NODESC_DROP_CNT);
  2702. if (nic_data->stats_pending &&
  2703. *nic_data->stats_dma_done == FALCON_STATS_DONE) {
  2704. nic_data->stats_pending = false;
  2705. rmb(); /* read the done flag before the stats */
  2706. efx->mac_op->update_stats(efx);
  2707. }
  2708. }
  2709. void falcon_start_nic_stats(struct efx_nic *efx)
  2710. {
  2711. struct falcon_nic_data *nic_data = efx->nic_data;
  2712. spin_lock_bh(&efx->stats_lock);
  2713. if (--nic_data->stats_disable_count == 0)
  2714. falcon_stats_request(efx);
  2715. spin_unlock_bh(&efx->stats_lock);
  2716. }
  2717. void falcon_stop_nic_stats(struct efx_nic *efx)
  2718. {
  2719. struct falcon_nic_data *nic_data = efx->nic_data;
  2720. int i;
  2721. might_sleep();
  2722. spin_lock_bh(&efx->stats_lock);
  2723. ++nic_data->stats_disable_count;
  2724. spin_unlock_bh(&efx->stats_lock);
  2725. del_timer_sync(&nic_data->stats_timer);
  2726. /* Wait enough time for the most recent transfer to
  2727. * complete. */
  2728. for (i = 0; i < 4 && nic_data->stats_pending; i++) {
  2729. if (*nic_data->stats_dma_done == FALCON_STATS_DONE)
  2730. break;
  2731. msleep(1);
  2732. }
  2733. spin_lock_bh(&efx->stats_lock);
  2734. falcon_stats_complete(efx);
  2735. spin_unlock_bh(&efx->stats_lock);
  2736. }
  2737. /**************************************************************************
  2738. *
  2739. * Revision-dependent attributes used by efx.c
  2740. *
  2741. **************************************************************************
  2742. */
  2743. struct efx_nic_type falcon_a_nic_type = {
  2744. .mem_map_size = 0x20000,
  2745. .txd_ptr_tbl_base = FR_AA_TX_DESC_PTR_TBL_KER,
  2746. .rxd_ptr_tbl_base = FR_AA_RX_DESC_PTR_TBL_KER,
  2747. .buf_tbl_base = FR_AA_BUF_FULL_TBL_KER,
  2748. .evq_ptr_tbl_base = FR_AA_EVQ_PTR_TBL_KER,
  2749. .evq_rptr_tbl_base = FR_AA_EVQ_RPTR_KER,
  2750. .max_dma_mask = DMA_BIT_MASK(FSF_AZ_TX_KER_BUF_ADDR_WIDTH),
  2751. .rx_buffer_padding = 0x24,
  2752. .max_interrupt_mode = EFX_INT_MODE_MSI,
  2753. .phys_addr_channels = 4,
  2754. };
  2755. struct efx_nic_type falcon_b_nic_type = {
  2756. /* Map everything up to and including the RSS indirection
  2757. * table. Don't map MSI-X table, MSI-X PBA since Linux
  2758. * requires that they not be mapped. */
  2759. .mem_map_size = (FR_BZ_RX_INDIRECTION_TBL +
  2760. FR_BZ_RX_INDIRECTION_TBL_STEP *
  2761. FR_BZ_RX_INDIRECTION_TBL_ROWS),
  2762. .txd_ptr_tbl_base = FR_BZ_TX_DESC_PTR_TBL,
  2763. .rxd_ptr_tbl_base = FR_BZ_RX_DESC_PTR_TBL,
  2764. .buf_tbl_base = FR_BZ_BUF_FULL_TBL,
  2765. .evq_ptr_tbl_base = FR_BZ_EVQ_PTR_TBL,
  2766. .evq_rptr_tbl_base = FR_BZ_EVQ_RPTR,
  2767. .max_dma_mask = DMA_BIT_MASK(FSF_AZ_TX_KER_BUF_ADDR_WIDTH),
  2768. .rx_buffer_padding = 0,
  2769. .max_interrupt_mode = EFX_INT_MODE_MSIX,
  2770. .phys_addr_channels = 32, /* Hardware limit is 64, but the legacy
  2771. * interrupt handler only supports 32
  2772. * channels */
  2773. };