falcon.c 90 KB

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