falcon.c 89 KB

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