falcon.c 90 KB

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