falcon.c 90 KB

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