falcon.c 89 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153
  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. efx->rx_checksum_enabled &&
  754. (rx_ev_hdr_type == FSE_AB_RX_EV_HDR_TYPE_IPV4_TCP ||
  755. rx_ev_hdr_type == FSE_AB_RX_EV_HDR_TYPE_IPV4_UDP);
  756. } else {
  757. falcon_handle_rx_not_ok(rx_queue, event, &rx_ev_pkt_ok,
  758. &discard);
  759. checksummed = false;
  760. }
  761. /* Detect multicast packets that didn't match the filter */
  762. rx_ev_mcast_pkt = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_MCAST_PKT);
  763. if (rx_ev_mcast_pkt) {
  764. unsigned int rx_ev_mcast_hash_match =
  765. EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_MCAST_HASH_MATCH);
  766. if (unlikely(!rx_ev_mcast_hash_match))
  767. discard = true;
  768. }
  769. channel->irq_mod_score += 2;
  770. /* Handle received packet */
  771. efx_rx_packet(rx_queue, rx_ev_desc_ptr, rx_ev_byte_cnt,
  772. checksummed, discard);
  773. }
  774. /* Global events are basically PHY events */
  775. static void falcon_handle_global_event(struct efx_channel *channel,
  776. efx_qword_t *event)
  777. {
  778. struct efx_nic *efx = channel->efx;
  779. bool handled = false;
  780. if (EFX_QWORD_FIELD(*event, FSF_AB_GLB_EV_G_PHY0_INTR) ||
  781. EFX_QWORD_FIELD(*event, FSF_AB_GLB_EV_XG_PHY0_INTR) ||
  782. EFX_QWORD_FIELD(*event, FSF_AB_GLB_EV_XFP_PHY0_INTR)) {
  783. efx->phy_op->clear_interrupt(efx);
  784. queue_work(efx->workqueue, &efx->phy_work);
  785. handled = true;
  786. }
  787. if ((falcon_rev(efx) >= FALCON_REV_B0) &&
  788. EFX_QWORD_FIELD(*event, FSF_BB_GLB_EV_XG_MGT_INTR)) {
  789. queue_work(efx->workqueue, &efx->mac_work);
  790. handled = true;
  791. }
  792. if (falcon_rev(efx) <= FALCON_REV_A1 ?
  793. EFX_QWORD_FIELD(*event, FSF_AA_GLB_EV_RX_RECOVERY) :
  794. EFX_QWORD_FIELD(*event, FSF_BB_GLB_EV_RX_RECOVERY)) {
  795. EFX_ERR(efx, "channel %d seen global RX_RESET "
  796. "event. Resetting.\n", channel->channel);
  797. atomic_inc(&efx->rx_reset);
  798. efx_schedule_reset(efx, EFX_WORKAROUND_6555(efx) ?
  799. RESET_TYPE_RX_RECOVERY : RESET_TYPE_DISABLE);
  800. handled = true;
  801. }
  802. if (!handled)
  803. EFX_ERR(efx, "channel %d unknown global event "
  804. EFX_QWORD_FMT "\n", channel->channel,
  805. EFX_QWORD_VAL(*event));
  806. }
  807. static void falcon_handle_driver_event(struct efx_channel *channel,
  808. efx_qword_t *event)
  809. {
  810. struct efx_nic *efx = channel->efx;
  811. unsigned int ev_sub_code;
  812. unsigned int ev_sub_data;
  813. ev_sub_code = EFX_QWORD_FIELD(*event, FSF_AZ_DRIVER_EV_SUBCODE);
  814. ev_sub_data = EFX_QWORD_FIELD(*event, FSF_AZ_DRIVER_EV_SUBDATA);
  815. switch (ev_sub_code) {
  816. case FSE_AZ_TX_DESCQ_FLS_DONE_EV:
  817. EFX_TRACE(efx, "channel %d TXQ %d flushed\n",
  818. channel->channel, ev_sub_data);
  819. break;
  820. case FSE_AZ_RX_DESCQ_FLS_DONE_EV:
  821. EFX_TRACE(efx, "channel %d RXQ %d flushed\n",
  822. channel->channel, ev_sub_data);
  823. break;
  824. case FSE_AZ_EVQ_INIT_DONE_EV:
  825. EFX_LOG(efx, "channel %d EVQ %d initialised\n",
  826. channel->channel, ev_sub_data);
  827. break;
  828. case FSE_AZ_SRM_UPD_DONE_EV:
  829. EFX_TRACE(efx, "channel %d SRAM update done\n",
  830. channel->channel);
  831. break;
  832. case FSE_AZ_WAKE_UP_EV:
  833. EFX_TRACE(efx, "channel %d RXQ %d wakeup event\n",
  834. channel->channel, ev_sub_data);
  835. break;
  836. case FSE_AZ_TIMER_EV:
  837. EFX_TRACE(efx, "channel %d RX queue %d timer expired\n",
  838. channel->channel, ev_sub_data);
  839. break;
  840. case FSE_AA_RX_RECOVER_EV:
  841. EFX_ERR(efx, "channel %d seen DRIVER RX_RESET event. "
  842. "Resetting.\n", channel->channel);
  843. atomic_inc(&efx->rx_reset);
  844. efx_schedule_reset(efx,
  845. EFX_WORKAROUND_6555(efx) ?
  846. RESET_TYPE_RX_RECOVERY :
  847. RESET_TYPE_DISABLE);
  848. break;
  849. case FSE_BZ_RX_DSC_ERROR_EV:
  850. EFX_ERR(efx, "RX DMA Q %d reports descriptor fetch error."
  851. " RX Q %d is disabled.\n", ev_sub_data, ev_sub_data);
  852. efx_schedule_reset(efx, RESET_TYPE_RX_DESC_FETCH);
  853. break;
  854. case FSE_BZ_TX_DSC_ERROR_EV:
  855. EFX_ERR(efx, "TX DMA Q %d reports descriptor fetch error."
  856. " TX Q %d is disabled.\n", ev_sub_data, ev_sub_data);
  857. efx_schedule_reset(efx, RESET_TYPE_TX_DESC_FETCH);
  858. break;
  859. default:
  860. EFX_TRACE(efx, "channel %d unknown driver event code %d "
  861. "data %04x\n", channel->channel, ev_sub_code,
  862. ev_sub_data);
  863. break;
  864. }
  865. }
  866. int falcon_process_eventq(struct efx_channel *channel, int rx_quota)
  867. {
  868. unsigned int read_ptr;
  869. efx_qword_t event, *p_event;
  870. int ev_code;
  871. int rx_packets = 0;
  872. read_ptr = channel->eventq_read_ptr;
  873. do {
  874. p_event = falcon_event(channel, read_ptr);
  875. event = *p_event;
  876. if (!falcon_event_present(&event))
  877. /* End of events */
  878. break;
  879. EFX_TRACE(channel->efx, "channel %d event is "EFX_QWORD_FMT"\n",
  880. channel->channel, EFX_QWORD_VAL(event));
  881. /* Clear this event by marking it all ones */
  882. EFX_SET_QWORD(*p_event);
  883. ev_code = EFX_QWORD_FIELD(event, FSF_AZ_EV_CODE);
  884. switch (ev_code) {
  885. case FSE_AZ_EV_CODE_RX_EV:
  886. falcon_handle_rx_event(channel, &event);
  887. ++rx_packets;
  888. break;
  889. case FSE_AZ_EV_CODE_TX_EV:
  890. falcon_handle_tx_event(channel, &event);
  891. break;
  892. case FSE_AZ_EV_CODE_DRV_GEN_EV:
  893. channel->eventq_magic = EFX_QWORD_FIELD(
  894. event, FSF_AZ_DRV_GEN_EV_MAGIC);
  895. EFX_LOG(channel->efx, "channel %d received generated "
  896. "event "EFX_QWORD_FMT"\n", channel->channel,
  897. EFX_QWORD_VAL(event));
  898. break;
  899. case FSE_AZ_EV_CODE_GLOBAL_EV:
  900. falcon_handle_global_event(channel, &event);
  901. break;
  902. case FSE_AZ_EV_CODE_DRIVER_EV:
  903. falcon_handle_driver_event(channel, &event);
  904. break;
  905. default:
  906. EFX_ERR(channel->efx, "channel %d unknown event type %d"
  907. " (data " EFX_QWORD_FMT ")\n", channel->channel,
  908. ev_code, EFX_QWORD_VAL(event));
  909. }
  910. /* Increment read pointer */
  911. read_ptr = (read_ptr + 1) & EFX_EVQ_MASK;
  912. } while (rx_packets < rx_quota);
  913. channel->eventq_read_ptr = read_ptr;
  914. return rx_packets;
  915. }
  916. void falcon_set_int_moderation(struct efx_channel *channel)
  917. {
  918. efx_dword_t timer_cmd;
  919. struct efx_nic *efx = channel->efx;
  920. /* Set timer register */
  921. if (channel->irq_moderation) {
  922. EFX_POPULATE_DWORD_2(timer_cmd,
  923. FRF_AB_TC_TIMER_MODE,
  924. FFE_BB_TIMER_MODE_INT_HLDOFF,
  925. FRF_AB_TC_TIMER_VAL,
  926. channel->irq_moderation - 1);
  927. } else {
  928. EFX_POPULATE_DWORD_2(timer_cmd,
  929. FRF_AB_TC_TIMER_MODE,
  930. FFE_BB_TIMER_MODE_DIS,
  931. FRF_AB_TC_TIMER_VAL, 0);
  932. }
  933. BUILD_BUG_ON(FR_AA_TIMER_COMMAND_KER != FR_BZ_TIMER_COMMAND_P0);
  934. efx_writed_page_locked(efx, &timer_cmd, FR_BZ_TIMER_COMMAND_P0,
  935. channel->channel);
  936. }
  937. /* Allocate buffer table entries for event queue */
  938. int falcon_probe_eventq(struct efx_channel *channel)
  939. {
  940. struct efx_nic *efx = channel->efx;
  941. BUILD_BUG_ON(EFX_EVQ_SIZE < 512 || EFX_EVQ_SIZE > 32768 ||
  942. EFX_EVQ_SIZE & EFX_EVQ_MASK);
  943. return falcon_alloc_special_buffer(efx, &channel->eventq,
  944. EFX_EVQ_SIZE * sizeof(efx_qword_t));
  945. }
  946. void falcon_init_eventq(struct efx_channel *channel)
  947. {
  948. efx_oword_t evq_ptr;
  949. struct efx_nic *efx = channel->efx;
  950. EFX_LOG(efx, "channel %d event queue in special buffers %d-%d\n",
  951. channel->channel, channel->eventq.index,
  952. channel->eventq.index + channel->eventq.entries - 1);
  953. /* Pin event queue buffer */
  954. falcon_init_special_buffer(efx, &channel->eventq);
  955. /* Fill event queue with all ones (i.e. empty events) */
  956. memset(channel->eventq.addr, 0xff, channel->eventq.len);
  957. /* Push event queue to card */
  958. EFX_POPULATE_OWORD_3(evq_ptr,
  959. FRF_AZ_EVQ_EN, 1,
  960. FRF_AZ_EVQ_SIZE, __ffs(channel->eventq.entries),
  961. FRF_AZ_EVQ_BUF_BASE_ID, channel->eventq.index);
  962. efx_writeo_table(efx, &evq_ptr, efx->type->evq_ptr_tbl_base,
  963. channel->channel);
  964. falcon_set_int_moderation(channel);
  965. }
  966. void falcon_fini_eventq(struct efx_channel *channel)
  967. {
  968. efx_oword_t eventq_ptr;
  969. struct efx_nic *efx = channel->efx;
  970. /* Remove event queue from card */
  971. EFX_ZERO_OWORD(eventq_ptr);
  972. efx_writeo_table(efx, &eventq_ptr, efx->type->evq_ptr_tbl_base,
  973. channel->channel);
  974. /* Unpin event queue */
  975. falcon_fini_special_buffer(efx, &channel->eventq);
  976. }
  977. /* Free buffers backing event queue */
  978. void falcon_remove_eventq(struct efx_channel *channel)
  979. {
  980. falcon_free_special_buffer(channel->efx, &channel->eventq);
  981. }
  982. /* Generates a test event on the event queue. A subsequent call to
  983. * process_eventq() should pick up the event and place the value of
  984. * "magic" into channel->eventq_magic;
  985. */
  986. void falcon_generate_test_event(struct efx_channel *channel, unsigned int magic)
  987. {
  988. efx_qword_t test_event;
  989. EFX_POPULATE_QWORD_2(test_event, FSF_AZ_EV_CODE,
  990. FSE_AZ_EV_CODE_DRV_GEN_EV,
  991. FSF_AZ_DRV_GEN_EV_MAGIC, magic);
  992. falcon_generate_event(channel, &test_event);
  993. }
  994. void falcon_sim_phy_event(struct efx_nic *efx)
  995. {
  996. efx_qword_t phy_event;
  997. EFX_POPULATE_QWORD_1(phy_event, FSF_AZ_EV_CODE,
  998. FSE_AZ_EV_CODE_GLOBAL_EV);
  999. if (EFX_IS10G(efx))
  1000. EFX_SET_QWORD_FIELD(phy_event, FSF_AB_GLB_EV_XG_PHY0_INTR, 1);
  1001. else
  1002. EFX_SET_QWORD_FIELD(phy_event, FSF_AB_GLB_EV_G_PHY0_INTR, 1);
  1003. falcon_generate_event(&efx->channel[0], &phy_event);
  1004. }
  1005. /**************************************************************************
  1006. *
  1007. * Flush handling
  1008. *
  1009. **************************************************************************/
  1010. static void falcon_poll_flush_events(struct efx_nic *efx)
  1011. {
  1012. struct efx_channel *channel = &efx->channel[0];
  1013. struct efx_tx_queue *tx_queue;
  1014. struct efx_rx_queue *rx_queue;
  1015. unsigned int read_ptr = channel->eventq_read_ptr;
  1016. unsigned int end_ptr = (read_ptr - 1) & EFX_EVQ_MASK;
  1017. do {
  1018. efx_qword_t *event = falcon_event(channel, read_ptr);
  1019. int ev_code, ev_sub_code, ev_queue;
  1020. bool ev_failed;
  1021. if (!falcon_event_present(event))
  1022. break;
  1023. ev_code = EFX_QWORD_FIELD(*event, FSF_AZ_EV_CODE);
  1024. ev_sub_code = EFX_QWORD_FIELD(*event,
  1025. FSF_AZ_DRIVER_EV_SUBCODE);
  1026. if (ev_code == FSE_AZ_EV_CODE_DRIVER_EV &&
  1027. ev_sub_code == FSE_AZ_TX_DESCQ_FLS_DONE_EV) {
  1028. ev_queue = EFX_QWORD_FIELD(*event,
  1029. FSF_AZ_DRIVER_EV_SUBDATA);
  1030. if (ev_queue < EFX_TX_QUEUE_COUNT) {
  1031. tx_queue = efx->tx_queue + ev_queue;
  1032. tx_queue->flushed = true;
  1033. }
  1034. } else if (ev_code == FSE_AZ_EV_CODE_DRIVER_EV &&
  1035. ev_sub_code == FSE_AZ_RX_DESCQ_FLS_DONE_EV) {
  1036. ev_queue = EFX_QWORD_FIELD(
  1037. *event, FSF_AZ_DRIVER_EV_RX_DESCQ_ID);
  1038. ev_failed = EFX_QWORD_FIELD(
  1039. *event, FSF_AZ_DRIVER_EV_RX_FLUSH_FAIL);
  1040. if (ev_queue < efx->n_rx_queues) {
  1041. rx_queue = efx->rx_queue + ev_queue;
  1042. /* retry the rx flush */
  1043. if (ev_failed)
  1044. falcon_flush_rx_queue(rx_queue);
  1045. else
  1046. rx_queue->flushed = true;
  1047. }
  1048. }
  1049. read_ptr = (read_ptr + 1) & EFX_EVQ_MASK;
  1050. } while (read_ptr != end_ptr);
  1051. }
  1052. /* Handle tx and rx flushes at the same time, since they run in
  1053. * parallel in the hardware and there's no reason for us to
  1054. * serialise them */
  1055. int falcon_flush_queues(struct efx_nic *efx)
  1056. {
  1057. struct efx_rx_queue *rx_queue;
  1058. struct efx_tx_queue *tx_queue;
  1059. int i;
  1060. bool outstanding;
  1061. /* Issue flush requests */
  1062. efx_for_each_tx_queue(tx_queue, efx) {
  1063. tx_queue->flushed = false;
  1064. falcon_flush_tx_queue(tx_queue);
  1065. }
  1066. efx_for_each_rx_queue(rx_queue, efx) {
  1067. rx_queue->flushed = false;
  1068. falcon_flush_rx_queue(rx_queue);
  1069. }
  1070. /* Poll the evq looking for flush completions. Since we're not pushing
  1071. * any more rx or tx descriptors at this point, we're in no danger of
  1072. * overflowing the evq whilst we wait */
  1073. for (i = 0; i < FALCON_FLUSH_POLL_COUNT; ++i) {
  1074. msleep(FALCON_FLUSH_INTERVAL);
  1075. falcon_poll_flush_events(efx);
  1076. /* Check if every queue has been succesfully flushed */
  1077. outstanding = false;
  1078. efx_for_each_tx_queue(tx_queue, efx)
  1079. outstanding |= !tx_queue->flushed;
  1080. efx_for_each_rx_queue(rx_queue, efx)
  1081. outstanding |= !rx_queue->flushed;
  1082. if (!outstanding)
  1083. return 0;
  1084. }
  1085. /* Mark the queues as all flushed. We're going to return failure
  1086. * leading to a reset, or fake up success anyway. "flushed" now
  1087. * indicates that we tried to flush. */
  1088. efx_for_each_tx_queue(tx_queue, efx) {
  1089. if (!tx_queue->flushed)
  1090. EFX_ERR(efx, "tx queue %d flush command timed out\n",
  1091. tx_queue->queue);
  1092. tx_queue->flushed = true;
  1093. }
  1094. efx_for_each_rx_queue(rx_queue, efx) {
  1095. if (!rx_queue->flushed)
  1096. EFX_ERR(efx, "rx queue %d flush command timed out\n",
  1097. rx_queue->queue);
  1098. rx_queue->flushed = true;
  1099. }
  1100. if (EFX_WORKAROUND_7803(efx))
  1101. return 0;
  1102. return -ETIMEDOUT;
  1103. }
  1104. /**************************************************************************
  1105. *
  1106. * Falcon hardware interrupts
  1107. * The hardware interrupt handler does very little work; all the event
  1108. * queue processing is carried out by per-channel tasklets.
  1109. *
  1110. **************************************************************************/
  1111. /* Enable/disable/generate Falcon interrupts */
  1112. static inline void falcon_interrupts(struct efx_nic *efx, int enabled,
  1113. int force)
  1114. {
  1115. efx_oword_t int_en_reg_ker;
  1116. EFX_POPULATE_OWORD_2(int_en_reg_ker,
  1117. FRF_AZ_KER_INT_KER, force,
  1118. FRF_AZ_DRV_INT_EN_KER, enabled);
  1119. efx_writeo(efx, &int_en_reg_ker, FR_AZ_INT_EN_KER);
  1120. }
  1121. void falcon_enable_interrupts(struct efx_nic *efx)
  1122. {
  1123. efx_oword_t int_adr_reg_ker;
  1124. struct efx_channel *channel;
  1125. EFX_ZERO_OWORD(*((efx_oword_t *) efx->irq_status.addr));
  1126. wmb(); /* Ensure interrupt vector is clear before interrupts enabled */
  1127. /* Program address */
  1128. EFX_POPULATE_OWORD_2(int_adr_reg_ker,
  1129. FRF_AZ_NORM_INT_VEC_DIS_KER,
  1130. EFX_INT_MODE_USE_MSI(efx),
  1131. FRF_AZ_INT_ADR_KER, efx->irq_status.dma_addr);
  1132. efx_writeo(efx, &int_adr_reg_ker, FR_AZ_INT_ADR_KER);
  1133. /* Enable interrupts */
  1134. falcon_interrupts(efx, 1, 0);
  1135. /* Force processing of all the channels to get the EVQ RPTRs up to
  1136. date */
  1137. efx_for_each_channel(channel, efx)
  1138. efx_schedule_channel(channel);
  1139. }
  1140. void falcon_disable_interrupts(struct efx_nic *efx)
  1141. {
  1142. /* Disable interrupts */
  1143. falcon_interrupts(efx, 0, 0);
  1144. }
  1145. /* Generate a Falcon test interrupt
  1146. * Interrupt must already have been enabled, otherwise nasty things
  1147. * may happen.
  1148. */
  1149. void falcon_generate_interrupt(struct efx_nic *efx)
  1150. {
  1151. falcon_interrupts(efx, 1, 1);
  1152. }
  1153. /* Acknowledge a legacy interrupt from Falcon
  1154. *
  1155. * This acknowledges a legacy (not MSI) interrupt via INT_ACK_KER_REG.
  1156. *
  1157. * Due to SFC bug 3706 (silicon revision <=A1) reads can be duplicated in the
  1158. * BIU. Interrupt acknowledge is read sensitive so must write instead
  1159. * (then read to ensure the BIU collector is flushed)
  1160. *
  1161. * NB most hardware supports MSI interrupts
  1162. */
  1163. static inline void falcon_irq_ack_a1(struct efx_nic *efx)
  1164. {
  1165. efx_dword_t reg;
  1166. EFX_POPULATE_DWORD_1(reg, FRF_AA_INT_ACK_KER_FIELD, 0xb7eb7e);
  1167. efx_writed(efx, &reg, FR_AA_INT_ACK_KER);
  1168. efx_readd(efx, &reg, FR_AA_WORK_AROUND_BROKEN_PCI_READS);
  1169. }
  1170. /* Process a fatal interrupt
  1171. * Disable bus mastering ASAP and schedule a reset
  1172. */
  1173. static irqreturn_t falcon_fatal_interrupt(struct efx_nic *efx)
  1174. {
  1175. struct falcon_nic_data *nic_data = efx->nic_data;
  1176. efx_oword_t *int_ker = efx->irq_status.addr;
  1177. efx_oword_t fatal_intr;
  1178. int error, mem_perr;
  1179. efx_reado(efx, &fatal_intr, FR_AZ_FATAL_INTR_KER);
  1180. error = EFX_OWORD_FIELD(fatal_intr, FRF_AZ_FATAL_INTR);
  1181. EFX_ERR(efx, "SYSTEM ERROR " EFX_OWORD_FMT " status "
  1182. EFX_OWORD_FMT ": %s\n", EFX_OWORD_VAL(*int_ker),
  1183. EFX_OWORD_VAL(fatal_intr),
  1184. error ? "disabling bus mastering" : "no recognised error");
  1185. if (error == 0)
  1186. goto out;
  1187. /* If this is a memory parity error dump which blocks are offending */
  1188. mem_perr = EFX_OWORD_FIELD(fatal_intr, FRF_AZ_MEM_PERR_INT_KER);
  1189. if (mem_perr) {
  1190. efx_oword_t reg;
  1191. efx_reado(efx, &reg, FR_AZ_MEM_STAT);
  1192. EFX_ERR(efx, "SYSTEM ERROR: memory parity error "
  1193. EFX_OWORD_FMT "\n", EFX_OWORD_VAL(reg));
  1194. }
  1195. /* Disable both devices */
  1196. pci_clear_master(efx->pci_dev);
  1197. if (FALCON_IS_DUAL_FUNC(efx))
  1198. pci_clear_master(nic_data->pci_dev2);
  1199. falcon_disable_interrupts(efx);
  1200. /* Count errors and reset or disable the NIC accordingly */
  1201. if (efx->int_error_count == 0 ||
  1202. time_after(jiffies, efx->int_error_expire)) {
  1203. efx->int_error_count = 0;
  1204. efx->int_error_expire =
  1205. jiffies + FALCON_INT_ERROR_EXPIRE * HZ;
  1206. }
  1207. if (++efx->int_error_count < FALCON_MAX_INT_ERRORS) {
  1208. EFX_ERR(efx, "SYSTEM ERROR - reset scheduled\n");
  1209. efx_schedule_reset(efx, RESET_TYPE_INT_ERROR);
  1210. } else {
  1211. EFX_ERR(efx, "SYSTEM ERROR - max number of errors seen."
  1212. "NIC will be disabled\n");
  1213. efx_schedule_reset(efx, RESET_TYPE_DISABLE);
  1214. }
  1215. out:
  1216. return IRQ_HANDLED;
  1217. }
  1218. /* Handle a legacy interrupt from Falcon
  1219. * Acknowledges the interrupt and schedule event queue processing.
  1220. */
  1221. static irqreturn_t falcon_legacy_interrupt_b0(int irq, void *dev_id)
  1222. {
  1223. struct efx_nic *efx = dev_id;
  1224. efx_oword_t *int_ker = efx->irq_status.addr;
  1225. irqreturn_t result = IRQ_NONE;
  1226. struct efx_channel *channel;
  1227. efx_dword_t reg;
  1228. u32 queues;
  1229. int syserr;
  1230. /* Read the ISR which also ACKs the interrupts */
  1231. efx_readd(efx, &reg, FR_BZ_INT_ISR0);
  1232. queues = EFX_EXTRACT_DWORD(reg, 0, 31);
  1233. /* Check to see if we have a serious error condition */
  1234. syserr = EFX_OWORD_FIELD(*int_ker, FSF_AZ_NET_IVEC_FATAL_INT);
  1235. if (unlikely(syserr))
  1236. return falcon_fatal_interrupt(efx);
  1237. /* Schedule processing of any interrupting queues */
  1238. efx_for_each_channel(channel, efx) {
  1239. if ((queues & 1) ||
  1240. falcon_event_present(
  1241. falcon_event(channel, channel->eventq_read_ptr))) {
  1242. efx_schedule_channel(channel);
  1243. result = IRQ_HANDLED;
  1244. }
  1245. queues >>= 1;
  1246. }
  1247. if (result == IRQ_HANDLED) {
  1248. efx->last_irq_cpu = raw_smp_processor_id();
  1249. EFX_TRACE(efx, "IRQ %d on CPU %d status " EFX_DWORD_FMT "\n",
  1250. irq, raw_smp_processor_id(), EFX_DWORD_VAL(reg));
  1251. }
  1252. return result;
  1253. }
  1254. static irqreturn_t falcon_legacy_interrupt_a1(int irq, void *dev_id)
  1255. {
  1256. struct efx_nic *efx = dev_id;
  1257. efx_oword_t *int_ker = efx->irq_status.addr;
  1258. struct efx_channel *channel;
  1259. int syserr;
  1260. int queues;
  1261. /* Check to see if this is our interrupt. If it isn't, we
  1262. * exit without having touched the hardware.
  1263. */
  1264. if (unlikely(EFX_OWORD_IS_ZERO(*int_ker))) {
  1265. EFX_TRACE(efx, "IRQ %d on CPU %d not for me\n", irq,
  1266. raw_smp_processor_id());
  1267. return IRQ_NONE;
  1268. }
  1269. efx->last_irq_cpu = raw_smp_processor_id();
  1270. EFX_TRACE(efx, "IRQ %d on CPU %d status " EFX_OWORD_FMT "\n",
  1271. irq, raw_smp_processor_id(), EFX_OWORD_VAL(*int_ker));
  1272. /* Check to see if we have a serious error condition */
  1273. syserr = EFX_OWORD_FIELD(*int_ker, FSF_AZ_NET_IVEC_FATAL_INT);
  1274. if (unlikely(syserr))
  1275. return falcon_fatal_interrupt(efx);
  1276. /* Determine interrupting queues, clear interrupt status
  1277. * register and acknowledge the device interrupt.
  1278. */
  1279. BUILD_BUG_ON(INT_EVQS_WIDTH > EFX_MAX_CHANNELS);
  1280. queues = EFX_OWORD_FIELD(*int_ker, INT_EVQS);
  1281. EFX_ZERO_OWORD(*int_ker);
  1282. wmb(); /* Ensure the vector is cleared before interrupt ack */
  1283. falcon_irq_ack_a1(efx);
  1284. /* Schedule processing of any interrupting queues */
  1285. channel = &efx->channel[0];
  1286. while (queues) {
  1287. if (queues & 0x01)
  1288. efx_schedule_channel(channel);
  1289. channel++;
  1290. queues >>= 1;
  1291. }
  1292. return IRQ_HANDLED;
  1293. }
  1294. /* Handle an MSI interrupt from Falcon
  1295. *
  1296. * Handle an MSI hardware interrupt. This routine schedules event
  1297. * queue processing. No interrupt acknowledgement cycle is necessary.
  1298. * Also, we never need to check that the interrupt is for us, since
  1299. * MSI interrupts cannot be shared.
  1300. */
  1301. static irqreturn_t falcon_msi_interrupt(int irq, void *dev_id)
  1302. {
  1303. struct efx_channel *channel = dev_id;
  1304. struct efx_nic *efx = channel->efx;
  1305. efx_oword_t *int_ker = efx->irq_status.addr;
  1306. int syserr;
  1307. efx->last_irq_cpu = raw_smp_processor_id();
  1308. EFX_TRACE(efx, "IRQ %d on CPU %d status " EFX_OWORD_FMT "\n",
  1309. irq, raw_smp_processor_id(), EFX_OWORD_VAL(*int_ker));
  1310. /* Check to see if we have a serious error condition */
  1311. syserr = EFX_OWORD_FIELD(*int_ker, FATAL_INT);
  1312. if (unlikely(syserr))
  1313. return falcon_fatal_interrupt(efx);
  1314. /* Schedule processing of the channel */
  1315. efx_schedule_channel(channel);
  1316. return IRQ_HANDLED;
  1317. }
  1318. /* Setup RSS indirection table.
  1319. * This maps from the hash value of the packet to RXQ
  1320. */
  1321. static void falcon_setup_rss_indir_table(struct efx_nic *efx)
  1322. {
  1323. int i = 0;
  1324. unsigned long offset;
  1325. efx_dword_t dword;
  1326. if (falcon_rev(efx) < FALCON_REV_B0)
  1327. return;
  1328. for (offset = FR_BZ_RX_INDIRECTION_TBL;
  1329. offset < FR_BZ_RX_INDIRECTION_TBL + 0x800;
  1330. offset += 0x10) {
  1331. EFX_POPULATE_DWORD_1(dword, FRF_BZ_IT_QUEUE,
  1332. i % efx->n_rx_queues);
  1333. efx_writed(efx, &dword, offset);
  1334. i++;
  1335. }
  1336. }
  1337. /* Hook interrupt handler(s)
  1338. * Try MSI and then legacy interrupts.
  1339. */
  1340. int falcon_init_interrupt(struct efx_nic *efx)
  1341. {
  1342. struct efx_channel *channel;
  1343. int rc;
  1344. if (!EFX_INT_MODE_USE_MSI(efx)) {
  1345. irq_handler_t handler;
  1346. if (falcon_rev(efx) >= FALCON_REV_B0)
  1347. handler = falcon_legacy_interrupt_b0;
  1348. else
  1349. handler = falcon_legacy_interrupt_a1;
  1350. rc = request_irq(efx->legacy_irq, handler, IRQF_SHARED,
  1351. efx->name, efx);
  1352. if (rc) {
  1353. EFX_ERR(efx, "failed to hook legacy IRQ %d\n",
  1354. efx->pci_dev->irq);
  1355. goto fail1;
  1356. }
  1357. return 0;
  1358. }
  1359. /* Hook MSI or MSI-X interrupt */
  1360. efx_for_each_channel(channel, efx) {
  1361. rc = request_irq(channel->irq, falcon_msi_interrupt,
  1362. IRQF_PROBE_SHARED, /* Not shared */
  1363. channel->name, channel);
  1364. if (rc) {
  1365. EFX_ERR(efx, "failed to hook IRQ %d\n", channel->irq);
  1366. goto fail2;
  1367. }
  1368. }
  1369. return 0;
  1370. fail2:
  1371. efx_for_each_channel(channel, efx)
  1372. free_irq(channel->irq, channel);
  1373. fail1:
  1374. return rc;
  1375. }
  1376. void falcon_fini_interrupt(struct efx_nic *efx)
  1377. {
  1378. struct efx_channel *channel;
  1379. efx_oword_t reg;
  1380. /* Disable MSI/MSI-X interrupts */
  1381. efx_for_each_channel(channel, efx) {
  1382. if (channel->irq)
  1383. free_irq(channel->irq, channel);
  1384. }
  1385. /* ACK legacy interrupt */
  1386. if (falcon_rev(efx) >= FALCON_REV_B0)
  1387. efx_reado(efx, &reg, FR_BZ_INT_ISR0);
  1388. else
  1389. falcon_irq_ack_a1(efx);
  1390. /* Disable legacy interrupt */
  1391. if (efx->legacy_irq)
  1392. free_irq(efx->legacy_irq, efx);
  1393. }
  1394. /**************************************************************************
  1395. *
  1396. * EEPROM/flash
  1397. *
  1398. **************************************************************************
  1399. */
  1400. #define FALCON_SPI_MAX_LEN sizeof(efx_oword_t)
  1401. static int falcon_spi_poll(struct efx_nic *efx)
  1402. {
  1403. efx_oword_t reg;
  1404. efx_reado(efx, &reg, FR_AB_EE_SPI_HCMD);
  1405. return EFX_OWORD_FIELD(reg, FRF_AB_EE_SPI_HCMD_CMD_EN) ? -EBUSY : 0;
  1406. }
  1407. /* Wait for SPI command completion */
  1408. static int falcon_spi_wait(struct efx_nic *efx)
  1409. {
  1410. /* Most commands will finish quickly, so we start polling at
  1411. * very short intervals. Sometimes the command may have to
  1412. * wait for VPD or expansion ROM access outside of our
  1413. * control, so we allow up to 100 ms. */
  1414. unsigned long timeout = jiffies + 1 + DIV_ROUND_UP(HZ, 10);
  1415. int i;
  1416. for (i = 0; i < 10; i++) {
  1417. if (!falcon_spi_poll(efx))
  1418. return 0;
  1419. udelay(10);
  1420. }
  1421. for (;;) {
  1422. if (!falcon_spi_poll(efx))
  1423. return 0;
  1424. if (time_after_eq(jiffies, timeout)) {
  1425. EFX_ERR(efx, "timed out waiting for SPI\n");
  1426. return -ETIMEDOUT;
  1427. }
  1428. schedule_timeout_uninterruptible(1);
  1429. }
  1430. }
  1431. int falcon_spi_cmd(const struct efx_spi_device *spi,
  1432. unsigned int command, int address,
  1433. const void *in, void *out, size_t len)
  1434. {
  1435. struct efx_nic *efx = spi->efx;
  1436. bool addressed = (address >= 0);
  1437. bool reading = (out != NULL);
  1438. efx_oword_t reg;
  1439. int rc;
  1440. /* Input validation */
  1441. if (len > FALCON_SPI_MAX_LEN)
  1442. return -EINVAL;
  1443. BUG_ON(!mutex_is_locked(&efx->spi_lock));
  1444. /* Check that previous command is not still running */
  1445. rc = falcon_spi_poll(efx);
  1446. if (rc)
  1447. return rc;
  1448. /* Program address register, if we have an address */
  1449. if (addressed) {
  1450. EFX_POPULATE_OWORD_1(reg, FRF_AB_EE_SPI_HADR_ADR, address);
  1451. efx_writeo(efx, &reg, FR_AB_EE_SPI_HADR);
  1452. }
  1453. /* Program data register, if we have data */
  1454. if (in != NULL) {
  1455. memcpy(&reg, in, len);
  1456. efx_writeo(efx, &reg, FR_AB_EE_SPI_HDATA);
  1457. }
  1458. /* Issue read/write command */
  1459. EFX_POPULATE_OWORD_7(reg,
  1460. FRF_AB_EE_SPI_HCMD_CMD_EN, 1,
  1461. FRF_AB_EE_SPI_HCMD_SF_SEL, spi->device_id,
  1462. FRF_AB_EE_SPI_HCMD_DABCNT, len,
  1463. FRF_AB_EE_SPI_HCMD_READ, reading,
  1464. FRF_AB_EE_SPI_HCMD_DUBCNT, 0,
  1465. FRF_AB_EE_SPI_HCMD_ADBCNT,
  1466. (addressed ? spi->addr_len : 0),
  1467. FRF_AB_EE_SPI_HCMD_ENC, command);
  1468. efx_writeo(efx, &reg, FR_AB_EE_SPI_HCMD);
  1469. /* Wait for read/write to complete */
  1470. rc = falcon_spi_wait(efx);
  1471. if (rc)
  1472. return rc;
  1473. /* Read data */
  1474. if (out != NULL) {
  1475. efx_reado(efx, &reg, FR_AB_EE_SPI_HDATA);
  1476. memcpy(out, &reg, len);
  1477. }
  1478. return 0;
  1479. }
  1480. static size_t
  1481. falcon_spi_write_limit(const struct efx_spi_device *spi, size_t start)
  1482. {
  1483. return min(FALCON_SPI_MAX_LEN,
  1484. (spi->block_size - (start & (spi->block_size - 1))));
  1485. }
  1486. static inline u8
  1487. efx_spi_munge_command(const struct efx_spi_device *spi,
  1488. const u8 command, const unsigned int address)
  1489. {
  1490. return command | (((address >> 8) & spi->munge_address) << 3);
  1491. }
  1492. /* Wait up to 10 ms for buffered write completion */
  1493. int falcon_spi_wait_write(const struct efx_spi_device *spi)
  1494. {
  1495. struct efx_nic *efx = spi->efx;
  1496. unsigned long timeout = jiffies + 1 + DIV_ROUND_UP(HZ, 100);
  1497. u8 status;
  1498. int rc;
  1499. for (;;) {
  1500. rc = falcon_spi_cmd(spi, SPI_RDSR, -1, NULL,
  1501. &status, sizeof(status));
  1502. if (rc)
  1503. return rc;
  1504. if (!(status & SPI_STATUS_NRDY))
  1505. return 0;
  1506. if (time_after_eq(jiffies, timeout)) {
  1507. EFX_ERR(efx, "SPI write timeout on device %d"
  1508. " last status=0x%02x\n",
  1509. spi->device_id, status);
  1510. return -ETIMEDOUT;
  1511. }
  1512. schedule_timeout_uninterruptible(1);
  1513. }
  1514. }
  1515. int falcon_spi_read(const struct efx_spi_device *spi, loff_t start,
  1516. size_t len, size_t *retlen, u8 *buffer)
  1517. {
  1518. size_t block_len, pos = 0;
  1519. unsigned int command;
  1520. int rc = 0;
  1521. while (pos < len) {
  1522. block_len = min(len - pos, FALCON_SPI_MAX_LEN);
  1523. command = efx_spi_munge_command(spi, SPI_READ, start + pos);
  1524. rc = falcon_spi_cmd(spi, command, start + pos, NULL,
  1525. buffer + pos, block_len);
  1526. if (rc)
  1527. break;
  1528. pos += block_len;
  1529. /* Avoid locking up the system */
  1530. cond_resched();
  1531. if (signal_pending(current)) {
  1532. rc = -EINTR;
  1533. break;
  1534. }
  1535. }
  1536. if (retlen)
  1537. *retlen = pos;
  1538. return rc;
  1539. }
  1540. int falcon_spi_write(const struct efx_spi_device *spi, loff_t start,
  1541. size_t len, size_t *retlen, const u8 *buffer)
  1542. {
  1543. u8 verify_buffer[FALCON_SPI_MAX_LEN];
  1544. size_t block_len, pos = 0;
  1545. unsigned int command;
  1546. int rc = 0;
  1547. while (pos < len) {
  1548. rc = falcon_spi_cmd(spi, SPI_WREN, -1, NULL, NULL, 0);
  1549. if (rc)
  1550. break;
  1551. block_len = min(len - pos,
  1552. falcon_spi_write_limit(spi, start + pos));
  1553. command = efx_spi_munge_command(spi, SPI_WRITE, start + pos);
  1554. rc = falcon_spi_cmd(spi, command, start + pos,
  1555. buffer + pos, NULL, block_len);
  1556. if (rc)
  1557. break;
  1558. rc = falcon_spi_wait_write(spi);
  1559. if (rc)
  1560. break;
  1561. command = efx_spi_munge_command(spi, SPI_READ, start + pos);
  1562. rc = falcon_spi_cmd(spi, command, start + pos,
  1563. NULL, verify_buffer, block_len);
  1564. if (memcmp(verify_buffer, buffer + pos, block_len)) {
  1565. rc = -EIO;
  1566. break;
  1567. }
  1568. pos += block_len;
  1569. /* Avoid locking up the system */
  1570. cond_resched();
  1571. if (signal_pending(current)) {
  1572. rc = -EINTR;
  1573. break;
  1574. }
  1575. }
  1576. if (retlen)
  1577. *retlen = pos;
  1578. return rc;
  1579. }
  1580. /**************************************************************************
  1581. *
  1582. * MAC wrapper
  1583. *
  1584. **************************************************************************
  1585. */
  1586. static int falcon_reset_macs(struct efx_nic *efx)
  1587. {
  1588. efx_oword_t reg;
  1589. int count;
  1590. if (falcon_rev(efx) < FALCON_REV_B0) {
  1591. /* It's not safe to use GLB_CTL_REG to reset the
  1592. * macs, so instead use the internal MAC resets
  1593. */
  1594. if (!EFX_IS10G(efx)) {
  1595. EFX_POPULATE_OWORD_1(reg, FRF_AB_GM_SW_RST, 1);
  1596. efx_writeo(efx, &reg, FR_AB_GM_CFG1);
  1597. udelay(1000);
  1598. EFX_POPULATE_OWORD_1(reg, FRF_AB_GM_SW_RST, 0);
  1599. efx_writeo(efx, &reg, FR_AB_GM_CFG1);
  1600. udelay(1000);
  1601. return 0;
  1602. } else {
  1603. EFX_POPULATE_OWORD_1(reg, FRF_AB_XM_CORE_RST, 1);
  1604. efx_writeo(efx, &reg, FR_AB_XM_GLB_CFG);
  1605. for (count = 0; count < 10000; count++) {
  1606. efx_reado(efx, &reg, FR_AB_XM_GLB_CFG);
  1607. if (EFX_OWORD_FIELD(reg, FRF_AB_XM_CORE_RST) ==
  1608. 0)
  1609. return 0;
  1610. udelay(10);
  1611. }
  1612. EFX_ERR(efx, "timed out waiting for XMAC core reset\n");
  1613. return -ETIMEDOUT;
  1614. }
  1615. }
  1616. /* MAC stats will fail whilst the TX fifo is draining. Serialise
  1617. * the drain sequence with the statistics fetch */
  1618. efx_stats_disable(efx);
  1619. efx_reado(efx, &reg, FR_AB_MAC_CTRL);
  1620. EFX_SET_OWORD_FIELD(reg, FRF_BB_TXFIFO_DRAIN_EN, 1);
  1621. efx_writeo(efx, &reg, FR_AB_MAC_CTRL);
  1622. efx_reado(efx, &reg, FR_AB_GLB_CTL);
  1623. EFX_SET_OWORD_FIELD(reg, FRF_AB_RST_XGTX, 1);
  1624. EFX_SET_OWORD_FIELD(reg, FRF_AB_RST_XGRX, 1);
  1625. EFX_SET_OWORD_FIELD(reg, FRF_AB_RST_EM, 1);
  1626. efx_writeo(efx, &reg, FR_AB_GLB_CTL);
  1627. count = 0;
  1628. while (1) {
  1629. efx_reado(efx, &reg, FR_AB_GLB_CTL);
  1630. if (!EFX_OWORD_FIELD(reg, FRF_AB_RST_XGTX) &&
  1631. !EFX_OWORD_FIELD(reg, FRF_AB_RST_XGRX) &&
  1632. !EFX_OWORD_FIELD(reg, FRF_AB_RST_EM)) {
  1633. EFX_LOG(efx, "Completed MAC reset after %d loops\n",
  1634. count);
  1635. break;
  1636. }
  1637. if (count > 20) {
  1638. EFX_ERR(efx, "MAC reset failed\n");
  1639. break;
  1640. }
  1641. count++;
  1642. udelay(10);
  1643. }
  1644. efx_stats_enable(efx);
  1645. /* If we've reset the EM block and the link is up, then
  1646. * we'll have to kick the XAUI link so the PHY can recover */
  1647. if (efx->link_up && EFX_IS10G(efx) && EFX_WORKAROUND_5147(efx))
  1648. falcon_reset_xaui(efx);
  1649. return 0;
  1650. }
  1651. void falcon_drain_tx_fifo(struct efx_nic *efx)
  1652. {
  1653. efx_oword_t reg;
  1654. if ((falcon_rev(efx) < FALCON_REV_B0) ||
  1655. (efx->loopback_mode != LOOPBACK_NONE))
  1656. return;
  1657. efx_reado(efx, &reg, FR_AB_MAC_CTRL);
  1658. /* There is no point in draining more than once */
  1659. if (EFX_OWORD_FIELD(reg, FRF_BB_TXFIFO_DRAIN_EN))
  1660. return;
  1661. falcon_reset_macs(efx);
  1662. }
  1663. void falcon_deconfigure_mac_wrapper(struct efx_nic *efx)
  1664. {
  1665. efx_oword_t reg;
  1666. if (falcon_rev(efx) < FALCON_REV_B0)
  1667. return;
  1668. /* Isolate the MAC -> RX */
  1669. efx_reado(efx, &reg, FR_AZ_RX_CFG);
  1670. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_INGR_EN, 0);
  1671. efx_writeo(efx, &reg, FR_AZ_RX_CFG);
  1672. if (!efx->link_up)
  1673. falcon_drain_tx_fifo(efx);
  1674. }
  1675. void falcon_reconfigure_mac_wrapper(struct efx_nic *efx)
  1676. {
  1677. efx_oword_t reg;
  1678. int link_speed;
  1679. bool tx_fc;
  1680. switch (efx->link_speed) {
  1681. case 10000: link_speed = 3; break;
  1682. case 1000: link_speed = 2; break;
  1683. case 100: link_speed = 1; break;
  1684. default: link_speed = 0; break;
  1685. }
  1686. /* MAC_LINK_STATUS controls MAC backpressure but doesn't work
  1687. * as advertised. Disable to ensure packets are not
  1688. * indefinitely held and TX queue can be flushed at any point
  1689. * while the link is down. */
  1690. EFX_POPULATE_OWORD_5(reg,
  1691. FRF_AB_MAC_XOFF_VAL, 0xffff /* max pause time */,
  1692. FRF_AB_MAC_BCAD_ACPT, 1,
  1693. FRF_AB_MAC_UC_PROM, efx->promiscuous,
  1694. FRF_AB_MAC_LINK_STATUS, 1, /* always set */
  1695. FRF_AB_MAC_SPEED, link_speed);
  1696. /* On B0, MAC backpressure can be disabled and packets get
  1697. * discarded. */
  1698. if (falcon_rev(efx) >= FALCON_REV_B0) {
  1699. EFX_SET_OWORD_FIELD(reg, FRF_BB_TXFIFO_DRAIN_EN,
  1700. !efx->link_up);
  1701. }
  1702. efx_writeo(efx, &reg, FR_AB_MAC_CTRL);
  1703. /* Restore the multicast hash registers. */
  1704. falcon_set_multicast_hash(efx);
  1705. /* Transmission of pause frames when RX crosses the threshold is
  1706. * covered by RX_XOFF_MAC_EN and XM_TX_CFG_REG:XM_FCNTL.
  1707. * Action on receipt of pause frames is controller by XM_DIS_FCNTL */
  1708. tx_fc = !!(efx->link_fc & EFX_FC_TX);
  1709. efx_reado(efx, &reg, FR_AZ_RX_CFG);
  1710. EFX_SET_OWORD_FIELD(reg, FRF_AZ_RX_XOFF_MAC_EN, tx_fc);
  1711. /* Unisolate the MAC -> RX */
  1712. if (falcon_rev(efx) >= FALCON_REV_B0)
  1713. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_INGR_EN, 1);
  1714. efx_writeo(efx, &reg, FR_AZ_RX_CFG);
  1715. }
  1716. int falcon_dma_stats(struct efx_nic *efx, unsigned int done_offset)
  1717. {
  1718. efx_oword_t reg;
  1719. u32 *dma_done;
  1720. int i;
  1721. if (disable_dma_stats)
  1722. return 0;
  1723. /* Statistics fetch will fail if the MAC is in TX drain */
  1724. if (falcon_rev(efx) >= FALCON_REV_B0) {
  1725. efx_oword_t temp;
  1726. efx_reado(efx, &temp, FR_AB_MAC_CTRL);
  1727. if (EFX_OWORD_FIELD(temp, FRF_BB_TXFIFO_DRAIN_EN))
  1728. return 0;
  1729. }
  1730. dma_done = (efx->stats_buffer.addr + done_offset);
  1731. *dma_done = FALCON_STATS_NOT_DONE;
  1732. wmb(); /* ensure done flag is clear */
  1733. /* Initiate DMA transfer of stats */
  1734. EFX_POPULATE_OWORD_2(reg,
  1735. FRF_AB_MAC_STAT_DMA_CMD, 1,
  1736. FRF_AB_MAC_STAT_DMA_ADR,
  1737. efx->stats_buffer.dma_addr);
  1738. efx_writeo(efx, &reg, FR_AB_MAC_STAT_DMA);
  1739. /* Wait for transfer to complete */
  1740. for (i = 0; i < 400; i++) {
  1741. if (*(volatile u32 *)dma_done == FALCON_STATS_DONE) {
  1742. rmb(); /* Ensure the stats are valid. */
  1743. return 0;
  1744. }
  1745. udelay(10);
  1746. }
  1747. EFX_ERR(efx, "timed out waiting for statistics\n");
  1748. return -ETIMEDOUT;
  1749. }
  1750. /**************************************************************************
  1751. *
  1752. * PHY access via GMII
  1753. *
  1754. **************************************************************************
  1755. */
  1756. /* Wait for GMII access to complete */
  1757. static int falcon_gmii_wait(struct efx_nic *efx)
  1758. {
  1759. efx_dword_t md_stat;
  1760. int count;
  1761. /* wait upto 50ms - taken max from datasheet */
  1762. for (count = 0; count < 5000; count++) {
  1763. efx_readd(efx, &md_stat, FR_AB_MD_STAT);
  1764. if (EFX_DWORD_FIELD(md_stat, FRF_AB_MD_BSY) == 0) {
  1765. if (EFX_DWORD_FIELD(md_stat, FRF_AB_MD_LNFL) != 0 ||
  1766. EFX_DWORD_FIELD(md_stat, FRF_AB_MD_BSERR) != 0) {
  1767. EFX_ERR(efx, "error from GMII access "
  1768. EFX_DWORD_FMT"\n",
  1769. EFX_DWORD_VAL(md_stat));
  1770. return -EIO;
  1771. }
  1772. return 0;
  1773. }
  1774. udelay(10);
  1775. }
  1776. EFX_ERR(efx, "timed out waiting for GMII\n");
  1777. return -ETIMEDOUT;
  1778. }
  1779. /* Write an MDIO register of a PHY connected to Falcon. */
  1780. static int falcon_mdio_write(struct net_device *net_dev,
  1781. int prtad, int devad, u16 addr, u16 value)
  1782. {
  1783. struct efx_nic *efx = netdev_priv(net_dev);
  1784. efx_oword_t reg;
  1785. int rc;
  1786. EFX_REGDUMP(efx, "writing MDIO %d register %d.%d with 0x%04x\n",
  1787. prtad, devad, addr, value);
  1788. spin_lock_bh(&efx->phy_lock);
  1789. /* Check MDIO not currently being accessed */
  1790. rc = falcon_gmii_wait(efx);
  1791. if (rc)
  1792. goto out;
  1793. /* Write the address/ID register */
  1794. EFX_POPULATE_OWORD_1(reg, FRF_AB_MD_PHY_ADR, addr);
  1795. efx_writeo(efx, &reg, FR_AB_MD_PHY_ADR);
  1796. EFX_POPULATE_OWORD_2(reg, FRF_AB_MD_PRT_ADR, prtad,
  1797. FRF_AB_MD_DEV_ADR, devad);
  1798. efx_writeo(efx, &reg, FR_AB_MD_ID);
  1799. /* Write data */
  1800. EFX_POPULATE_OWORD_1(reg, FRF_AB_MD_TXD, value);
  1801. efx_writeo(efx, &reg, FR_AB_MD_TXD);
  1802. EFX_POPULATE_OWORD_2(reg,
  1803. FRF_AB_MD_WRC, 1,
  1804. FRF_AB_MD_GC, 0);
  1805. efx_writeo(efx, &reg, FR_AB_MD_CS);
  1806. /* Wait for data to be written */
  1807. rc = falcon_gmii_wait(efx);
  1808. if (rc) {
  1809. /* Abort the write operation */
  1810. EFX_POPULATE_OWORD_2(reg,
  1811. FRF_AB_MD_WRC, 0,
  1812. FRF_AB_MD_GC, 1);
  1813. efx_writeo(efx, &reg, FR_AB_MD_CS);
  1814. udelay(10);
  1815. }
  1816. out:
  1817. spin_unlock_bh(&efx->phy_lock);
  1818. return rc;
  1819. }
  1820. /* Read an MDIO register of a PHY connected to Falcon. */
  1821. static int falcon_mdio_read(struct net_device *net_dev,
  1822. int prtad, int devad, u16 addr)
  1823. {
  1824. struct efx_nic *efx = netdev_priv(net_dev);
  1825. efx_oword_t reg;
  1826. int rc;
  1827. spin_lock_bh(&efx->phy_lock);
  1828. /* Check MDIO not currently being accessed */
  1829. rc = falcon_gmii_wait(efx);
  1830. if (rc)
  1831. goto out;
  1832. EFX_POPULATE_OWORD_1(reg, FRF_AB_MD_PHY_ADR, addr);
  1833. efx_writeo(efx, &reg, FR_AB_MD_PHY_ADR);
  1834. EFX_POPULATE_OWORD_2(reg, FRF_AB_MD_PRT_ADR, prtad,
  1835. FRF_AB_MD_DEV_ADR, devad);
  1836. efx_writeo(efx, &reg, FR_AB_MD_ID);
  1837. /* Request data to be read */
  1838. EFX_POPULATE_OWORD_2(reg, FRF_AB_MD_RDC, 1, FRF_AB_MD_GC, 0);
  1839. efx_writeo(efx, &reg, FR_AB_MD_CS);
  1840. /* Wait for data to become available */
  1841. rc = falcon_gmii_wait(efx);
  1842. if (rc == 0) {
  1843. efx_reado(efx, &reg, FR_AB_MD_RXD);
  1844. rc = EFX_OWORD_FIELD(reg, FRF_AB_MD_RXD);
  1845. EFX_REGDUMP(efx, "read from MDIO %d register %d.%d, got %04x\n",
  1846. prtad, devad, addr, rc);
  1847. } else {
  1848. /* Abort the read operation */
  1849. EFX_POPULATE_OWORD_2(reg,
  1850. FRF_AB_MD_RIC, 0,
  1851. FRF_AB_MD_GC, 1);
  1852. efx_writeo(efx, &reg, FR_AB_MD_CS);
  1853. EFX_LOG(efx, "read from MDIO %d register %d.%d, got error %d\n",
  1854. prtad, devad, addr, rc);
  1855. }
  1856. out:
  1857. spin_unlock_bh(&efx->phy_lock);
  1858. return rc;
  1859. }
  1860. int falcon_switch_mac(struct efx_nic *efx)
  1861. {
  1862. struct efx_mac_operations *old_mac_op = efx->mac_op;
  1863. efx_oword_t nic_stat;
  1864. unsigned strap_val;
  1865. int rc = 0;
  1866. /* Don't try to fetch MAC stats while we're switching MACs */
  1867. efx_stats_disable(efx);
  1868. /* Internal loopbacks override the phy speed setting */
  1869. if (efx->loopback_mode == LOOPBACK_GMAC) {
  1870. efx->link_speed = 1000;
  1871. efx->link_fd = true;
  1872. } else if (LOOPBACK_INTERNAL(efx)) {
  1873. efx->link_speed = 10000;
  1874. efx->link_fd = true;
  1875. }
  1876. WARN_ON(!mutex_is_locked(&efx->mac_lock));
  1877. efx->mac_op = (EFX_IS10G(efx) ?
  1878. &falcon_xmac_operations : &falcon_gmac_operations);
  1879. /* Always push the NIC_STAT_REG setting even if the mac hasn't
  1880. * changed, because this function is run post online reset */
  1881. efx_reado(efx, &nic_stat, FR_AB_NIC_STAT);
  1882. strap_val = EFX_IS10G(efx) ? 5 : 3;
  1883. if (falcon_rev(efx) >= FALCON_REV_B0) {
  1884. EFX_SET_OWORD_FIELD(nic_stat, FRF_BB_EE_STRAP_EN, 1);
  1885. EFX_SET_OWORD_FIELD(nic_stat, FRF_BB_EE_STRAP, strap_val);
  1886. efx_writeo(efx, &nic_stat, FR_AB_NIC_STAT);
  1887. } else {
  1888. /* Falcon A1 does not support 1G/10G speed switching
  1889. * and must not be used with a PHY that does. */
  1890. BUG_ON(EFX_OWORD_FIELD(nic_stat, FRF_AB_STRAP_PINS) !=
  1891. strap_val);
  1892. }
  1893. if (old_mac_op == efx->mac_op)
  1894. goto out;
  1895. EFX_LOG(efx, "selected %cMAC\n", EFX_IS10G(efx) ? 'X' : 'G');
  1896. /* Not all macs support a mac-level link state */
  1897. efx->mac_up = true;
  1898. rc = falcon_reset_macs(efx);
  1899. out:
  1900. efx_stats_enable(efx);
  1901. return rc;
  1902. }
  1903. /* This call is responsible for hooking in the MAC and PHY operations */
  1904. int falcon_probe_port(struct efx_nic *efx)
  1905. {
  1906. int rc;
  1907. switch (efx->phy_type) {
  1908. case PHY_TYPE_SFX7101:
  1909. efx->phy_op = &falcon_sfx7101_phy_ops;
  1910. break;
  1911. case PHY_TYPE_SFT9001A:
  1912. case PHY_TYPE_SFT9001B:
  1913. efx->phy_op = &falcon_sft9001_phy_ops;
  1914. break;
  1915. case PHY_TYPE_QT2022C2:
  1916. case PHY_TYPE_QT2025C:
  1917. efx->phy_op = &falcon_qt202x_phy_ops;
  1918. break;
  1919. default:
  1920. EFX_ERR(efx, "Unknown PHY type %d\n",
  1921. efx->phy_type);
  1922. return -ENODEV;
  1923. }
  1924. if (efx->phy_op->macs & EFX_XMAC)
  1925. efx->loopback_modes |= ((1 << LOOPBACK_XGMII) |
  1926. (1 << LOOPBACK_XGXS) |
  1927. (1 << LOOPBACK_XAUI));
  1928. if (efx->phy_op->macs & EFX_GMAC)
  1929. efx->loopback_modes |= (1 << LOOPBACK_GMAC);
  1930. efx->loopback_modes |= efx->phy_op->loopbacks;
  1931. /* Set up MDIO structure for PHY */
  1932. efx->mdio.mmds = efx->phy_op->mmds;
  1933. efx->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  1934. efx->mdio.mdio_read = falcon_mdio_read;
  1935. efx->mdio.mdio_write = falcon_mdio_write;
  1936. /* Hardware flow ctrl. FalconA RX FIFO too small for pause generation */
  1937. if (falcon_rev(efx) >= FALCON_REV_B0)
  1938. efx->wanted_fc = EFX_FC_RX | EFX_FC_TX;
  1939. else
  1940. efx->wanted_fc = EFX_FC_RX;
  1941. /* Allocate buffer for stats */
  1942. rc = falcon_alloc_buffer(efx, &efx->stats_buffer,
  1943. FALCON_MAC_STATS_SIZE);
  1944. if (rc)
  1945. return rc;
  1946. EFX_LOG(efx, "stats buffer at %llx (virt %p phys %llx)\n",
  1947. (u64)efx->stats_buffer.dma_addr,
  1948. efx->stats_buffer.addr,
  1949. (u64)virt_to_phys(efx->stats_buffer.addr));
  1950. return 0;
  1951. }
  1952. void falcon_remove_port(struct efx_nic *efx)
  1953. {
  1954. falcon_free_buffer(efx, &efx->stats_buffer);
  1955. }
  1956. /**************************************************************************
  1957. *
  1958. * Multicast filtering
  1959. *
  1960. **************************************************************************
  1961. */
  1962. void falcon_set_multicast_hash(struct efx_nic *efx)
  1963. {
  1964. union efx_multicast_hash *mc_hash = &efx->multicast_hash;
  1965. /* Broadcast packets go through the multicast hash filter.
  1966. * ether_crc_le() of the broadcast address is 0xbe2612ff
  1967. * so we always add bit 0xff to the mask.
  1968. */
  1969. set_bit_le(0xff, mc_hash->byte);
  1970. efx_writeo(efx, &mc_hash->oword[0], FR_AB_MAC_MC_HASH_REG0);
  1971. efx_writeo(efx, &mc_hash->oword[1], FR_AB_MAC_MC_HASH_REG1);
  1972. }
  1973. /**************************************************************************
  1974. *
  1975. * Falcon test code
  1976. *
  1977. **************************************************************************/
  1978. int falcon_read_nvram(struct efx_nic *efx, struct falcon_nvconfig *nvconfig_out)
  1979. {
  1980. struct falcon_nvconfig *nvconfig;
  1981. struct efx_spi_device *spi;
  1982. void *region;
  1983. int rc, magic_num, struct_ver;
  1984. __le16 *word, *limit;
  1985. u32 csum;
  1986. spi = efx->spi_flash ? efx->spi_flash : efx->spi_eeprom;
  1987. if (!spi)
  1988. return -EINVAL;
  1989. region = kmalloc(FALCON_NVCONFIG_END, GFP_KERNEL);
  1990. if (!region)
  1991. return -ENOMEM;
  1992. nvconfig = region + FALCON_NVCONFIG_OFFSET;
  1993. mutex_lock(&efx->spi_lock);
  1994. rc = falcon_spi_read(spi, 0, FALCON_NVCONFIG_END, NULL, region);
  1995. mutex_unlock(&efx->spi_lock);
  1996. if (rc) {
  1997. EFX_ERR(efx, "Failed to read %s\n",
  1998. efx->spi_flash ? "flash" : "EEPROM");
  1999. rc = -EIO;
  2000. goto out;
  2001. }
  2002. magic_num = le16_to_cpu(nvconfig->board_magic_num);
  2003. struct_ver = le16_to_cpu(nvconfig->board_struct_ver);
  2004. rc = -EINVAL;
  2005. if (magic_num != FALCON_NVCONFIG_BOARD_MAGIC_NUM) {
  2006. EFX_ERR(efx, "NVRAM bad magic 0x%x\n", magic_num);
  2007. goto out;
  2008. }
  2009. if (struct_ver < 2) {
  2010. EFX_ERR(efx, "NVRAM has ancient version 0x%x\n", struct_ver);
  2011. goto out;
  2012. } else if (struct_ver < 4) {
  2013. word = &nvconfig->board_magic_num;
  2014. limit = (__le16 *) (nvconfig + 1);
  2015. } else {
  2016. word = region;
  2017. limit = region + FALCON_NVCONFIG_END;
  2018. }
  2019. for (csum = 0; word < limit; ++word)
  2020. csum += le16_to_cpu(*word);
  2021. if (~csum & 0xffff) {
  2022. EFX_ERR(efx, "NVRAM has incorrect checksum\n");
  2023. goto out;
  2024. }
  2025. rc = 0;
  2026. if (nvconfig_out)
  2027. memcpy(nvconfig_out, nvconfig, sizeof(*nvconfig));
  2028. out:
  2029. kfree(region);
  2030. return rc;
  2031. }
  2032. /* Registers tested in the falcon register test */
  2033. static struct {
  2034. unsigned address;
  2035. efx_oword_t mask;
  2036. } efx_test_registers[] = {
  2037. { FR_AZ_ADR_REGION,
  2038. EFX_OWORD32(0x0001FFFF, 0x0001FFFF, 0x0001FFFF, 0x0001FFFF) },
  2039. { FR_AZ_RX_CFG,
  2040. EFX_OWORD32(0xFFFFFFFE, 0x00017FFF, 0x00000000, 0x00000000) },
  2041. { FR_AZ_TX_CFG,
  2042. EFX_OWORD32(0x7FFF0037, 0x00000000, 0x00000000, 0x00000000) },
  2043. { FR_AZ_TX_RESERVED,
  2044. EFX_OWORD32(0xFFFEFE80, 0x1FFFFFFF, 0x020000FE, 0x007FFFFF) },
  2045. { FR_AB_MAC_CTRL,
  2046. EFX_OWORD32(0xFFFF0000, 0x00000000, 0x00000000, 0x00000000) },
  2047. { FR_AZ_SRM_TX_DC_CFG,
  2048. EFX_OWORD32(0x001FFFFF, 0x00000000, 0x00000000, 0x00000000) },
  2049. { FR_AZ_RX_DC_CFG,
  2050. EFX_OWORD32(0x0000000F, 0x00000000, 0x00000000, 0x00000000) },
  2051. { FR_AZ_RX_DC_PF_WM,
  2052. EFX_OWORD32(0x000003FF, 0x00000000, 0x00000000, 0x00000000) },
  2053. { FR_BZ_DP_CTRL,
  2054. EFX_OWORD32(0x00000FFF, 0x00000000, 0x00000000, 0x00000000) },
  2055. { FR_AB_GM_CFG2,
  2056. EFX_OWORD32(0x00007337, 0x00000000, 0x00000000, 0x00000000) },
  2057. { FR_AB_GMF_CFG0,
  2058. EFX_OWORD32(0x00001F1F, 0x00000000, 0x00000000, 0x00000000) },
  2059. { FR_AB_XM_GLB_CFG,
  2060. EFX_OWORD32(0x00000C68, 0x00000000, 0x00000000, 0x00000000) },
  2061. { FR_AB_XM_TX_CFG,
  2062. EFX_OWORD32(0x00080164, 0x00000000, 0x00000000, 0x00000000) },
  2063. { FR_AB_XM_RX_CFG,
  2064. EFX_OWORD32(0x07100A0C, 0x00000000, 0x00000000, 0x00000000) },
  2065. { FR_AB_XM_RX_PARAM,
  2066. EFX_OWORD32(0x00001FF8, 0x00000000, 0x00000000, 0x00000000) },
  2067. { FR_AB_XM_FC,
  2068. EFX_OWORD32(0xFFFF0001, 0x00000000, 0x00000000, 0x00000000) },
  2069. { FR_AB_XM_ADR_LO,
  2070. EFX_OWORD32(0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000) },
  2071. { FR_AB_XX_SD_CTL,
  2072. EFX_OWORD32(0x0003FF0F, 0x00000000, 0x00000000, 0x00000000) },
  2073. };
  2074. static bool efx_masked_compare_oword(const efx_oword_t *a, const efx_oword_t *b,
  2075. const efx_oword_t *mask)
  2076. {
  2077. return ((a->u64[0] ^ b->u64[0]) & mask->u64[0]) ||
  2078. ((a->u64[1] ^ b->u64[1]) & mask->u64[1]);
  2079. }
  2080. int falcon_test_registers(struct efx_nic *efx)
  2081. {
  2082. unsigned address = 0, i, j;
  2083. efx_oword_t mask, imask, original, reg, buf;
  2084. /* Falcon should be in loopback to isolate the XMAC from the PHY */
  2085. WARN_ON(!LOOPBACK_INTERNAL(efx));
  2086. for (i = 0; i < ARRAY_SIZE(efx_test_registers); ++i) {
  2087. address = efx_test_registers[i].address;
  2088. mask = imask = efx_test_registers[i].mask;
  2089. EFX_INVERT_OWORD(imask);
  2090. efx_reado(efx, &original, address);
  2091. /* bit sweep on and off */
  2092. for (j = 0; j < 128; j++) {
  2093. if (!EFX_EXTRACT_OWORD32(mask, j, j))
  2094. continue;
  2095. /* Test this testable bit can be set in isolation */
  2096. EFX_AND_OWORD(reg, original, mask);
  2097. EFX_SET_OWORD32(reg, j, j, 1);
  2098. efx_writeo(efx, &reg, address);
  2099. efx_reado(efx, &buf, address);
  2100. if (efx_masked_compare_oword(&reg, &buf, &mask))
  2101. goto fail;
  2102. /* Test this testable bit can be cleared in isolation */
  2103. EFX_OR_OWORD(reg, original, mask);
  2104. EFX_SET_OWORD32(reg, j, j, 0);
  2105. efx_writeo(efx, &reg, address);
  2106. efx_reado(efx, &buf, address);
  2107. if (efx_masked_compare_oword(&reg, &buf, &mask))
  2108. goto fail;
  2109. }
  2110. efx_writeo(efx, &original, address);
  2111. }
  2112. return 0;
  2113. fail:
  2114. EFX_ERR(efx, "wrote "EFX_OWORD_FMT" read "EFX_OWORD_FMT
  2115. " at address 0x%x mask "EFX_OWORD_FMT"\n", EFX_OWORD_VAL(reg),
  2116. EFX_OWORD_VAL(buf), address, EFX_OWORD_VAL(mask));
  2117. return -EIO;
  2118. }
  2119. /**************************************************************************
  2120. *
  2121. * Device reset
  2122. *
  2123. **************************************************************************
  2124. */
  2125. /* Resets NIC to known state. This routine must be called in process
  2126. * context and is allowed to sleep. */
  2127. int falcon_reset_hw(struct efx_nic *efx, enum reset_type method)
  2128. {
  2129. struct falcon_nic_data *nic_data = efx->nic_data;
  2130. efx_oword_t glb_ctl_reg_ker;
  2131. int rc;
  2132. EFX_LOG(efx, "performing hardware reset (%d)\n", method);
  2133. /* Initiate device reset */
  2134. if (method == RESET_TYPE_WORLD) {
  2135. rc = pci_save_state(efx->pci_dev);
  2136. if (rc) {
  2137. EFX_ERR(efx, "failed to backup PCI state of primary "
  2138. "function prior to hardware reset\n");
  2139. goto fail1;
  2140. }
  2141. if (FALCON_IS_DUAL_FUNC(efx)) {
  2142. rc = pci_save_state(nic_data->pci_dev2);
  2143. if (rc) {
  2144. EFX_ERR(efx, "failed to backup PCI state of "
  2145. "secondary function prior to "
  2146. "hardware reset\n");
  2147. goto fail2;
  2148. }
  2149. }
  2150. EFX_POPULATE_OWORD_2(glb_ctl_reg_ker,
  2151. FRF_AB_EXT_PHY_RST_DUR,
  2152. FFE_AB_EXT_PHY_RST_DUR_10240US,
  2153. FRF_AB_SWRST, 1);
  2154. } else {
  2155. EFX_POPULATE_OWORD_7(glb_ctl_reg_ker,
  2156. /* exclude PHY from "invisible" reset */
  2157. FRF_AB_EXT_PHY_RST_CTL,
  2158. method == RESET_TYPE_INVISIBLE,
  2159. /* exclude EEPROM/flash and PCIe */
  2160. FRF_AB_PCIE_CORE_RST_CTL, 1,
  2161. FRF_AB_PCIE_NSTKY_RST_CTL, 1,
  2162. FRF_AB_PCIE_SD_RST_CTL, 1,
  2163. FRF_AB_EE_RST_CTL, 1,
  2164. FRF_AB_EXT_PHY_RST_DUR,
  2165. FFE_AB_EXT_PHY_RST_DUR_10240US,
  2166. FRF_AB_SWRST, 1);
  2167. }
  2168. efx_writeo(efx, &glb_ctl_reg_ker, FR_AB_GLB_CTL);
  2169. EFX_LOG(efx, "waiting for hardware reset\n");
  2170. schedule_timeout_uninterruptible(HZ / 20);
  2171. /* Restore PCI configuration if needed */
  2172. if (method == RESET_TYPE_WORLD) {
  2173. if (FALCON_IS_DUAL_FUNC(efx)) {
  2174. rc = pci_restore_state(nic_data->pci_dev2);
  2175. if (rc) {
  2176. EFX_ERR(efx, "failed to restore PCI config for "
  2177. "the secondary function\n");
  2178. goto fail3;
  2179. }
  2180. }
  2181. rc = pci_restore_state(efx->pci_dev);
  2182. if (rc) {
  2183. EFX_ERR(efx, "failed to restore PCI config for the "
  2184. "primary function\n");
  2185. goto fail4;
  2186. }
  2187. EFX_LOG(efx, "successfully restored PCI config\n");
  2188. }
  2189. /* Assert that reset complete */
  2190. efx_reado(efx, &glb_ctl_reg_ker, FR_AB_GLB_CTL);
  2191. if (EFX_OWORD_FIELD(glb_ctl_reg_ker, FRF_AB_SWRST) != 0) {
  2192. rc = -ETIMEDOUT;
  2193. EFX_ERR(efx, "timed out waiting for hardware reset\n");
  2194. goto fail5;
  2195. }
  2196. EFX_LOG(efx, "hardware reset complete\n");
  2197. return 0;
  2198. /* pci_save_state() and pci_restore_state() MUST be called in pairs */
  2199. fail2:
  2200. fail3:
  2201. pci_restore_state(efx->pci_dev);
  2202. fail1:
  2203. fail4:
  2204. fail5:
  2205. return rc;
  2206. }
  2207. /* Zeroes out the SRAM contents. This routine must be called in
  2208. * process context and is allowed to sleep.
  2209. */
  2210. static int falcon_reset_sram(struct efx_nic *efx)
  2211. {
  2212. efx_oword_t srm_cfg_reg_ker, gpio_cfg_reg_ker;
  2213. int count;
  2214. /* Set the SRAM wake/sleep GPIO appropriately. */
  2215. efx_reado(efx, &gpio_cfg_reg_ker, FR_AB_GPIO_CTL);
  2216. EFX_SET_OWORD_FIELD(gpio_cfg_reg_ker, FRF_AB_GPIO1_OEN, 1);
  2217. EFX_SET_OWORD_FIELD(gpio_cfg_reg_ker, FRF_AB_GPIO1_OUT, 1);
  2218. efx_writeo(efx, &gpio_cfg_reg_ker, FR_AB_GPIO_CTL);
  2219. /* Initiate SRAM reset */
  2220. EFX_POPULATE_OWORD_2(srm_cfg_reg_ker,
  2221. FRF_AZ_SRM_INIT_EN, 1,
  2222. FRF_AZ_SRM_NB_SZ, 0);
  2223. efx_writeo(efx, &srm_cfg_reg_ker, FR_AZ_SRM_CFG);
  2224. /* Wait for SRAM reset to complete */
  2225. count = 0;
  2226. do {
  2227. EFX_LOG(efx, "waiting for SRAM reset (attempt %d)...\n", count);
  2228. /* SRAM reset is slow; expect around 16ms */
  2229. schedule_timeout_uninterruptible(HZ / 50);
  2230. /* Check for reset complete */
  2231. efx_reado(efx, &srm_cfg_reg_ker, FR_AZ_SRM_CFG);
  2232. if (!EFX_OWORD_FIELD(srm_cfg_reg_ker, FRF_AZ_SRM_INIT_EN)) {
  2233. EFX_LOG(efx, "SRAM reset complete\n");
  2234. return 0;
  2235. }
  2236. } while (++count < 20); /* wait upto 0.4 sec */
  2237. EFX_ERR(efx, "timed out waiting for SRAM reset\n");
  2238. return -ETIMEDOUT;
  2239. }
  2240. static int falcon_spi_device_init(struct efx_nic *efx,
  2241. struct efx_spi_device **spi_device_ret,
  2242. unsigned int device_id, u32 device_type)
  2243. {
  2244. struct efx_spi_device *spi_device;
  2245. if (device_type != 0) {
  2246. spi_device = kzalloc(sizeof(*spi_device), GFP_KERNEL);
  2247. if (!spi_device)
  2248. return -ENOMEM;
  2249. spi_device->device_id = device_id;
  2250. spi_device->size =
  2251. 1 << SPI_DEV_TYPE_FIELD(device_type, SPI_DEV_TYPE_SIZE);
  2252. spi_device->addr_len =
  2253. SPI_DEV_TYPE_FIELD(device_type, SPI_DEV_TYPE_ADDR_LEN);
  2254. spi_device->munge_address = (spi_device->size == 1 << 9 &&
  2255. spi_device->addr_len == 1);
  2256. spi_device->erase_command =
  2257. SPI_DEV_TYPE_FIELD(device_type, SPI_DEV_TYPE_ERASE_CMD);
  2258. spi_device->erase_size =
  2259. 1 << SPI_DEV_TYPE_FIELD(device_type,
  2260. SPI_DEV_TYPE_ERASE_SIZE);
  2261. spi_device->block_size =
  2262. 1 << SPI_DEV_TYPE_FIELD(device_type,
  2263. SPI_DEV_TYPE_BLOCK_SIZE);
  2264. spi_device->efx = efx;
  2265. } else {
  2266. spi_device = NULL;
  2267. }
  2268. kfree(*spi_device_ret);
  2269. *spi_device_ret = spi_device;
  2270. return 0;
  2271. }
  2272. static void falcon_remove_spi_devices(struct efx_nic *efx)
  2273. {
  2274. kfree(efx->spi_eeprom);
  2275. efx->spi_eeprom = NULL;
  2276. kfree(efx->spi_flash);
  2277. efx->spi_flash = NULL;
  2278. }
  2279. /* Extract non-volatile configuration */
  2280. static int falcon_probe_nvconfig(struct efx_nic *efx)
  2281. {
  2282. struct falcon_nvconfig *nvconfig;
  2283. int board_rev;
  2284. int rc;
  2285. nvconfig = kmalloc(sizeof(*nvconfig), GFP_KERNEL);
  2286. if (!nvconfig)
  2287. return -ENOMEM;
  2288. rc = falcon_read_nvram(efx, nvconfig);
  2289. if (rc == -EINVAL) {
  2290. EFX_ERR(efx, "NVRAM is invalid therefore using defaults\n");
  2291. efx->phy_type = PHY_TYPE_NONE;
  2292. efx->mdio.prtad = MDIO_PRTAD_NONE;
  2293. board_rev = 0;
  2294. rc = 0;
  2295. } else if (rc) {
  2296. goto fail1;
  2297. } else {
  2298. struct falcon_nvconfig_board_v2 *v2 = &nvconfig->board_v2;
  2299. struct falcon_nvconfig_board_v3 *v3 = &nvconfig->board_v3;
  2300. efx->phy_type = v2->port0_phy_type;
  2301. efx->mdio.prtad = v2->port0_phy_addr;
  2302. board_rev = le16_to_cpu(v2->board_revision);
  2303. if (le16_to_cpu(nvconfig->board_struct_ver) >= 3) {
  2304. rc = falcon_spi_device_init(
  2305. efx, &efx->spi_flash, FFE_AB_SPI_DEVICE_FLASH,
  2306. le32_to_cpu(v3->spi_device_type
  2307. [FFE_AB_SPI_DEVICE_FLASH]));
  2308. if (rc)
  2309. goto fail2;
  2310. rc = falcon_spi_device_init(
  2311. efx, &efx->spi_eeprom, FFE_AB_SPI_DEVICE_EEPROM,
  2312. le32_to_cpu(v3->spi_device_type
  2313. [FFE_AB_SPI_DEVICE_EEPROM]));
  2314. if (rc)
  2315. goto fail2;
  2316. }
  2317. }
  2318. /* Read the MAC addresses */
  2319. memcpy(efx->mac_address, nvconfig->mac_address[0], ETH_ALEN);
  2320. EFX_LOG(efx, "PHY is %d phy_id %d\n", efx->phy_type, efx->mdio.prtad);
  2321. falcon_probe_board(efx, board_rev);
  2322. kfree(nvconfig);
  2323. return 0;
  2324. fail2:
  2325. falcon_remove_spi_devices(efx);
  2326. fail1:
  2327. kfree(nvconfig);
  2328. return rc;
  2329. }
  2330. /* Probe the NIC variant (revision, ASIC vs FPGA, function count, port
  2331. * count, port speed). Set workaround and feature flags accordingly.
  2332. */
  2333. static int falcon_probe_nic_variant(struct efx_nic *efx)
  2334. {
  2335. efx_oword_t altera_build;
  2336. efx_oword_t nic_stat;
  2337. efx_reado(efx, &altera_build, FR_AZ_ALTERA_BUILD);
  2338. if (EFX_OWORD_FIELD(altera_build, FRF_AZ_ALTERA_BUILD_VER)) {
  2339. EFX_ERR(efx, "Falcon FPGA not supported\n");
  2340. return -ENODEV;
  2341. }
  2342. efx_reado(efx, &nic_stat, FR_AB_NIC_STAT);
  2343. switch (falcon_rev(efx)) {
  2344. case FALCON_REV_A0:
  2345. case 0xff:
  2346. EFX_ERR(efx, "Falcon rev A0 not supported\n");
  2347. return -ENODEV;
  2348. case FALCON_REV_A1:
  2349. if (EFX_OWORD_FIELD(nic_stat, FRF_AA_STRAP_PCIE) == 0) {
  2350. EFX_ERR(efx, "Falcon rev A1 PCI-X not supported\n");
  2351. return -ENODEV;
  2352. }
  2353. break;
  2354. case FALCON_REV_B0:
  2355. break;
  2356. default:
  2357. EFX_ERR(efx, "Unknown Falcon rev %d\n", falcon_rev(efx));
  2358. return -ENODEV;
  2359. }
  2360. /* Initial assumed speed */
  2361. efx->link_speed = EFX_OWORD_FIELD(nic_stat, FRF_AB_STRAP_10G) ? 10000 : 1000;
  2362. return 0;
  2363. }
  2364. /* Probe all SPI devices on the NIC */
  2365. static void falcon_probe_spi_devices(struct efx_nic *efx)
  2366. {
  2367. efx_oword_t nic_stat, gpio_ctl, ee_vpd_cfg;
  2368. int boot_dev;
  2369. efx_reado(efx, &gpio_ctl, FR_AB_GPIO_CTL);
  2370. efx_reado(efx, &nic_stat, FR_AB_NIC_STAT);
  2371. efx_reado(efx, &ee_vpd_cfg, FR_AB_EE_VPD_CFG0);
  2372. if (EFX_OWORD_FIELD(gpio_ctl, FRF_AB_GPIO3_PWRUP_VALUE)) {
  2373. boot_dev = (EFX_OWORD_FIELD(nic_stat, FRF_AB_SF_PRST) ?
  2374. FFE_AB_SPI_DEVICE_FLASH : FFE_AB_SPI_DEVICE_EEPROM);
  2375. EFX_LOG(efx, "Booted from %s\n",
  2376. boot_dev == FFE_AB_SPI_DEVICE_FLASH ? "flash" : "EEPROM");
  2377. } else {
  2378. /* Disable VPD and set clock dividers to safe
  2379. * values for initial programming. */
  2380. boot_dev = -1;
  2381. EFX_LOG(efx, "Booted from internal ASIC settings;"
  2382. " setting SPI config\n");
  2383. EFX_POPULATE_OWORD_3(ee_vpd_cfg, FRF_AB_EE_VPD_EN, 0,
  2384. /* 125 MHz / 7 ~= 20 MHz */
  2385. FRF_AB_EE_SF_CLOCK_DIV, 7,
  2386. /* 125 MHz / 63 ~= 2 MHz */
  2387. FRF_AB_EE_EE_CLOCK_DIV, 63);
  2388. efx_writeo(efx, &ee_vpd_cfg, FR_AB_EE_VPD_CFG0);
  2389. }
  2390. if (boot_dev == FFE_AB_SPI_DEVICE_FLASH)
  2391. falcon_spi_device_init(efx, &efx->spi_flash,
  2392. FFE_AB_SPI_DEVICE_FLASH,
  2393. default_flash_type);
  2394. if (boot_dev == FFE_AB_SPI_DEVICE_EEPROM)
  2395. falcon_spi_device_init(efx, &efx->spi_eeprom,
  2396. FFE_AB_SPI_DEVICE_EEPROM,
  2397. large_eeprom_type);
  2398. }
  2399. int falcon_probe_nic(struct efx_nic *efx)
  2400. {
  2401. struct falcon_nic_data *nic_data;
  2402. int rc;
  2403. /* Allocate storage for hardware specific data */
  2404. nic_data = kzalloc(sizeof(*nic_data), GFP_KERNEL);
  2405. if (!nic_data)
  2406. return -ENOMEM;
  2407. efx->nic_data = nic_data;
  2408. /* Determine number of ports etc. */
  2409. rc = falcon_probe_nic_variant(efx);
  2410. if (rc)
  2411. goto fail1;
  2412. /* Probe secondary function if expected */
  2413. if (FALCON_IS_DUAL_FUNC(efx)) {
  2414. struct pci_dev *dev = pci_dev_get(efx->pci_dev);
  2415. while ((dev = pci_get_device(EFX_VENDID_SFC, FALCON_A_S_DEVID,
  2416. dev))) {
  2417. if (dev->bus == efx->pci_dev->bus &&
  2418. dev->devfn == efx->pci_dev->devfn + 1) {
  2419. nic_data->pci_dev2 = dev;
  2420. break;
  2421. }
  2422. }
  2423. if (!nic_data->pci_dev2) {
  2424. EFX_ERR(efx, "failed to find secondary function\n");
  2425. rc = -ENODEV;
  2426. goto fail2;
  2427. }
  2428. }
  2429. /* Now we can reset the NIC */
  2430. rc = falcon_reset_hw(efx, RESET_TYPE_ALL);
  2431. if (rc) {
  2432. EFX_ERR(efx, "failed to reset NIC\n");
  2433. goto fail3;
  2434. }
  2435. /* Allocate memory for INT_KER */
  2436. rc = falcon_alloc_buffer(efx, &efx->irq_status, sizeof(efx_oword_t));
  2437. if (rc)
  2438. goto fail4;
  2439. BUG_ON(efx->irq_status.dma_addr & 0x0f);
  2440. EFX_LOG(efx, "INT_KER at %llx (virt %p phys %llx)\n",
  2441. (u64)efx->irq_status.dma_addr,
  2442. efx->irq_status.addr, (u64)virt_to_phys(efx->irq_status.addr));
  2443. falcon_probe_spi_devices(efx);
  2444. /* Read in the non-volatile configuration */
  2445. rc = falcon_probe_nvconfig(efx);
  2446. if (rc)
  2447. goto fail5;
  2448. /* Initialise I2C adapter */
  2449. efx->i2c_adap.owner = THIS_MODULE;
  2450. nic_data->i2c_data = falcon_i2c_bit_operations;
  2451. nic_data->i2c_data.data = efx;
  2452. efx->i2c_adap.algo_data = &nic_data->i2c_data;
  2453. efx->i2c_adap.dev.parent = &efx->pci_dev->dev;
  2454. strlcpy(efx->i2c_adap.name, "SFC4000 GPIO", sizeof(efx->i2c_adap.name));
  2455. rc = i2c_bit_add_bus(&efx->i2c_adap);
  2456. if (rc)
  2457. goto fail5;
  2458. rc = falcon_board(efx)->init(efx);
  2459. if (rc) {
  2460. EFX_ERR(efx, "failed to initialise board\n");
  2461. goto fail6;
  2462. }
  2463. return 0;
  2464. fail6:
  2465. BUG_ON(i2c_del_adapter(&efx->i2c_adap));
  2466. memset(&efx->i2c_adap, 0, sizeof(efx->i2c_adap));
  2467. fail5:
  2468. falcon_remove_spi_devices(efx);
  2469. falcon_free_buffer(efx, &efx->irq_status);
  2470. fail4:
  2471. fail3:
  2472. if (nic_data->pci_dev2) {
  2473. pci_dev_put(nic_data->pci_dev2);
  2474. nic_data->pci_dev2 = NULL;
  2475. }
  2476. fail2:
  2477. fail1:
  2478. kfree(efx->nic_data);
  2479. return rc;
  2480. }
  2481. static void falcon_init_rx_cfg(struct efx_nic *efx)
  2482. {
  2483. /* Prior to Siena the RX DMA engine will split each frame at
  2484. * intervals of RX_USR_BUF_SIZE (32-byte units). We set it to
  2485. * be so large that that never happens. */
  2486. const unsigned huge_buf_size = (3 * 4096) >> 5;
  2487. /* RX control FIFO thresholds (32 entries) */
  2488. const unsigned ctrl_xon_thr = 20;
  2489. const unsigned ctrl_xoff_thr = 25;
  2490. /* RX data FIFO thresholds (256-byte units; size varies) */
  2491. int data_xon_thr = rx_xon_thresh_bytes >> 8;
  2492. int data_xoff_thr = rx_xoff_thresh_bytes >> 8;
  2493. efx_oword_t reg;
  2494. efx_reado(efx, &reg, FR_AZ_RX_CFG);
  2495. if (falcon_rev(efx) <= FALCON_REV_A1) {
  2496. /* Data FIFO size is 5.5K */
  2497. if (data_xon_thr < 0)
  2498. data_xon_thr = 512 >> 8;
  2499. if (data_xoff_thr < 0)
  2500. data_xoff_thr = 2048 >> 8;
  2501. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_DESC_PUSH_EN, 0);
  2502. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_USR_BUF_SIZE,
  2503. huge_buf_size);
  2504. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XON_MAC_TH, data_xon_thr);
  2505. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XOFF_MAC_TH, data_xoff_thr);
  2506. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XON_TX_TH, ctrl_xon_thr);
  2507. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XOFF_TX_TH, ctrl_xoff_thr);
  2508. } else {
  2509. /* Data FIFO size is 80K; register fields moved */
  2510. if (data_xon_thr < 0)
  2511. data_xon_thr = 27648 >> 8; /* ~3*max MTU */
  2512. if (data_xoff_thr < 0)
  2513. data_xoff_thr = 54272 >> 8; /* ~80Kb - 3*max MTU */
  2514. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_DESC_PUSH_EN, 0);
  2515. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_USR_BUF_SIZE,
  2516. huge_buf_size);
  2517. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XON_MAC_TH, data_xon_thr);
  2518. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XOFF_MAC_TH, data_xoff_thr);
  2519. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XON_TX_TH, ctrl_xon_thr);
  2520. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XOFF_TX_TH, ctrl_xoff_thr);
  2521. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_INGR_EN, 1);
  2522. }
  2523. efx_writeo(efx, &reg, FR_AZ_RX_CFG);
  2524. }
  2525. /* This call performs hardware-specific global initialisation, such as
  2526. * defining the descriptor cache sizes and number of RSS channels.
  2527. * It does not set up any buffers, descriptor rings or event queues.
  2528. */
  2529. int falcon_init_nic(struct efx_nic *efx)
  2530. {
  2531. efx_oword_t temp;
  2532. int rc;
  2533. /* Use on-chip SRAM */
  2534. efx_reado(efx, &temp, FR_AB_NIC_STAT);
  2535. EFX_SET_OWORD_FIELD(temp, FRF_AB_ONCHIP_SRAM, 1);
  2536. efx_writeo(efx, &temp, FR_AB_NIC_STAT);
  2537. /* Set the source of the GMAC clock */
  2538. if (falcon_rev(efx) == FALCON_REV_B0) {
  2539. efx_reado(efx, &temp, FR_AB_GPIO_CTL);
  2540. EFX_SET_OWORD_FIELD(temp, FRF_AB_USE_NIC_CLK, true);
  2541. efx_writeo(efx, &temp, FR_AB_GPIO_CTL);
  2542. }
  2543. rc = falcon_reset_sram(efx);
  2544. if (rc)
  2545. return rc;
  2546. /* Set positions of descriptor caches in SRAM. */
  2547. EFX_POPULATE_OWORD_1(temp, FRF_AZ_SRM_TX_DC_BASE_ADR, TX_DC_BASE / 8);
  2548. efx_writeo(efx, &temp, FR_AZ_SRM_TX_DC_CFG);
  2549. EFX_POPULATE_OWORD_1(temp, FRF_AZ_SRM_RX_DC_BASE_ADR, RX_DC_BASE / 8);
  2550. efx_writeo(efx, &temp, FR_AZ_SRM_RX_DC_CFG);
  2551. /* Set TX descriptor cache size. */
  2552. BUILD_BUG_ON(TX_DC_ENTRIES != (16 << TX_DC_ENTRIES_ORDER));
  2553. EFX_POPULATE_OWORD_1(temp, FRF_AZ_TX_DC_SIZE, TX_DC_ENTRIES_ORDER);
  2554. efx_writeo(efx, &temp, FR_AZ_TX_DC_CFG);
  2555. /* Set RX descriptor cache size. Set low watermark to size-8, as
  2556. * this allows most efficient prefetching.
  2557. */
  2558. BUILD_BUG_ON(RX_DC_ENTRIES != (16 << RX_DC_ENTRIES_ORDER));
  2559. EFX_POPULATE_OWORD_1(temp, FRF_AZ_RX_DC_SIZE, RX_DC_ENTRIES_ORDER);
  2560. efx_writeo(efx, &temp, FR_AZ_RX_DC_CFG);
  2561. EFX_POPULATE_OWORD_1(temp, FRF_AZ_RX_DC_PF_LWM, RX_DC_ENTRIES - 8);
  2562. efx_writeo(efx, &temp, FR_AZ_RX_DC_PF_WM);
  2563. /* Clear the parity enables on the TX data fifos as
  2564. * they produce false parity errors because of timing issues
  2565. */
  2566. if (EFX_WORKAROUND_5129(efx)) {
  2567. efx_reado(efx, &temp, FR_AZ_CSR_SPARE);
  2568. EFX_SET_OWORD_FIELD(temp, FRF_AB_MEM_PERR_EN_TX_DATA, 0);
  2569. efx_writeo(efx, &temp, FR_AZ_CSR_SPARE);
  2570. }
  2571. /* Enable all the genuinely fatal interrupts. (They are still
  2572. * masked by the overall interrupt mask, controlled by
  2573. * falcon_interrupts()).
  2574. *
  2575. * Note: All other fatal interrupts are enabled
  2576. */
  2577. EFX_POPULATE_OWORD_3(temp,
  2578. FRF_AZ_ILL_ADR_INT_KER_EN, 1,
  2579. FRF_AZ_RBUF_OWN_INT_KER_EN, 1,
  2580. FRF_AZ_TBUF_OWN_INT_KER_EN, 1);
  2581. EFX_INVERT_OWORD(temp);
  2582. efx_writeo(efx, &temp, FR_AZ_FATAL_INTR_KER);
  2583. if (EFX_WORKAROUND_7244(efx)) {
  2584. efx_reado(efx, &temp, FR_BZ_RX_FILTER_CTL);
  2585. EFX_SET_OWORD_FIELD(temp, FRF_BZ_UDP_FULL_SRCH_LIMIT, 8);
  2586. EFX_SET_OWORD_FIELD(temp, FRF_BZ_UDP_WILD_SRCH_LIMIT, 8);
  2587. EFX_SET_OWORD_FIELD(temp, FRF_BZ_TCP_FULL_SRCH_LIMIT, 8);
  2588. EFX_SET_OWORD_FIELD(temp, FRF_BZ_TCP_WILD_SRCH_LIMIT, 8);
  2589. efx_writeo(efx, &temp, FR_BZ_RX_FILTER_CTL);
  2590. }
  2591. falcon_setup_rss_indir_table(efx);
  2592. /* XXX This is documented only for Falcon A0/A1 */
  2593. /* Setup RX. Wait for descriptor is broken and must
  2594. * be disabled. RXDP recovery shouldn't be needed, but is.
  2595. */
  2596. efx_reado(efx, &temp, FR_AA_RX_SELF_RST);
  2597. EFX_SET_OWORD_FIELD(temp, FRF_AA_RX_NODESC_WAIT_DIS, 1);
  2598. EFX_SET_OWORD_FIELD(temp, FRF_AA_RX_SELF_RST_EN, 1);
  2599. if (EFX_WORKAROUND_5583(efx))
  2600. EFX_SET_OWORD_FIELD(temp, FRF_AA_RX_ISCSI_DIS, 1);
  2601. efx_writeo(efx, &temp, FR_AA_RX_SELF_RST);
  2602. /* Disable the ugly timer-based TX DMA backoff and allow TX DMA to be
  2603. * controlled by the RX FIFO fill level. Set arbitration to one pkt/Q.
  2604. */
  2605. efx_reado(efx, &temp, FR_AZ_TX_RESERVED);
  2606. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_RX_SPACER, 0xfe);
  2607. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_RX_SPACER_EN, 1);
  2608. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_ONE_PKT_PER_Q, 1);
  2609. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_PUSH_EN, 0);
  2610. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_DIS_NON_IP_EV, 1);
  2611. /* Enable SW_EV to inherit in char driver - assume harmless here */
  2612. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_SOFT_EVT_EN, 1);
  2613. /* Prefetch threshold 2 => fetch when descriptor cache half empty */
  2614. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_PREF_THRESHOLD, 2);
  2615. /* Squash TX of packets of 16 bytes or less */
  2616. if (falcon_rev(efx) >= FALCON_REV_B0 && EFX_WORKAROUND_9141(efx))
  2617. EFX_SET_OWORD_FIELD(temp, FRF_BZ_TX_FLUSH_MIN_LEN_EN, 1);
  2618. efx_writeo(efx, &temp, FR_AZ_TX_RESERVED);
  2619. /* Do not enable TX_NO_EOP_DISC_EN, since it limits packets to 16
  2620. * descriptors (which is bad).
  2621. */
  2622. efx_reado(efx, &temp, FR_AZ_TX_CFG);
  2623. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_NO_EOP_DISC_EN, 0);
  2624. efx_writeo(efx, &temp, FR_AZ_TX_CFG);
  2625. falcon_init_rx_cfg(efx);
  2626. /* Set destination of both TX and RX Flush events */
  2627. if (falcon_rev(efx) >= FALCON_REV_B0) {
  2628. EFX_POPULATE_OWORD_1(temp, FRF_BZ_FLS_EVQ_ID, 0);
  2629. efx_writeo(efx, &temp, FR_BZ_DP_CTRL);
  2630. }
  2631. return 0;
  2632. }
  2633. void falcon_remove_nic(struct efx_nic *efx)
  2634. {
  2635. struct falcon_nic_data *nic_data = efx->nic_data;
  2636. int rc;
  2637. falcon_board(efx)->fini(efx);
  2638. /* Remove I2C adapter and clear it in preparation for a retry */
  2639. rc = i2c_del_adapter(&efx->i2c_adap);
  2640. BUG_ON(rc);
  2641. memset(&efx->i2c_adap, 0, sizeof(efx->i2c_adap));
  2642. falcon_remove_spi_devices(efx);
  2643. falcon_free_buffer(efx, &efx->irq_status);
  2644. falcon_reset_hw(efx, RESET_TYPE_ALL);
  2645. /* Release the second function after the reset */
  2646. if (nic_data->pci_dev2) {
  2647. pci_dev_put(nic_data->pci_dev2);
  2648. nic_data->pci_dev2 = NULL;
  2649. }
  2650. /* Tear down the private nic state */
  2651. kfree(efx->nic_data);
  2652. efx->nic_data = NULL;
  2653. }
  2654. void falcon_update_nic_stats(struct efx_nic *efx)
  2655. {
  2656. efx_oword_t cnt;
  2657. efx_reado(efx, &cnt, FR_AZ_RX_NODESC_DROP);
  2658. efx->n_rx_nodesc_drop_cnt +=
  2659. EFX_OWORD_FIELD(cnt, FRF_AB_RX_NODESC_DROP_CNT);
  2660. }
  2661. /**************************************************************************
  2662. *
  2663. * Revision-dependent attributes used by efx.c
  2664. *
  2665. **************************************************************************
  2666. */
  2667. struct efx_nic_type falcon_a_nic_type = {
  2668. .mem_map_size = 0x20000,
  2669. .txd_ptr_tbl_base = FR_AA_TX_DESC_PTR_TBL_KER,
  2670. .rxd_ptr_tbl_base = FR_AA_RX_DESC_PTR_TBL_KER,
  2671. .buf_tbl_base = FR_AA_BUF_FULL_TBL_KER,
  2672. .evq_ptr_tbl_base = FR_AA_EVQ_PTR_TBL_KER,
  2673. .evq_rptr_tbl_base = FR_AA_EVQ_RPTR_KER,
  2674. .max_dma_mask = DMA_BIT_MASK(FSF_AZ_TX_KER_BUF_ADDR_WIDTH),
  2675. .rx_buffer_padding = 0x24,
  2676. .max_interrupt_mode = EFX_INT_MODE_MSI,
  2677. .phys_addr_channels = 4,
  2678. };
  2679. struct efx_nic_type falcon_b_nic_type = {
  2680. /* Map everything up to and including the RSS indirection
  2681. * table. Don't map MSI-X table, MSI-X PBA since Linux
  2682. * requires that they not be mapped. */
  2683. .mem_map_size = (FR_BZ_RX_INDIRECTION_TBL +
  2684. FR_BZ_RX_INDIRECTION_TBL_STEP *
  2685. FR_BZ_RX_INDIRECTION_TBL_ROWS),
  2686. .txd_ptr_tbl_base = FR_BZ_TX_DESC_PTR_TBL,
  2687. .rxd_ptr_tbl_base = FR_BZ_RX_DESC_PTR_TBL,
  2688. .buf_tbl_base = FR_BZ_BUF_FULL_TBL,
  2689. .evq_ptr_tbl_base = FR_BZ_EVQ_PTR_TBL,
  2690. .evq_rptr_tbl_base = FR_BZ_EVQ_RPTR,
  2691. .max_dma_mask = DMA_BIT_MASK(FSF_AZ_TX_KER_BUF_ADDR_WIDTH),
  2692. .rx_buffer_padding = 0,
  2693. .max_interrupt_mode = EFX_INT_MODE_MSIX,
  2694. .phys_addr_channels = 32, /* Hardware limit is 64, but the legacy
  2695. * interrupt handler only supports 32
  2696. * channels */
  2697. };