falcon.c 78 KB

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