falcon.c 89 KB

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