falcon.c 95 KB

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