falcon.c 78 KB

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