falcon.c 89 KB

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