falcon.c 90 KB

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