falcon.c 89 KB

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