falcon.c 79 KB

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