falcon.c 78 KB

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