falcon.c 83 KB

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