falcon.c 90 KB

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