falcon.c 92 KB

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