falcon.c 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880
  1. /****************************************************************************
  2. * Driver for Solarflare Solarstorm network controllers and boards
  3. * Copyright 2005-2006 Fen Systems Ltd.
  4. * Copyright 2006-2009 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/mii.h>
  17. #include <linux/slab.h>
  18. #include "net_driver.h"
  19. #include "bitfield.h"
  20. #include "efx.h"
  21. #include "mac.h"
  22. #include "spi.h"
  23. #include "nic.h"
  24. #include "regs.h"
  25. #include "io.h"
  26. #include "mdio_10g.h"
  27. #include "phy.h"
  28. #include "workarounds.h"
  29. /* Hardware control for SFC4000 (aka Falcon). */
  30. static const unsigned int
  31. /* "Large" EEPROM device: Atmel AT25640 or similar
  32. * 8 KB, 16-bit address, 32 B write block */
  33. large_eeprom_type = ((13 << SPI_DEV_TYPE_SIZE_LBN)
  34. | (2 << SPI_DEV_TYPE_ADDR_LEN_LBN)
  35. | (5 << SPI_DEV_TYPE_BLOCK_SIZE_LBN)),
  36. /* Default flash device: Atmel AT25F1024
  37. * 128 KB, 24-bit address, 32 KB erase block, 256 B write block */
  38. default_flash_type = ((17 << SPI_DEV_TYPE_SIZE_LBN)
  39. | (3 << SPI_DEV_TYPE_ADDR_LEN_LBN)
  40. | (0x52 << SPI_DEV_TYPE_ERASE_CMD_LBN)
  41. | (15 << SPI_DEV_TYPE_ERASE_SIZE_LBN)
  42. | (8 << SPI_DEV_TYPE_BLOCK_SIZE_LBN));
  43. /**************************************************************************
  44. *
  45. * I2C bus - this is a bit-bashing interface using GPIO pins
  46. * Note that it uses the output enables to tristate the outputs
  47. * SDA is the data pin and SCL is the clock
  48. *
  49. **************************************************************************
  50. */
  51. static void falcon_setsda(void *data, int state)
  52. {
  53. struct efx_nic *efx = (struct efx_nic *)data;
  54. efx_oword_t reg;
  55. efx_reado(efx, &reg, FR_AB_GPIO_CTL);
  56. EFX_SET_OWORD_FIELD(reg, FRF_AB_GPIO3_OEN, !state);
  57. efx_writeo(efx, &reg, FR_AB_GPIO_CTL);
  58. }
  59. static void falcon_setscl(void *data, int state)
  60. {
  61. struct efx_nic *efx = (struct efx_nic *)data;
  62. efx_oword_t reg;
  63. efx_reado(efx, &reg, FR_AB_GPIO_CTL);
  64. EFX_SET_OWORD_FIELD(reg, FRF_AB_GPIO0_OEN, !state);
  65. efx_writeo(efx, &reg, FR_AB_GPIO_CTL);
  66. }
  67. static int falcon_getsda(void *data)
  68. {
  69. struct efx_nic *efx = (struct efx_nic *)data;
  70. efx_oword_t reg;
  71. efx_reado(efx, &reg, FR_AB_GPIO_CTL);
  72. return EFX_OWORD_FIELD(reg, FRF_AB_GPIO3_IN);
  73. }
  74. static int falcon_getscl(void *data)
  75. {
  76. struct efx_nic *efx = (struct efx_nic *)data;
  77. efx_oword_t reg;
  78. efx_reado(efx, &reg, FR_AB_GPIO_CTL);
  79. return EFX_OWORD_FIELD(reg, FRF_AB_GPIO0_IN);
  80. }
  81. static struct i2c_algo_bit_data falcon_i2c_bit_operations = {
  82. .setsda = falcon_setsda,
  83. .setscl = falcon_setscl,
  84. .getsda = falcon_getsda,
  85. .getscl = falcon_getscl,
  86. .udelay = 5,
  87. /* Wait up to 50 ms for slave to let us pull SCL high */
  88. .timeout = DIV_ROUND_UP(HZ, 20),
  89. };
  90. static void falcon_push_irq_moderation(struct efx_channel *channel)
  91. {
  92. efx_dword_t timer_cmd;
  93. struct efx_nic *efx = channel->efx;
  94. /* Set timer register */
  95. if (channel->irq_moderation) {
  96. EFX_POPULATE_DWORD_2(timer_cmd,
  97. FRF_AB_TC_TIMER_MODE,
  98. FFE_BB_TIMER_MODE_INT_HLDOFF,
  99. FRF_AB_TC_TIMER_VAL,
  100. channel->irq_moderation - 1);
  101. } else {
  102. EFX_POPULATE_DWORD_2(timer_cmd,
  103. FRF_AB_TC_TIMER_MODE,
  104. FFE_BB_TIMER_MODE_DIS,
  105. FRF_AB_TC_TIMER_VAL, 0);
  106. }
  107. BUILD_BUG_ON(FR_AA_TIMER_COMMAND_KER != FR_BZ_TIMER_COMMAND_P0);
  108. efx_writed_page_locked(efx, &timer_cmd, FR_BZ_TIMER_COMMAND_P0,
  109. channel->channel);
  110. }
  111. static void falcon_deconfigure_mac_wrapper(struct efx_nic *efx);
  112. static void falcon_prepare_flush(struct efx_nic *efx)
  113. {
  114. falcon_deconfigure_mac_wrapper(efx);
  115. /* Wait for the tx and rx fifo's to get to the next packet boundary
  116. * (~1ms without back-pressure), then to drain the remainder of the
  117. * fifo's at data path speeds (negligible), with a healthy margin. */
  118. msleep(10);
  119. }
  120. /* Acknowledge a legacy interrupt from Falcon
  121. *
  122. * This acknowledges a legacy (not MSI) interrupt via INT_ACK_KER_REG.
  123. *
  124. * Due to SFC bug 3706 (silicon revision <=A1) reads can be duplicated in the
  125. * BIU. Interrupt acknowledge is read sensitive so must write instead
  126. * (then read to ensure the BIU collector is flushed)
  127. *
  128. * NB most hardware supports MSI interrupts
  129. */
  130. inline void falcon_irq_ack_a1(struct efx_nic *efx)
  131. {
  132. efx_dword_t reg;
  133. EFX_POPULATE_DWORD_1(reg, FRF_AA_INT_ACK_KER_FIELD, 0xb7eb7e);
  134. efx_writed(efx, &reg, FR_AA_INT_ACK_KER);
  135. efx_readd(efx, &reg, FR_AA_WORK_AROUND_BROKEN_PCI_READS);
  136. }
  137. irqreturn_t falcon_legacy_interrupt_a1(int irq, void *dev_id)
  138. {
  139. struct efx_nic *efx = dev_id;
  140. efx_oword_t *int_ker = efx->irq_status.addr;
  141. int syserr;
  142. int queues;
  143. /* Check to see if this is our interrupt. If it isn't, we
  144. * exit without having touched the hardware.
  145. */
  146. if (unlikely(EFX_OWORD_IS_ZERO(*int_ker))) {
  147. netif_vdbg(efx, intr, efx->net_dev,
  148. "IRQ %d on CPU %d not for me\n", irq,
  149. raw_smp_processor_id());
  150. return IRQ_NONE;
  151. }
  152. efx->last_irq_cpu = raw_smp_processor_id();
  153. netif_vdbg(efx, intr, efx->net_dev,
  154. "IRQ %d on CPU %d status " EFX_OWORD_FMT "\n",
  155. irq, raw_smp_processor_id(), EFX_OWORD_VAL(*int_ker));
  156. /* Determine interrupting queues, clear interrupt status
  157. * register and acknowledge the device interrupt.
  158. */
  159. BUILD_BUG_ON(FSF_AZ_NET_IVEC_INT_Q_WIDTH > EFX_MAX_CHANNELS);
  160. queues = EFX_OWORD_FIELD(*int_ker, FSF_AZ_NET_IVEC_INT_Q);
  161. /* Check to see if we have a serious error condition */
  162. if (queues & (1U << efx->fatal_irq_level)) {
  163. syserr = EFX_OWORD_FIELD(*int_ker, FSF_AZ_NET_IVEC_FATAL_INT);
  164. if (unlikely(syserr))
  165. return efx_nic_fatal_interrupt(efx);
  166. }
  167. EFX_ZERO_OWORD(*int_ker);
  168. wmb(); /* Ensure the vector is cleared before interrupt ack */
  169. falcon_irq_ack_a1(efx);
  170. if (queues & 1)
  171. efx_schedule_channel(efx_get_channel(efx, 0));
  172. if (queues & 2)
  173. efx_schedule_channel(efx_get_channel(efx, 1));
  174. return IRQ_HANDLED;
  175. }
  176. /**************************************************************************
  177. *
  178. * EEPROM/flash
  179. *
  180. **************************************************************************
  181. */
  182. #define FALCON_SPI_MAX_LEN sizeof(efx_oword_t)
  183. static int falcon_spi_poll(struct efx_nic *efx)
  184. {
  185. efx_oword_t reg;
  186. efx_reado(efx, &reg, FR_AB_EE_SPI_HCMD);
  187. return EFX_OWORD_FIELD(reg, FRF_AB_EE_SPI_HCMD_CMD_EN) ? -EBUSY : 0;
  188. }
  189. /* Wait for SPI command completion */
  190. static int falcon_spi_wait(struct efx_nic *efx)
  191. {
  192. /* Most commands will finish quickly, so we start polling at
  193. * very short intervals. Sometimes the command may have to
  194. * wait for VPD or expansion ROM access outside of our
  195. * control, so we allow up to 100 ms. */
  196. unsigned long timeout = jiffies + 1 + DIV_ROUND_UP(HZ, 10);
  197. int i;
  198. for (i = 0; i < 10; i++) {
  199. if (!falcon_spi_poll(efx))
  200. return 0;
  201. udelay(10);
  202. }
  203. for (;;) {
  204. if (!falcon_spi_poll(efx))
  205. return 0;
  206. if (time_after_eq(jiffies, timeout)) {
  207. netif_err(efx, hw, efx->net_dev,
  208. "timed out waiting for SPI\n");
  209. return -ETIMEDOUT;
  210. }
  211. schedule_timeout_uninterruptible(1);
  212. }
  213. }
  214. int falcon_spi_cmd(struct efx_nic *efx, const struct efx_spi_device *spi,
  215. unsigned int command, int address,
  216. const void *in, void *out, size_t len)
  217. {
  218. bool addressed = (address >= 0);
  219. bool reading = (out != NULL);
  220. efx_oword_t reg;
  221. int rc;
  222. /* Input validation */
  223. if (len > FALCON_SPI_MAX_LEN)
  224. return -EINVAL;
  225. BUG_ON(!mutex_is_locked(&efx->spi_lock));
  226. /* Check that previous command is not still running */
  227. rc = falcon_spi_poll(efx);
  228. if (rc)
  229. return rc;
  230. /* Program address register, if we have an address */
  231. if (addressed) {
  232. EFX_POPULATE_OWORD_1(reg, FRF_AB_EE_SPI_HADR_ADR, address);
  233. efx_writeo(efx, &reg, FR_AB_EE_SPI_HADR);
  234. }
  235. /* Program data register, if we have data */
  236. if (in != NULL) {
  237. memcpy(&reg, in, len);
  238. efx_writeo(efx, &reg, FR_AB_EE_SPI_HDATA);
  239. }
  240. /* Issue read/write command */
  241. EFX_POPULATE_OWORD_7(reg,
  242. FRF_AB_EE_SPI_HCMD_CMD_EN, 1,
  243. FRF_AB_EE_SPI_HCMD_SF_SEL, spi->device_id,
  244. FRF_AB_EE_SPI_HCMD_DABCNT, len,
  245. FRF_AB_EE_SPI_HCMD_READ, reading,
  246. FRF_AB_EE_SPI_HCMD_DUBCNT, 0,
  247. FRF_AB_EE_SPI_HCMD_ADBCNT,
  248. (addressed ? spi->addr_len : 0),
  249. FRF_AB_EE_SPI_HCMD_ENC, command);
  250. efx_writeo(efx, &reg, FR_AB_EE_SPI_HCMD);
  251. /* Wait for read/write to complete */
  252. rc = falcon_spi_wait(efx);
  253. if (rc)
  254. return rc;
  255. /* Read data */
  256. if (out != NULL) {
  257. efx_reado(efx, &reg, FR_AB_EE_SPI_HDATA);
  258. memcpy(out, &reg, len);
  259. }
  260. return 0;
  261. }
  262. static size_t
  263. falcon_spi_write_limit(const struct efx_spi_device *spi, size_t start)
  264. {
  265. return min(FALCON_SPI_MAX_LEN,
  266. (spi->block_size - (start & (spi->block_size - 1))));
  267. }
  268. static inline u8
  269. efx_spi_munge_command(const struct efx_spi_device *spi,
  270. const u8 command, const unsigned int address)
  271. {
  272. return command | (((address >> 8) & spi->munge_address) << 3);
  273. }
  274. /* Wait up to 10 ms for buffered write completion */
  275. int
  276. falcon_spi_wait_write(struct efx_nic *efx, const struct efx_spi_device *spi)
  277. {
  278. unsigned long timeout = jiffies + 1 + DIV_ROUND_UP(HZ, 100);
  279. u8 status;
  280. int rc;
  281. for (;;) {
  282. rc = falcon_spi_cmd(efx, spi, SPI_RDSR, -1, NULL,
  283. &status, sizeof(status));
  284. if (rc)
  285. return rc;
  286. if (!(status & SPI_STATUS_NRDY))
  287. return 0;
  288. if (time_after_eq(jiffies, timeout)) {
  289. netif_err(efx, hw, efx->net_dev,
  290. "SPI write timeout on device %d"
  291. " last status=0x%02x\n",
  292. spi->device_id, status);
  293. return -ETIMEDOUT;
  294. }
  295. schedule_timeout_uninterruptible(1);
  296. }
  297. }
  298. int falcon_spi_read(struct efx_nic *efx, const struct efx_spi_device *spi,
  299. loff_t start, size_t len, size_t *retlen, u8 *buffer)
  300. {
  301. size_t block_len, pos = 0;
  302. unsigned int command;
  303. int rc = 0;
  304. while (pos < len) {
  305. block_len = min(len - pos, FALCON_SPI_MAX_LEN);
  306. command = efx_spi_munge_command(spi, SPI_READ, start + pos);
  307. rc = falcon_spi_cmd(efx, spi, command, start + pos, NULL,
  308. buffer + pos, block_len);
  309. if (rc)
  310. break;
  311. pos += block_len;
  312. /* Avoid locking up the system */
  313. cond_resched();
  314. if (signal_pending(current)) {
  315. rc = -EINTR;
  316. break;
  317. }
  318. }
  319. if (retlen)
  320. *retlen = pos;
  321. return rc;
  322. }
  323. int
  324. falcon_spi_write(struct efx_nic *efx, const struct efx_spi_device *spi,
  325. loff_t start, size_t len, size_t *retlen, const u8 *buffer)
  326. {
  327. u8 verify_buffer[FALCON_SPI_MAX_LEN];
  328. size_t block_len, pos = 0;
  329. unsigned int command;
  330. int rc = 0;
  331. while (pos < len) {
  332. rc = falcon_spi_cmd(efx, spi, SPI_WREN, -1, NULL, NULL, 0);
  333. if (rc)
  334. break;
  335. block_len = min(len - pos,
  336. falcon_spi_write_limit(spi, start + pos));
  337. command = efx_spi_munge_command(spi, SPI_WRITE, start + pos);
  338. rc = falcon_spi_cmd(efx, spi, command, start + pos,
  339. buffer + pos, NULL, block_len);
  340. if (rc)
  341. break;
  342. rc = falcon_spi_wait_write(efx, spi);
  343. if (rc)
  344. break;
  345. command = efx_spi_munge_command(spi, SPI_READ, start + pos);
  346. rc = falcon_spi_cmd(efx, spi, command, start + pos,
  347. NULL, verify_buffer, block_len);
  348. if (memcmp(verify_buffer, buffer + pos, block_len)) {
  349. rc = -EIO;
  350. break;
  351. }
  352. pos += block_len;
  353. /* Avoid locking up the system */
  354. cond_resched();
  355. if (signal_pending(current)) {
  356. rc = -EINTR;
  357. break;
  358. }
  359. }
  360. if (retlen)
  361. *retlen = pos;
  362. return rc;
  363. }
  364. /**************************************************************************
  365. *
  366. * MAC wrapper
  367. *
  368. **************************************************************************
  369. */
  370. static void falcon_push_multicast_hash(struct efx_nic *efx)
  371. {
  372. union efx_multicast_hash *mc_hash = &efx->multicast_hash;
  373. WARN_ON(!mutex_is_locked(&efx->mac_lock));
  374. efx_writeo(efx, &mc_hash->oword[0], FR_AB_MAC_MC_HASH_REG0);
  375. efx_writeo(efx, &mc_hash->oword[1], FR_AB_MAC_MC_HASH_REG1);
  376. }
  377. static void falcon_reset_macs(struct efx_nic *efx)
  378. {
  379. struct falcon_nic_data *nic_data = efx->nic_data;
  380. efx_oword_t reg, mac_ctrl;
  381. int count;
  382. if (efx_nic_rev(efx) < EFX_REV_FALCON_B0) {
  383. /* It's not safe to use GLB_CTL_REG to reset the
  384. * macs, so instead use the internal MAC resets
  385. */
  386. if (!EFX_IS10G(efx)) {
  387. EFX_POPULATE_OWORD_1(reg, FRF_AB_GM_SW_RST, 1);
  388. efx_writeo(efx, &reg, FR_AB_GM_CFG1);
  389. udelay(1000);
  390. EFX_POPULATE_OWORD_1(reg, FRF_AB_GM_SW_RST, 0);
  391. efx_writeo(efx, &reg, FR_AB_GM_CFG1);
  392. udelay(1000);
  393. return;
  394. } else {
  395. EFX_POPULATE_OWORD_1(reg, FRF_AB_XM_CORE_RST, 1);
  396. efx_writeo(efx, &reg, FR_AB_XM_GLB_CFG);
  397. for (count = 0; count < 10000; count++) {
  398. efx_reado(efx, &reg, FR_AB_XM_GLB_CFG);
  399. if (EFX_OWORD_FIELD(reg, FRF_AB_XM_CORE_RST) ==
  400. 0)
  401. return;
  402. udelay(10);
  403. }
  404. netif_err(efx, hw, efx->net_dev,
  405. "timed out waiting for XMAC core reset\n");
  406. }
  407. }
  408. /* Mac stats will fail whist the TX fifo is draining */
  409. WARN_ON(nic_data->stats_disable_count == 0);
  410. efx_reado(efx, &mac_ctrl, FR_AB_MAC_CTRL);
  411. EFX_SET_OWORD_FIELD(mac_ctrl, FRF_BB_TXFIFO_DRAIN_EN, 1);
  412. efx_writeo(efx, &mac_ctrl, FR_AB_MAC_CTRL);
  413. efx_reado(efx, &reg, FR_AB_GLB_CTL);
  414. EFX_SET_OWORD_FIELD(reg, FRF_AB_RST_XGTX, 1);
  415. EFX_SET_OWORD_FIELD(reg, FRF_AB_RST_XGRX, 1);
  416. EFX_SET_OWORD_FIELD(reg, FRF_AB_RST_EM, 1);
  417. efx_writeo(efx, &reg, FR_AB_GLB_CTL);
  418. count = 0;
  419. while (1) {
  420. efx_reado(efx, &reg, FR_AB_GLB_CTL);
  421. if (!EFX_OWORD_FIELD(reg, FRF_AB_RST_XGTX) &&
  422. !EFX_OWORD_FIELD(reg, FRF_AB_RST_XGRX) &&
  423. !EFX_OWORD_FIELD(reg, FRF_AB_RST_EM)) {
  424. netif_dbg(efx, hw, efx->net_dev,
  425. "Completed MAC reset after %d loops\n",
  426. count);
  427. break;
  428. }
  429. if (count > 20) {
  430. netif_err(efx, hw, efx->net_dev, "MAC reset failed\n");
  431. break;
  432. }
  433. count++;
  434. udelay(10);
  435. }
  436. /* Ensure the correct MAC is selected before statistics
  437. * are re-enabled by the caller */
  438. efx_writeo(efx, &mac_ctrl, FR_AB_MAC_CTRL);
  439. /* This can run even when the GMAC is selected */
  440. falcon_setup_xaui(efx);
  441. }
  442. void falcon_drain_tx_fifo(struct efx_nic *efx)
  443. {
  444. efx_oword_t reg;
  445. if ((efx_nic_rev(efx) < EFX_REV_FALCON_B0) ||
  446. (efx->loopback_mode != LOOPBACK_NONE))
  447. return;
  448. efx_reado(efx, &reg, FR_AB_MAC_CTRL);
  449. /* There is no point in draining more than once */
  450. if (EFX_OWORD_FIELD(reg, FRF_BB_TXFIFO_DRAIN_EN))
  451. return;
  452. falcon_reset_macs(efx);
  453. }
  454. static void falcon_deconfigure_mac_wrapper(struct efx_nic *efx)
  455. {
  456. efx_oword_t reg;
  457. if (efx_nic_rev(efx) < EFX_REV_FALCON_B0)
  458. return;
  459. /* Isolate the MAC -> RX */
  460. efx_reado(efx, &reg, FR_AZ_RX_CFG);
  461. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_INGR_EN, 0);
  462. efx_writeo(efx, &reg, FR_AZ_RX_CFG);
  463. /* Isolate TX -> MAC */
  464. falcon_drain_tx_fifo(efx);
  465. }
  466. void falcon_reconfigure_mac_wrapper(struct efx_nic *efx)
  467. {
  468. struct efx_link_state *link_state = &efx->link_state;
  469. efx_oword_t reg;
  470. int link_speed, isolate;
  471. isolate = (efx->reset_pending != RESET_TYPE_NONE);
  472. switch (link_state->speed) {
  473. case 10000: link_speed = 3; break;
  474. case 1000: link_speed = 2; break;
  475. case 100: link_speed = 1; break;
  476. default: link_speed = 0; break;
  477. }
  478. /* MAC_LINK_STATUS controls MAC backpressure but doesn't work
  479. * as advertised. Disable to ensure packets are not
  480. * indefinitely held and TX queue can be flushed at any point
  481. * while the link is down. */
  482. EFX_POPULATE_OWORD_5(reg,
  483. FRF_AB_MAC_XOFF_VAL, 0xffff /* max pause time */,
  484. FRF_AB_MAC_BCAD_ACPT, 1,
  485. FRF_AB_MAC_UC_PROM, efx->promiscuous,
  486. FRF_AB_MAC_LINK_STATUS, 1, /* always set */
  487. FRF_AB_MAC_SPEED, link_speed);
  488. /* On B0, MAC backpressure can be disabled and packets get
  489. * discarded. */
  490. if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0) {
  491. EFX_SET_OWORD_FIELD(reg, FRF_BB_TXFIFO_DRAIN_EN,
  492. !link_state->up || isolate);
  493. }
  494. efx_writeo(efx, &reg, FR_AB_MAC_CTRL);
  495. /* Restore the multicast hash registers. */
  496. falcon_push_multicast_hash(efx);
  497. efx_reado(efx, &reg, FR_AZ_RX_CFG);
  498. /* Enable XOFF signal from RX FIFO (we enabled it during NIC
  499. * initialisation but it may read back as 0) */
  500. EFX_SET_OWORD_FIELD(reg, FRF_AZ_RX_XOFF_MAC_EN, 1);
  501. /* Unisolate the MAC -> RX */
  502. if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0)
  503. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_INGR_EN, !isolate);
  504. efx_writeo(efx, &reg, FR_AZ_RX_CFG);
  505. }
  506. static void falcon_stats_request(struct efx_nic *efx)
  507. {
  508. struct falcon_nic_data *nic_data = efx->nic_data;
  509. efx_oword_t reg;
  510. WARN_ON(nic_data->stats_pending);
  511. WARN_ON(nic_data->stats_disable_count);
  512. if (nic_data->stats_dma_done == NULL)
  513. return; /* no mac selected */
  514. *nic_data->stats_dma_done = FALCON_STATS_NOT_DONE;
  515. nic_data->stats_pending = true;
  516. wmb(); /* ensure done flag is clear */
  517. /* Initiate DMA transfer of stats */
  518. EFX_POPULATE_OWORD_2(reg,
  519. FRF_AB_MAC_STAT_DMA_CMD, 1,
  520. FRF_AB_MAC_STAT_DMA_ADR,
  521. efx->stats_buffer.dma_addr);
  522. efx_writeo(efx, &reg, FR_AB_MAC_STAT_DMA);
  523. mod_timer(&nic_data->stats_timer, round_jiffies_up(jiffies + HZ / 2));
  524. }
  525. static void falcon_stats_complete(struct efx_nic *efx)
  526. {
  527. struct falcon_nic_data *nic_data = efx->nic_data;
  528. if (!nic_data->stats_pending)
  529. return;
  530. nic_data->stats_pending = 0;
  531. if (*nic_data->stats_dma_done == FALCON_STATS_DONE) {
  532. rmb(); /* read the done flag before the stats */
  533. efx->mac_op->update_stats(efx);
  534. } else {
  535. netif_err(efx, hw, efx->net_dev,
  536. "timed out waiting for statistics\n");
  537. }
  538. }
  539. static void falcon_stats_timer_func(unsigned long context)
  540. {
  541. struct efx_nic *efx = (struct efx_nic *)context;
  542. struct falcon_nic_data *nic_data = efx->nic_data;
  543. spin_lock(&efx->stats_lock);
  544. falcon_stats_complete(efx);
  545. if (nic_data->stats_disable_count == 0)
  546. falcon_stats_request(efx);
  547. spin_unlock(&efx->stats_lock);
  548. }
  549. static void falcon_switch_mac(struct efx_nic *efx);
  550. static bool falcon_loopback_link_poll(struct efx_nic *efx)
  551. {
  552. struct efx_link_state old_state = efx->link_state;
  553. WARN_ON(!mutex_is_locked(&efx->mac_lock));
  554. WARN_ON(!LOOPBACK_INTERNAL(efx));
  555. efx->link_state.fd = true;
  556. efx->link_state.fc = efx->wanted_fc;
  557. efx->link_state.up = true;
  558. if (efx->loopback_mode == LOOPBACK_GMAC)
  559. efx->link_state.speed = 1000;
  560. else
  561. efx->link_state.speed = 10000;
  562. return !efx_link_state_equal(&efx->link_state, &old_state);
  563. }
  564. static int falcon_reconfigure_port(struct efx_nic *efx)
  565. {
  566. int rc;
  567. WARN_ON(efx_nic_rev(efx) > EFX_REV_FALCON_B0);
  568. /* Poll the PHY link state *before* reconfiguring it. This means we
  569. * will pick up the correct speed (in loopback) to select the correct
  570. * MAC.
  571. */
  572. if (LOOPBACK_INTERNAL(efx))
  573. falcon_loopback_link_poll(efx);
  574. else
  575. efx->phy_op->poll(efx);
  576. falcon_stop_nic_stats(efx);
  577. falcon_deconfigure_mac_wrapper(efx);
  578. falcon_switch_mac(efx);
  579. efx->phy_op->reconfigure(efx);
  580. rc = efx->mac_op->reconfigure(efx);
  581. BUG_ON(rc);
  582. falcon_start_nic_stats(efx);
  583. /* Synchronise efx->link_state with the kernel */
  584. efx_link_status_changed(efx);
  585. return 0;
  586. }
  587. /**************************************************************************
  588. *
  589. * PHY access via GMII
  590. *
  591. **************************************************************************
  592. */
  593. /* Wait for GMII access to complete */
  594. static int falcon_gmii_wait(struct efx_nic *efx)
  595. {
  596. efx_oword_t md_stat;
  597. int count;
  598. /* wait upto 50ms - taken max from datasheet */
  599. for (count = 0; count < 5000; count++) {
  600. efx_reado(efx, &md_stat, FR_AB_MD_STAT);
  601. if (EFX_OWORD_FIELD(md_stat, FRF_AB_MD_BSY) == 0) {
  602. if (EFX_OWORD_FIELD(md_stat, FRF_AB_MD_LNFL) != 0 ||
  603. EFX_OWORD_FIELD(md_stat, FRF_AB_MD_BSERR) != 0) {
  604. netif_err(efx, hw, efx->net_dev,
  605. "error from GMII access "
  606. EFX_OWORD_FMT"\n",
  607. EFX_OWORD_VAL(md_stat));
  608. return -EIO;
  609. }
  610. return 0;
  611. }
  612. udelay(10);
  613. }
  614. netif_err(efx, hw, efx->net_dev, "timed out waiting for GMII\n");
  615. return -ETIMEDOUT;
  616. }
  617. /* Write an MDIO register of a PHY connected to Falcon. */
  618. static int falcon_mdio_write(struct net_device *net_dev,
  619. int prtad, int devad, u16 addr, u16 value)
  620. {
  621. struct efx_nic *efx = netdev_priv(net_dev);
  622. efx_oword_t reg;
  623. int rc;
  624. netif_vdbg(efx, hw, efx->net_dev,
  625. "writing MDIO %d register %d.%d with 0x%04x\n",
  626. prtad, devad, addr, value);
  627. mutex_lock(&efx->mdio_lock);
  628. /* Check MDIO not currently being accessed */
  629. rc = falcon_gmii_wait(efx);
  630. if (rc)
  631. goto out;
  632. /* Write the address/ID register */
  633. EFX_POPULATE_OWORD_1(reg, FRF_AB_MD_PHY_ADR, addr);
  634. efx_writeo(efx, &reg, FR_AB_MD_PHY_ADR);
  635. EFX_POPULATE_OWORD_2(reg, FRF_AB_MD_PRT_ADR, prtad,
  636. FRF_AB_MD_DEV_ADR, devad);
  637. efx_writeo(efx, &reg, FR_AB_MD_ID);
  638. /* Write data */
  639. EFX_POPULATE_OWORD_1(reg, FRF_AB_MD_TXD, value);
  640. efx_writeo(efx, &reg, FR_AB_MD_TXD);
  641. EFX_POPULATE_OWORD_2(reg,
  642. FRF_AB_MD_WRC, 1,
  643. FRF_AB_MD_GC, 0);
  644. efx_writeo(efx, &reg, FR_AB_MD_CS);
  645. /* Wait for data to be written */
  646. rc = falcon_gmii_wait(efx);
  647. if (rc) {
  648. /* Abort the write operation */
  649. EFX_POPULATE_OWORD_2(reg,
  650. FRF_AB_MD_WRC, 0,
  651. FRF_AB_MD_GC, 1);
  652. efx_writeo(efx, &reg, FR_AB_MD_CS);
  653. udelay(10);
  654. }
  655. out:
  656. mutex_unlock(&efx->mdio_lock);
  657. return rc;
  658. }
  659. /* Read an MDIO register of a PHY connected to Falcon. */
  660. static int falcon_mdio_read(struct net_device *net_dev,
  661. int prtad, int devad, u16 addr)
  662. {
  663. struct efx_nic *efx = netdev_priv(net_dev);
  664. efx_oword_t reg;
  665. int rc;
  666. mutex_lock(&efx->mdio_lock);
  667. /* Check MDIO not currently being accessed */
  668. rc = falcon_gmii_wait(efx);
  669. if (rc)
  670. goto out;
  671. EFX_POPULATE_OWORD_1(reg, FRF_AB_MD_PHY_ADR, addr);
  672. efx_writeo(efx, &reg, FR_AB_MD_PHY_ADR);
  673. EFX_POPULATE_OWORD_2(reg, FRF_AB_MD_PRT_ADR, prtad,
  674. FRF_AB_MD_DEV_ADR, devad);
  675. efx_writeo(efx, &reg, FR_AB_MD_ID);
  676. /* Request data to be read */
  677. EFX_POPULATE_OWORD_2(reg, FRF_AB_MD_RDC, 1, FRF_AB_MD_GC, 0);
  678. efx_writeo(efx, &reg, FR_AB_MD_CS);
  679. /* Wait for data to become available */
  680. rc = falcon_gmii_wait(efx);
  681. if (rc == 0) {
  682. efx_reado(efx, &reg, FR_AB_MD_RXD);
  683. rc = EFX_OWORD_FIELD(reg, FRF_AB_MD_RXD);
  684. netif_vdbg(efx, hw, efx->net_dev,
  685. "read from MDIO %d register %d.%d, got %04x\n",
  686. prtad, devad, addr, rc);
  687. } else {
  688. /* Abort the read operation */
  689. EFX_POPULATE_OWORD_2(reg,
  690. FRF_AB_MD_RIC, 0,
  691. FRF_AB_MD_GC, 1);
  692. efx_writeo(efx, &reg, FR_AB_MD_CS);
  693. netif_dbg(efx, hw, efx->net_dev,
  694. "read from MDIO %d register %d.%d, got error %d\n",
  695. prtad, devad, addr, rc);
  696. }
  697. out:
  698. mutex_unlock(&efx->mdio_lock);
  699. return rc;
  700. }
  701. static void falcon_clock_mac(struct efx_nic *efx)
  702. {
  703. unsigned strap_val;
  704. efx_oword_t nic_stat;
  705. /* Configure the NIC generated MAC clock correctly */
  706. efx_reado(efx, &nic_stat, FR_AB_NIC_STAT);
  707. strap_val = EFX_IS10G(efx) ? 5 : 3;
  708. if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0) {
  709. EFX_SET_OWORD_FIELD(nic_stat, FRF_BB_EE_STRAP_EN, 1);
  710. EFX_SET_OWORD_FIELD(nic_stat, FRF_BB_EE_STRAP, strap_val);
  711. efx_writeo(efx, &nic_stat, FR_AB_NIC_STAT);
  712. } else {
  713. /* Falcon A1 does not support 1G/10G speed switching
  714. * and must not be used with a PHY that does. */
  715. BUG_ON(EFX_OWORD_FIELD(nic_stat, FRF_AB_STRAP_PINS) !=
  716. strap_val);
  717. }
  718. }
  719. static void falcon_switch_mac(struct efx_nic *efx)
  720. {
  721. struct efx_mac_operations *old_mac_op = efx->mac_op;
  722. struct falcon_nic_data *nic_data = efx->nic_data;
  723. unsigned int stats_done_offset;
  724. WARN_ON(!mutex_is_locked(&efx->mac_lock));
  725. WARN_ON(nic_data->stats_disable_count == 0);
  726. efx->mac_op = (EFX_IS10G(efx) ?
  727. &falcon_xmac_operations : &falcon_gmac_operations);
  728. if (EFX_IS10G(efx))
  729. stats_done_offset = XgDmaDone_offset;
  730. else
  731. stats_done_offset = GDmaDone_offset;
  732. nic_data->stats_dma_done = efx->stats_buffer.addr + stats_done_offset;
  733. if (old_mac_op == efx->mac_op)
  734. return;
  735. falcon_clock_mac(efx);
  736. netif_dbg(efx, hw, efx->net_dev, "selected %cMAC\n",
  737. EFX_IS10G(efx) ? 'X' : 'G');
  738. /* Not all macs support a mac-level link state */
  739. efx->xmac_poll_required = false;
  740. falcon_reset_macs(efx);
  741. }
  742. /* This call is responsible for hooking in the MAC and PHY operations */
  743. static int falcon_probe_port(struct efx_nic *efx)
  744. {
  745. int rc;
  746. switch (efx->phy_type) {
  747. case PHY_TYPE_SFX7101:
  748. efx->phy_op = &falcon_sfx7101_phy_ops;
  749. break;
  750. case PHY_TYPE_SFT9001A:
  751. case PHY_TYPE_SFT9001B:
  752. efx->phy_op = &falcon_sft9001_phy_ops;
  753. break;
  754. case PHY_TYPE_QT2022C2:
  755. case PHY_TYPE_QT2025C:
  756. efx->phy_op = &falcon_qt202x_phy_ops;
  757. break;
  758. default:
  759. netif_err(efx, probe, efx->net_dev, "Unknown PHY type %d\n",
  760. efx->phy_type);
  761. return -ENODEV;
  762. }
  763. /* Fill out MDIO structure and loopback modes */
  764. efx->mdio.mdio_read = falcon_mdio_read;
  765. efx->mdio.mdio_write = falcon_mdio_write;
  766. rc = efx->phy_op->probe(efx);
  767. if (rc != 0)
  768. return rc;
  769. /* Initial assumption */
  770. efx->link_state.speed = 10000;
  771. efx->link_state.fd = true;
  772. /* Hardware flow ctrl. FalconA RX FIFO too small for pause generation */
  773. if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0)
  774. efx->wanted_fc = EFX_FC_RX | EFX_FC_TX;
  775. else
  776. efx->wanted_fc = EFX_FC_RX;
  777. if (efx->mdio.mmds & MDIO_DEVS_AN)
  778. efx->wanted_fc |= EFX_FC_AUTO;
  779. /* Allocate buffer for stats */
  780. rc = efx_nic_alloc_buffer(efx, &efx->stats_buffer,
  781. FALCON_MAC_STATS_SIZE);
  782. if (rc)
  783. return rc;
  784. netif_dbg(efx, probe, efx->net_dev,
  785. "stats buffer at %llx (virt %p phys %llx)\n",
  786. (u64)efx->stats_buffer.dma_addr,
  787. efx->stats_buffer.addr,
  788. (u64)virt_to_phys(efx->stats_buffer.addr));
  789. return 0;
  790. }
  791. static void falcon_remove_port(struct efx_nic *efx)
  792. {
  793. efx->phy_op->remove(efx);
  794. efx_nic_free_buffer(efx, &efx->stats_buffer);
  795. }
  796. /**************************************************************************
  797. *
  798. * Falcon test code
  799. *
  800. **************************************************************************/
  801. static int
  802. falcon_read_nvram(struct efx_nic *efx, struct falcon_nvconfig *nvconfig_out)
  803. {
  804. struct falcon_nvconfig *nvconfig;
  805. struct efx_spi_device *spi;
  806. void *region;
  807. int rc, magic_num, struct_ver;
  808. __le16 *word, *limit;
  809. u32 csum;
  810. spi = efx->spi_flash ? efx->spi_flash : efx->spi_eeprom;
  811. if (!spi)
  812. return -EINVAL;
  813. region = kmalloc(FALCON_NVCONFIG_END, GFP_KERNEL);
  814. if (!region)
  815. return -ENOMEM;
  816. nvconfig = region + FALCON_NVCONFIG_OFFSET;
  817. mutex_lock(&efx->spi_lock);
  818. rc = falcon_spi_read(efx, spi, 0, FALCON_NVCONFIG_END, NULL, region);
  819. mutex_unlock(&efx->spi_lock);
  820. if (rc) {
  821. netif_err(efx, hw, efx->net_dev, "Failed to read %s\n",
  822. efx->spi_flash ? "flash" : "EEPROM");
  823. rc = -EIO;
  824. goto out;
  825. }
  826. magic_num = le16_to_cpu(nvconfig->board_magic_num);
  827. struct_ver = le16_to_cpu(nvconfig->board_struct_ver);
  828. rc = -EINVAL;
  829. if (magic_num != FALCON_NVCONFIG_BOARD_MAGIC_NUM) {
  830. netif_err(efx, hw, efx->net_dev,
  831. "NVRAM bad magic 0x%x\n", magic_num);
  832. goto out;
  833. }
  834. if (struct_ver < 2) {
  835. netif_err(efx, hw, efx->net_dev,
  836. "NVRAM has ancient version 0x%x\n", struct_ver);
  837. goto out;
  838. } else if (struct_ver < 4) {
  839. word = &nvconfig->board_magic_num;
  840. limit = (__le16 *) (nvconfig + 1);
  841. } else {
  842. word = region;
  843. limit = region + FALCON_NVCONFIG_END;
  844. }
  845. for (csum = 0; word < limit; ++word)
  846. csum += le16_to_cpu(*word);
  847. if (~csum & 0xffff) {
  848. netif_err(efx, hw, efx->net_dev,
  849. "NVRAM has incorrect checksum\n");
  850. goto out;
  851. }
  852. rc = 0;
  853. if (nvconfig_out)
  854. memcpy(nvconfig_out, nvconfig, sizeof(*nvconfig));
  855. out:
  856. kfree(region);
  857. return rc;
  858. }
  859. static int falcon_test_nvram(struct efx_nic *efx)
  860. {
  861. return falcon_read_nvram(efx, NULL);
  862. }
  863. static const struct efx_nic_register_test falcon_b0_register_tests[] = {
  864. { FR_AZ_ADR_REGION,
  865. EFX_OWORD32(0x0003FFFF, 0x0003FFFF, 0x0003FFFF, 0x0003FFFF) },
  866. { FR_AZ_RX_CFG,
  867. EFX_OWORD32(0xFFFFFFFE, 0x00017FFF, 0x00000000, 0x00000000) },
  868. { FR_AZ_TX_CFG,
  869. EFX_OWORD32(0x7FFF0037, 0x00000000, 0x00000000, 0x00000000) },
  870. { FR_AZ_TX_RESERVED,
  871. EFX_OWORD32(0xFFFEFE80, 0x1FFFFFFF, 0x020000FE, 0x007FFFFF) },
  872. { FR_AB_MAC_CTRL,
  873. EFX_OWORD32(0xFFFF0000, 0x00000000, 0x00000000, 0x00000000) },
  874. { FR_AZ_SRM_TX_DC_CFG,
  875. EFX_OWORD32(0x001FFFFF, 0x00000000, 0x00000000, 0x00000000) },
  876. { FR_AZ_RX_DC_CFG,
  877. EFX_OWORD32(0x0000000F, 0x00000000, 0x00000000, 0x00000000) },
  878. { FR_AZ_RX_DC_PF_WM,
  879. EFX_OWORD32(0x000003FF, 0x00000000, 0x00000000, 0x00000000) },
  880. { FR_BZ_DP_CTRL,
  881. EFX_OWORD32(0x00000FFF, 0x00000000, 0x00000000, 0x00000000) },
  882. { FR_AB_GM_CFG2,
  883. EFX_OWORD32(0x00007337, 0x00000000, 0x00000000, 0x00000000) },
  884. { FR_AB_GMF_CFG0,
  885. EFX_OWORD32(0x00001F1F, 0x00000000, 0x00000000, 0x00000000) },
  886. { FR_AB_XM_GLB_CFG,
  887. EFX_OWORD32(0x00000C68, 0x00000000, 0x00000000, 0x00000000) },
  888. { FR_AB_XM_TX_CFG,
  889. EFX_OWORD32(0x00080164, 0x00000000, 0x00000000, 0x00000000) },
  890. { FR_AB_XM_RX_CFG,
  891. EFX_OWORD32(0x07100A0C, 0x00000000, 0x00000000, 0x00000000) },
  892. { FR_AB_XM_RX_PARAM,
  893. EFX_OWORD32(0x00001FF8, 0x00000000, 0x00000000, 0x00000000) },
  894. { FR_AB_XM_FC,
  895. EFX_OWORD32(0xFFFF0001, 0x00000000, 0x00000000, 0x00000000) },
  896. { FR_AB_XM_ADR_LO,
  897. EFX_OWORD32(0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000) },
  898. { FR_AB_XX_SD_CTL,
  899. EFX_OWORD32(0x0003FF0F, 0x00000000, 0x00000000, 0x00000000) },
  900. };
  901. static int falcon_b0_test_registers(struct efx_nic *efx)
  902. {
  903. return efx_nic_test_registers(efx, falcon_b0_register_tests,
  904. ARRAY_SIZE(falcon_b0_register_tests));
  905. }
  906. /**************************************************************************
  907. *
  908. * Device reset
  909. *
  910. **************************************************************************
  911. */
  912. /* Resets NIC to known state. This routine must be called in process
  913. * context and is allowed to sleep. */
  914. static int falcon_reset_hw(struct efx_nic *efx, enum reset_type method)
  915. {
  916. struct falcon_nic_data *nic_data = efx->nic_data;
  917. efx_oword_t glb_ctl_reg_ker;
  918. int rc;
  919. netif_dbg(efx, hw, efx->net_dev, "performing %s hardware reset\n",
  920. RESET_TYPE(method));
  921. /* Initiate device reset */
  922. if (method == RESET_TYPE_WORLD) {
  923. rc = pci_save_state(efx->pci_dev);
  924. if (rc) {
  925. netif_err(efx, drv, efx->net_dev,
  926. "failed to backup PCI state of primary "
  927. "function prior to hardware reset\n");
  928. goto fail1;
  929. }
  930. if (efx_nic_is_dual_func(efx)) {
  931. rc = pci_save_state(nic_data->pci_dev2);
  932. if (rc) {
  933. netif_err(efx, drv, efx->net_dev,
  934. "failed to backup PCI state of "
  935. "secondary function prior to "
  936. "hardware reset\n");
  937. goto fail2;
  938. }
  939. }
  940. EFX_POPULATE_OWORD_2(glb_ctl_reg_ker,
  941. FRF_AB_EXT_PHY_RST_DUR,
  942. FFE_AB_EXT_PHY_RST_DUR_10240US,
  943. FRF_AB_SWRST, 1);
  944. } else {
  945. EFX_POPULATE_OWORD_7(glb_ctl_reg_ker,
  946. /* exclude PHY from "invisible" reset */
  947. FRF_AB_EXT_PHY_RST_CTL,
  948. method == RESET_TYPE_INVISIBLE,
  949. /* exclude EEPROM/flash and PCIe */
  950. FRF_AB_PCIE_CORE_RST_CTL, 1,
  951. FRF_AB_PCIE_NSTKY_RST_CTL, 1,
  952. FRF_AB_PCIE_SD_RST_CTL, 1,
  953. FRF_AB_EE_RST_CTL, 1,
  954. FRF_AB_EXT_PHY_RST_DUR,
  955. FFE_AB_EXT_PHY_RST_DUR_10240US,
  956. FRF_AB_SWRST, 1);
  957. }
  958. efx_writeo(efx, &glb_ctl_reg_ker, FR_AB_GLB_CTL);
  959. netif_dbg(efx, hw, efx->net_dev, "waiting for hardware reset\n");
  960. schedule_timeout_uninterruptible(HZ / 20);
  961. /* Restore PCI configuration if needed */
  962. if (method == RESET_TYPE_WORLD) {
  963. if (efx_nic_is_dual_func(efx)) {
  964. rc = pci_restore_state(nic_data->pci_dev2);
  965. if (rc) {
  966. netif_err(efx, drv, efx->net_dev,
  967. "failed to restore PCI config for "
  968. "the secondary function\n");
  969. goto fail3;
  970. }
  971. }
  972. rc = pci_restore_state(efx->pci_dev);
  973. if (rc) {
  974. netif_err(efx, drv, efx->net_dev,
  975. "failed to restore PCI config for the "
  976. "primary function\n");
  977. goto fail4;
  978. }
  979. netif_dbg(efx, drv, efx->net_dev,
  980. "successfully restored PCI config\n");
  981. }
  982. /* Assert that reset complete */
  983. efx_reado(efx, &glb_ctl_reg_ker, FR_AB_GLB_CTL);
  984. if (EFX_OWORD_FIELD(glb_ctl_reg_ker, FRF_AB_SWRST) != 0) {
  985. rc = -ETIMEDOUT;
  986. netif_err(efx, hw, efx->net_dev,
  987. "timed out waiting for hardware reset\n");
  988. goto fail5;
  989. }
  990. netif_dbg(efx, hw, efx->net_dev, "hardware reset complete\n");
  991. return 0;
  992. /* pci_save_state() and pci_restore_state() MUST be called in pairs */
  993. fail2:
  994. fail3:
  995. pci_restore_state(efx->pci_dev);
  996. fail1:
  997. fail4:
  998. fail5:
  999. return rc;
  1000. }
  1001. static void falcon_monitor(struct efx_nic *efx)
  1002. {
  1003. bool link_changed;
  1004. int rc;
  1005. BUG_ON(!mutex_is_locked(&efx->mac_lock));
  1006. rc = falcon_board(efx)->type->monitor(efx);
  1007. if (rc) {
  1008. netif_err(efx, hw, efx->net_dev,
  1009. "Board sensor %s; shutting down PHY\n",
  1010. (rc == -ERANGE) ? "reported fault" : "failed");
  1011. efx->phy_mode |= PHY_MODE_LOW_POWER;
  1012. rc = __efx_reconfigure_port(efx);
  1013. WARN_ON(rc);
  1014. }
  1015. if (LOOPBACK_INTERNAL(efx))
  1016. link_changed = falcon_loopback_link_poll(efx);
  1017. else
  1018. link_changed = efx->phy_op->poll(efx);
  1019. if (link_changed) {
  1020. falcon_stop_nic_stats(efx);
  1021. falcon_deconfigure_mac_wrapper(efx);
  1022. falcon_switch_mac(efx);
  1023. rc = efx->mac_op->reconfigure(efx);
  1024. BUG_ON(rc);
  1025. falcon_start_nic_stats(efx);
  1026. efx_link_status_changed(efx);
  1027. }
  1028. if (EFX_IS10G(efx))
  1029. falcon_poll_xmac(efx);
  1030. }
  1031. /* Zeroes out the SRAM contents. This routine must be called in
  1032. * process context and is allowed to sleep.
  1033. */
  1034. static int falcon_reset_sram(struct efx_nic *efx)
  1035. {
  1036. efx_oword_t srm_cfg_reg_ker, gpio_cfg_reg_ker;
  1037. int count;
  1038. /* Set the SRAM wake/sleep GPIO appropriately. */
  1039. efx_reado(efx, &gpio_cfg_reg_ker, FR_AB_GPIO_CTL);
  1040. EFX_SET_OWORD_FIELD(gpio_cfg_reg_ker, FRF_AB_GPIO1_OEN, 1);
  1041. EFX_SET_OWORD_FIELD(gpio_cfg_reg_ker, FRF_AB_GPIO1_OUT, 1);
  1042. efx_writeo(efx, &gpio_cfg_reg_ker, FR_AB_GPIO_CTL);
  1043. /* Initiate SRAM reset */
  1044. EFX_POPULATE_OWORD_2(srm_cfg_reg_ker,
  1045. FRF_AZ_SRM_INIT_EN, 1,
  1046. FRF_AZ_SRM_NB_SZ, 0);
  1047. efx_writeo(efx, &srm_cfg_reg_ker, FR_AZ_SRM_CFG);
  1048. /* Wait for SRAM reset to complete */
  1049. count = 0;
  1050. do {
  1051. netif_dbg(efx, hw, efx->net_dev,
  1052. "waiting for SRAM reset (attempt %d)...\n", count);
  1053. /* SRAM reset is slow; expect around 16ms */
  1054. schedule_timeout_uninterruptible(HZ / 50);
  1055. /* Check for reset complete */
  1056. efx_reado(efx, &srm_cfg_reg_ker, FR_AZ_SRM_CFG);
  1057. if (!EFX_OWORD_FIELD(srm_cfg_reg_ker, FRF_AZ_SRM_INIT_EN)) {
  1058. netif_dbg(efx, hw, efx->net_dev,
  1059. "SRAM reset complete\n");
  1060. return 0;
  1061. }
  1062. } while (++count < 20); /* wait upto 0.4 sec */
  1063. netif_err(efx, hw, efx->net_dev, "timed out waiting for SRAM reset\n");
  1064. return -ETIMEDOUT;
  1065. }
  1066. static int falcon_spi_device_init(struct efx_nic *efx,
  1067. struct efx_spi_device **spi_device_ret,
  1068. unsigned int device_id, u32 device_type)
  1069. {
  1070. struct efx_spi_device *spi_device;
  1071. if (device_type != 0) {
  1072. spi_device = kzalloc(sizeof(*spi_device), GFP_KERNEL);
  1073. if (!spi_device)
  1074. return -ENOMEM;
  1075. spi_device->device_id = device_id;
  1076. spi_device->size =
  1077. 1 << SPI_DEV_TYPE_FIELD(device_type, SPI_DEV_TYPE_SIZE);
  1078. spi_device->addr_len =
  1079. SPI_DEV_TYPE_FIELD(device_type, SPI_DEV_TYPE_ADDR_LEN);
  1080. spi_device->munge_address = (spi_device->size == 1 << 9 &&
  1081. spi_device->addr_len == 1);
  1082. spi_device->erase_command =
  1083. SPI_DEV_TYPE_FIELD(device_type, SPI_DEV_TYPE_ERASE_CMD);
  1084. spi_device->erase_size =
  1085. 1 << SPI_DEV_TYPE_FIELD(device_type,
  1086. SPI_DEV_TYPE_ERASE_SIZE);
  1087. spi_device->block_size =
  1088. 1 << SPI_DEV_TYPE_FIELD(device_type,
  1089. SPI_DEV_TYPE_BLOCK_SIZE);
  1090. } else {
  1091. spi_device = NULL;
  1092. }
  1093. kfree(*spi_device_ret);
  1094. *spi_device_ret = spi_device;
  1095. return 0;
  1096. }
  1097. static void falcon_remove_spi_devices(struct efx_nic *efx)
  1098. {
  1099. kfree(efx->spi_eeprom);
  1100. efx->spi_eeprom = NULL;
  1101. kfree(efx->spi_flash);
  1102. efx->spi_flash = NULL;
  1103. }
  1104. /* Extract non-volatile configuration */
  1105. static int falcon_probe_nvconfig(struct efx_nic *efx)
  1106. {
  1107. struct falcon_nvconfig *nvconfig;
  1108. int board_rev;
  1109. int rc;
  1110. nvconfig = kmalloc(sizeof(*nvconfig), GFP_KERNEL);
  1111. if (!nvconfig)
  1112. return -ENOMEM;
  1113. rc = falcon_read_nvram(efx, nvconfig);
  1114. if (rc == -EINVAL) {
  1115. netif_err(efx, probe, efx->net_dev,
  1116. "NVRAM is invalid therefore using defaults\n");
  1117. efx->phy_type = PHY_TYPE_NONE;
  1118. efx->mdio.prtad = MDIO_PRTAD_NONE;
  1119. board_rev = 0;
  1120. rc = 0;
  1121. } else if (rc) {
  1122. goto fail1;
  1123. } else {
  1124. struct falcon_nvconfig_board_v2 *v2 = &nvconfig->board_v2;
  1125. struct falcon_nvconfig_board_v3 *v3 = &nvconfig->board_v3;
  1126. efx->phy_type = v2->port0_phy_type;
  1127. efx->mdio.prtad = v2->port0_phy_addr;
  1128. board_rev = le16_to_cpu(v2->board_revision);
  1129. if (le16_to_cpu(nvconfig->board_struct_ver) >= 3) {
  1130. rc = falcon_spi_device_init(
  1131. efx, &efx->spi_flash, FFE_AB_SPI_DEVICE_FLASH,
  1132. le32_to_cpu(v3->spi_device_type
  1133. [FFE_AB_SPI_DEVICE_FLASH]));
  1134. if (rc)
  1135. goto fail2;
  1136. rc = falcon_spi_device_init(
  1137. efx, &efx->spi_eeprom, FFE_AB_SPI_DEVICE_EEPROM,
  1138. le32_to_cpu(v3->spi_device_type
  1139. [FFE_AB_SPI_DEVICE_EEPROM]));
  1140. if (rc)
  1141. goto fail2;
  1142. }
  1143. }
  1144. /* Read the MAC addresses */
  1145. memcpy(efx->mac_address, nvconfig->mac_address[0], ETH_ALEN);
  1146. netif_dbg(efx, probe, efx->net_dev, "PHY is %d phy_id %d\n",
  1147. efx->phy_type, efx->mdio.prtad);
  1148. rc = falcon_probe_board(efx, board_rev);
  1149. if (rc)
  1150. goto fail2;
  1151. kfree(nvconfig);
  1152. return 0;
  1153. fail2:
  1154. falcon_remove_spi_devices(efx);
  1155. fail1:
  1156. kfree(nvconfig);
  1157. return rc;
  1158. }
  1159. /* Probe all SPI devices on the NIC */
  1160. static void falcon_probe_spi_devices(struct efx_nic *efx)
  1161. {
  1162. efx_oword_t nic_stat, gpio_ctl, ee_vpd_cfg;
  1163. int boot_dev;
  1164. efx_reado(efx, &gpio_ctl, FR_AB_GPIO_CTL);
  1165. efx_reado(efx, &nic_stat, FR_AB_NIC_STAT);
  1166. efx_reado(efx, &ee_vpd_cfg, FR_AB_EE_VPD_CFG0);
  1167. if (EFX_OWORD_FIELD(gpio_ctl, FRF_AB_GPIO3_PWRUP_VALUE)) {
  1168. boot_dev = (EFX_OWORD_FIELD(nic_stat, FRF_AB_SF_PRST) ?
  1169. FFE_AB_SPI_DEVICE_FLASH : FFE_AB_SPI_DEVICE_EEPROM);
  1170. netif_dbg(efx, probe, efx->net_dev, "Booted from %s\n",
  1171. boot_dev == FFE_AB_SPI_DEVICE_FLASH ?
  1172. "flash" : "EEPROM");
  1173. } else {
  1174. /* Disable VPD and set clock dividers to safe
  1175. * values for initial programming. */
  1176. boot_dev = -1;
  1177. netif_dbg(efx, probe, efx->net_dev,
  1178. "Booted from internal ASIC settings;"
  1179. " setting SPI config\n");
  1180. EFX_POPULATE_OWORD_3(ee_vpd_cfg, FRF_AB_EE_VPD_EN, 0,
  1181. /* 125 MHz / 7 ~= 20 MHz */
  1182. FRF_AB_EE_SF_CLOCK_DIV, 7,
  1183. /* 125 MHz / 63 ~= 2 MHz */
  1184. FRF_AB_EE_EE_CLOCK_DIV, 63);
  1185. efx_writeo(efx, &ee_vpd_cfg, FR_AB_EE_VPD_CFG0);
  1186. }
  1187. if (boot_dev == FFE_AB_SPI_DEVICE_FLASH)
  1188. falcon_spi_device_init(efx, &efx->spi_flash,
  1189. FFE_AB_SPI_DEVICE_FLASH,
  1190. default_flash_type);
  1191. if (boot_dev == FFE_AB_SPI_DEVICE_EEPROM)
  1192. falcon_spi_device_init(efx, &efx->spi_eeprom,
  1193. FFE_AB_SPI_DEVICE_EEPROM,
  1194. large_eeprom_type);
  1195. }
  1196. static int falcon_probe_nic(struct efx_nic *efx)
  1197. {
  1198. struct falcon_nic_data *nic_data;
  1199. struct falcon_board *board;
  1200. int rc;
  1201. /* Allocate storage for hardware specific data */
  1202. nic_data = kzalloc(sizeof(*nic_data), GFP_KERNEL);
  1203. if (!nic_data)
  1204. return -ENOMEM;
  1205. efx->nic_data = nic_data;
  1206. rc = -ENODEV;
  1207. if (efx_nic_fpga_ver(efx) != 0) {
  1208. netif_err(efx, probe, efx->net_dev,
  1209. "Falcon FPGA not supported\n");
  1210. goto fail1;
  1211. }
  1212. if (efx_nic_rev(efx) <= EFX_REV_FALCON_A1) {
  1213. efx_oword_t nic_stat;
  1214. struct pci_dev *dev;
  1215. u8 pci_rev = efx->pci_dev->revision;
  1216. if ((pci_rev == 0xff) || (pci_rev == 0)) {
  1217. netif_err(efx, probe, efx->net_dev,
  1218. "Falcon rev A0 not supported\n");
  1219. goto fail1;
  1220. }
  1221. efx_reado(efx, &nic_stat, FR_AB_NIC_STAT);
  1222. if (EFX_OWORD_FIELD(nic_stat, FRF_AB_STRAP_10G) == 0) {
  1223. netif_err(efx, probe, efx->net_dev,
  1224. "Falcon rev A1 1G not supported\n");
  1225. goto fail1;
  1226. }
  1227. if (EFX_OWORD_FIELD(nic_stat, FRF_AA_STRAP_PCIE) == 0) {
  1228. netif_err(efx, probe, efx->net_dev,
  1229. "Falcon rev A1 PCI-X not supported\n");
  1230. goto fail1;
  1231. }
  1232. dev = pci_dev_get(efx->pci_dev);
  1233. while ((dev = pci_get_device(EFX_VENDID_SFC, FALCON_A_S_DEVID,
  1234. dev))) {
  1235. if (dev->bus == efx->pci_dev->bus &&
  1236. dev->devfn == efx->pci_dev->devfn + 1) {
  1237. nic_data->pci_dev2 = dev;
  1238. break;
  1239. }
  1240. }
  1241. if (!nic_data->pci_dev2) {
  1242. netif_err(efx, probe, efx->net_dev,
  1243. "failed to find secondary function\n");
  1244. rc = -ENODEV;
  1245. goto fail2;
  1246. }
  1247. }
  1248. /* Now we can reset the NIC */
  1249. rc = falcon_reset_hw(efx, RESET_TYPE_ALL);
  1250. if (rc) {
  1251. netif_err(efx, probe, efx->net_dev, "failed to reset NIC\n");
  1252. goto fail3;
  1253. }
  1254. /* Allocate memory for INT_KER */
  1255. rc = efx_nic_alloc_buffer(efx, &efx->irq_status, sizeof(efx_oword_t));
  1256. if (rc)
  1257. goto fail4;
  1258. BUG_ON(efx->irq_status.dma_addr & 0x0f);
  1259. netif_dbg(efx, probe, efx->net_dev,
  1260. "INT_KER at %llx (virt %p phys %llx)\n",
  1261. (u64)efx->irq_status.dma_addr,
  1262. efx->irq_status.addr,
  1263. (u64)virt_to_phys(efx->irq_status.addr));
  1264. falcon_probe_spi_devices(efx);
  1265. /* Read in the non-volatile configuration */
  1266. rc = falcon_probe_nvconfig(efx);
  1267. if (rc)
  1268. goto fail5;
  1269. /* Initialise I2C adapter */
  1270. board = falcon_board(efx);
  1271. board->i2c_adap.owner = THIS_MODULE;
  1272. board->i2c_data = falcon_i2c_bit_operations;
  1273. board->i2c_data.data = efx;
  1274. board->i2c_adap.algo_data = &board->i2c_data;
  1275. board->i2c_adap.dev.parent = &efx->pci_dev->dev;
  1276. strlcpy(board->i2c_adap.name, "SFC4000 GPIO",
  1277. sizeof(board->i2c_adap.name));
  1278. rc = i2c_bit_add_bus(&board->i2c_adap);
  1279. if (rc)
  1280. goto fail5;
  1281. rc = falcon_board(efx)->type->init(efx);
  1282. if (rc) {
  1283. netif_err(efx, probe, efx->net_dev,
  1284. "failed to initialise board\n");
  1285. goto fail6;
  1286. }
  1287. nic_data->stats_disable_count = 1;
  1288. setup_timer(&nic_data->stats_timer, &falcon_stats_timer_func,
  1289. (unsigned long)efx);
  1290. return 0;
  1291. fail6:
  1292. BUG_ON(i2c_del_adapter(&board->i2c_adap));
  1293. memset(&board->i2c_adap, 0, sizeof(board->i2c_adap));
  1294. fail5:
  1295. falcon_remove_spi_devices(efx);
  1296. efx_nic_free_buffer(efx, &efx->irq_status);
  1297. fail4:
  1298. fail3:
  1299. if (nic_data->pci_dev2) {
  1300. pci_dev_put(nic_data->pci_dev2);
  1301. nic_data->pci_dev2 = NULL;
  1302. }
  1303. fail2:
  1304. fail1:
  1305. kfree(efx->nic_data);
  1306. return rc;
  1307. }
  1308. static void falcon_init_rx_cfg(struct efx_nic *efx)
  1309. {
  1310. /* Prior to Siena the RX DMA engine will split each frame at
  1311. * intervals of RX_USR_BUF_SIZE (32-byte units). We set it to
  1312. * be so large that that never happens. */
  1313. const unsigned huge_buf_size = (3 * 4096) >> 5;
  1314. /* RX control FIFO thresholds (32 entries) */
  1315. const unsigned ctrl_xon_thr = 20;
  1316. const unsigned ctrl_xoff_thr = 25;
  1317. /* RX data FIFO thresholds (256-byte units; size varies) */
  1318. int data_xon_thr = efx_nic_rx_xon_thresh >> 8;
  1319. int data_xoff_thr = efx_nic_rx_xoff_thresh >> 8;
  1320. efx_oword_t reg;
  1321. efx_reado(efx, &reg, FR_AZ_RX_CFG);
  1322. if (efx_nic_rev(efx) <= EFX_REV_FALCON_A1) {
  1323. /* Data FIFO size is 5.5K */
  1324. if (data_xon_thr < 0)
  1325. data_xon_thr = 512 >> 8;
  1326. if (data_xoff_thr < 0)
  1327. data_xoff_thr = 2048 >> 8;
  1328. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_DESC_PUSH_EN, 0);
  1329. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_USR_BUF_SIZE,
  1330. huge_buf_size);
  1331. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XON_MAC_TH, data_xon_thr);
  1332. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XOFF_MAC_TH, data_xoff_thr);
  1333. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XON_TX_TH, ctrl_xon_thr);
  1334. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XOFF_TX_TH, ctrl_xoff_thr);
  1335. } else {
  1336. /* Data FIFO size is 80K; register fields moved */
  1337. if (data_xon_thr < 0)
  1338. data_xon_thr = 27648 >> 8; /* ~3*max MTU */
  1339. if (data_xoff_thr < 0)
  1340. data_xoff_thr = 54272 >> 8; /* ~80Kb - 3*max MTU */
  1341. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_DESC_PUSH_EN, 0);
  1342. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_USR_BUF_SIZE,
  1343. huge_buf_size);
  1344. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XON_MAC_TH, data_xon_thr);
  1345. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XOFF_MAC_TH, data_xoff_thr);
  1346. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XON_TX_TH, ctrl_xon_thr);
  1347. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XOFF_TX_TH, ctrl_xoff_thr);
  1348. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_INGR_EN, 1);
  1349. /* Enable hash insertion. This is broken for the
  1350. * 'Falcon' hash so also select Toeplitz TCP/IPv4 and
  1351. * IPv4 hashes. */
  1352. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_HASH_INSRT_HDR, 1);
  1353. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_HASH_ALG, 1);
  1354. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_IP_HASH, 1);
  1355. }
  1356. /* Always enable XOFF signal from RX FIFO. We enable
  1357. * or disable transmission of pause frames at the MAC. */
  1358. EFX_SET_OWORD_FIELD(reg, FRF_AZ_RX_XOFF_MAC_EN, 1);
  1359. efx_writeo(efx, &reg, FR_AZ_RX_CFG);
  1360. }
  1361. /* This call performs hardware-specific global initialisation, such as
  1362. * defining the descriptor cache sizes and number of RSS channels.
  1363. * It does not set up any buffers, descriptor rings or event queues.
  1364. */
  1365. static int falcon_init_nic(struct efx_nic *efx)
  1366. {
  1367. efx_oword_t temp;
  1368. int rc;
  1369. /* Use on-chip SRAM */
  1370. efx_reado(efx, &temp, FR_AB_NIC_STAT);
  1371. EFX_SET_OWORD_FIELD(temp, FRF_AB_ONCHIP_SRAM, 1);
  1372. efx_writeo(efx, &temp, FR_AB_NIC_STAT);
  1373. /* Set the source of the GMAC clock */
  1374. if (efx_nic_rev(efx) == EFX_REV_FALCON_B0) {
  1375. efx_reado(efx, &temp, FR_AB_GPIO_CTL);
  1376. EFX_SET_OWORD_FIELD(temp, FRF_AB_USE_NIC_CLK, true);
  1377. efx_writeo(efx, &temp, FR_AB_GPIO_CTL);
  1378. }
  1379. /* Select the correct MAC */
  1380. falcon_clock_mac(efx);
  1381. rc = falcon_reset_sram(efx);
  1382. if (rc)
  1383. return rc;
  1384. /* Clear the parity enables on the TX data fifos as
  1385. * they produce false parity errors because of timing issues
  1386. */
  1387. if (EFX_WORKAROUND_5129(efx)) {
  1388. efx_reado(efx, &temp, FR_AZ_CSR_SPARE);
  1389. EFX_SET_OWORD_FIELD(temp, FRF_AB_MEM_PERR_EN_TX_DATA, 0);
  1390. efx_writeo(efx, &temp, FR_AZ_CSR_SPARE);
  1391. }
  1392. if (EFX_WORKAROUND_7244(efx)) {
  1393. efx_reado(efx, &temp, FR_BZ_RX_FILTER_CTL);
  1394. EFX_SET_OWORD_FIELD(temp, FRF_BZ_UDP_FULL_SRCH_LIMIT, 8);
  1395. EFX_SET_OWORD_FIELD(temp, FRF_BZ_UDP_WILD_SRCH_LIMIT, 8);
  1396. EFX_SET_OWORD_FIELD(temp, FRF_BZ_TCP_FULL_SRCH_LIMIT, 8);
  1397. EFX_SET_OWORD_FIELD(temp, FRF_BZ_TCP_WILD_SRCH_LIMIT, 8);
  1398. efx_writeo(efx, &temp, FR_BZ_RX_FILTER_CTL);
  1399. }
  1400. /* XXX This is documented only for Falcon A0/A1 */
  1401. /* Setup RX. Wait for descriptor is broken and must
  1402. * be disabled. RXDP recovery shouldn't be needed, but is.
  1403. */
  1404. efx_reado(efx, &temp, FR_AA_RX_SELF_RST);
  1405. EFX_SET_OWORD_FIELD(temp, FRF_AA_RX_NODESC_WAIT_DIS, 1);
  1406. EFX_SET_OWORD_FIELD(temp, FRF_AA_RX_SELF_RST_EN, 1);
  1407. if (EFX_WORKAROUND_5583(efx))
  1408. EFX_SET_OWORD_FIELD(temp, FRF_AA_RX_ISCSI_DIS, 1);
  1409. efx_writeo(efx, &temp, FR_AA_RX_SELF_RST);
  1410. /* Do not enable TX_NO_EOP_DISC_EN, since it limits packets to 16
  1411. * descriptors (which is bad).
  1412. */
  1413. efx_reado(efx, &temp, FR_AZ_TX_CFG);
  1414. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_NO_EOP_DISC_EN, 0);
  1415. efx_writeo(efx, &temp, FR_AZ_TX_CFG);
  1416. falcon_init_rx_cfg(efx);
  1417. if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0) {
  1418. /* Set hash key for IPv4 */
  1419. memcpy(&temp, efx->rx_hash_key, sizeof(temp));
  1420. efx_writeo(efx, &temp, FR_BZ_RX_RSS_TKEY);
  1421. /* Set destination of both TX and RX Flush events */
  1422. EFX_POPULATE_OWORD_1(temp, FRF_BZ_FLS_EVQ_ID, 0);
  1423. efx_writeo(efx, &temp, FR_BZ_DP_CTRL);
  1424. }
  1425. efx_nic_init_common(efx);
  1426. return 0;
  1427. }
  1428. static void falcon_remove_nic(struct efx_nic *efx)
  1429. {
  1430. struct falcon_nic_data *nic_data = efx->nic_data;
  1431. struct falcon_board *board = falcon_board(efx);
  1432. int rc;
  1433. board->type->fini(efx);
  1434. /* Remove I2C adapter and clear it in preparation for a retry */
  1435. rc = i2c_del_adapter(&board->i2c_adap);
  1436. BUG_ON(rc);
  1437. memset(&board->i2c_adap, 0, sizeof(board->i2c_adap));
  1438. falcon_remove_spi_devices(efx);
  1439. efx_nic_free_buffer(efx, &efx->irq_status);
  1440. falcon_reset_hw(efx, RESET_TYPE_ALL);
  1441. /* Release the second function after the reset */
  1442. if (nic_data->pci_dev2) {
  1443. pci_dev_put(nic_data->pci_dev2);
  1444. nic_data->pci_dev2 = NULL;
  1445. }
  1446. /* Tear down the private nic state */
  1447. kfree(efx->nic_data);
  1448. efx->nic_data = NULL;
  1449. }
  1450. static void falcon_update_nic_stats(struct efx_nic *efx)
  1451. {
  1452. struct falcon_nic_data *nic_data = efx->nic_data;
  1453. efx_oword_t cnt;
  1454. if (nic_data->stats_disable_count)
  1455. return;
  1456. efx_reado(efx, &cnt, FR_AZ_RX_NODESC_DROP);
  1457. efx->n_rx_nodesc_drop_cnt +=
  1458. EFX_OWORD_FIELD(cnt, FRF_AB_RX_NODESC_DROP_CNT);
  1459. if (nic_data->stats_pending &&
  1460. *nic_data->stats_dma_done == FALCON_STATS_DONE) {
  1461. nic_data->stats_pending = false;
  1462. rmb(); /* read the done flag before the stats */
  1463. efx->mac_op->update_stats(efx);
  1464. }
  1465. }
  1466. void falcon_start_nic_stats(struct efx_nic *efx)
  1467. {
  1468. struct falcon_nic_data *nic_data = efx->nic_data;
  1469. spin_lock_bh(&efx->stats_lock);
  1470. if (--nic_data->stats_disable_count == 0)
  1471. falcon_stats_request(efx);
  1472. spin_unlock_bh(&efx->stats_lock);
  1473. }
  1474. void falcon_stop_nic_stats(struct efx_nic *efx)
  1475. {
  1476. struct falcon_nic_data *nic_data = efx->nic_data;
  1477. int i;
  1478. might_sleep();
  1479. spin_lock_bh(&efx->stats_lock);
  1480. ++nic_data->stats_disable_count;
  1481. spin_unlock_bh(&efx->stats_lock);
  1482. del_timer_sync(&nic_data->stats_timer);
  1483. /* Wait enough time for the most recent transfer to
  1484. * complete. */
  1485. for (i = 0; i < 4 && nic_data->stats_pending; i++) {
  1486. if (*nic_data->stats_dma_done == FALCON_STATS_DONE)
  1487. break;
  1488. msleep(1);
  1489. }
  1490. spin_lock_bh(&efx->stats_lock);
  1491. falcon_stats_complete(efx);
  1492. spin_unlock_bh(&efx->stats_lock);
  1493. }
  1494. static void falcon_set_id_led(struct efx_nic *efx, enum efx_led_mode mode)
  1495. {
  1496. falcon_board(efx)->type->set_id_led(efx, mode);
  1497. }
  1498. /**************************************************************************
  1499. *
  1500. * Wake on LAN
  1501. *
  1502. **************************************************************************
  1503. */
  1504. static void falcon_get_wol(struct efx_nic *efx, struct ethtool_wolinfo *wol)
  1505. {
  1506. wol->supported = 0;
  1507. wol->wolopts = 0;
  1508. memset(&wol->sopass, 0, sizeof(wol->sopass));
  1509. }
  1510. static int falcon_set_wol(struct efx_nic *efx, u32 type)
  1511. {
  1512. if (type != 0)
  1513. return -EINVAL;
  1514. return 0;
  1515. }
  1516. /**************************************************************************
  1517. *
  1518. * Revision-dependent attributes used by efx.c and nic.c
  1519. *
  1520. **************************************************************************
  1521. */
  1522. struct efx_nic_type falcon_a1_nic_type = {
  1523. .probe = falcon_probe_nic,
  1524. .remove = falcon_remove_nic,
  1525. .init = falcon_init_nic,
  1526. .fini = efx_port_dummy_op_void,
  1527. .monitor = falcon_monitor,
  1528. .reset = falcon_reset_hw,
  1529. .probe_port = falcon_probe_port,
  1530. .remove_port = falcon_remove_port,
  1531. .prepare_flush = falcon_prepare_flush,
  1532. .update_stats = falcon_update_nic_stats,
  1533. .start_stats = falcon_start_nic_stats,
  1534. .stop_stats = falcon_stop_nic_stats,
  1535. .set_id_led = falcon_set_id_led,
  1536. .push_irq_moderation = falcon_push_irq_moderation,
  1537. .push_multicast_hash = falcon_push_multicast_hash,
  1538. .reconfigure_port = falcon_reconfigure_port,
  1539. .get_wol = falcon_get_wol,
  1540. .set_wol = falcon_set_wol,
  1541. .resume_wol = efx_port_dummy_op_void,
  1542. .test_nvram = falcon_test_nvram,
  1543. .default_mac_ops = &falcon_xmac_operations,
  1544. .revision = EFX_REV_FALCON_A1,
  1545. .mem_map_size = 0x20000,
  1546. .txd_ptr_tbl_base = FR_AA_TX_DESC_PTR_TBL_KER,
  1547. .rxd_ptr_tbl_base = FR_AA_RX_DESC_PTR_TBL_KER,
  1548. .buf_tbl_base = FR_AA_BUF_FULL_TBL_KER,
  1549. .evq_ptr_tbl_base = FR_AA_EVQ_PTR_TBL_KER,
  1550. .evq_rptr_tbl_base = FR_AA_EVQ_RPTR_KER,
  1551. .max_dma_mask = DMA_BIT_MASK(FSF_AZ_TX_KER_BUF_ADDR_WIDTH),
  1552. .rx_buffer_padding = 0x24,
  1553. .max_interrupt_mode = EFX_INT_MODE_MSI,
  1554. .phys_addr_channels = 4,
  1555. .tx_dc_base = 0x130000,
  1556. .rx_dc_base = 0x100000,
  1557. .offload_features = NETIF_F_IP_CSUM,
  1558. .reset_world_flags = ETH_RESET_IRQ,
  1559. };
  1560. struct efx_nic_type falcon_b0_nic_type = {
  1561. .probe = falcon_probe_nic,
  1562. .remove = falcon_remove_nic,
  1563. .init = falcon_init_nic,
  1564. .fini = efx_port_dummy_op_void,
  1565. .monitor = falcon_monitor,
  1566. .reset = falcon_reset_hw,
  1567. .probe_port = falcon_probe_port,
  1568. .remove_port = falcon_remove_port,
  1569. .prepare_flush = falcon_prepare_flush,
  1570. .update_stats = falcon_update_nic_stats,
  1571. .start_stats = falcon_start_nic_stats,
  1572. .stop_stats = falcon_stop_nic_stats,
  1573. .set_id_led = falcon_set_id_led,
  1574. .push_irq_moderation = falcon_push_irq_moderation,
  1575. .push_multicast_hash = falcon_push_multicast_hash,
  1576. .reconfigure_port = falcon_reconfigure_port,
  1577. .get_wol = falcon_get_wol,
  1578. .set_wol = falcon_set_wol,
  1579. .resume_wol = efx_port_dummy_op_void,
  1580. .test_registers = falcon_b0_test_registers,
  1581. .test_nvram = falcon_test_nvram,
  1582. .default_mac_ops = &falcon_xmac_operations,
  1583. .revision = EFX_REV_FALCON_B0,
  1584. /* Map everything up to and including the RSS indirection
  1585. * table. Don't map MSI-X table, MSI-X PBA since Linux
  1586. * requires that they not be mapped. */
  1587. .mem_map_size = (FR_BZ_RX_INDIRECTION_TBL +
  1588. FR_BZ_RX_INDIRECTION_TBL_STEP *
  1589. FR_BZ_RX_INDIRECTION_TBL_ROWS),
  1590. .txd_ptr_tbl_base = FR_BZ_TX_DESC_PTR_TBL,
  1591. .rxd_ptr_tbl_base = FR_BZ_RX_DESC_PTR_TBL,
  1592. .buf_tbl_base = FR_BZ_BUF_FULL_TBL,
  1593. .evq_ptr_tbl_base = FR_BZ_EVQ_PTR_TBL,
  1594. .evq_rptr_tbl_base = FR_BZ_EVQ_RPTR,
  1595. .max_dma_mask = DMA_BIT_MASK(FSF_AZ_TX_KER_BUF_ADDR_WIDTH),
  1596. .rx_buffer_hash_size = 0x10,
  1597. .rx_buffer_padding = 0,
  1598. .max_interrupt_mode = EFX_INT_MODE_MSIX,
  1599. .phys_addr_channels = 32, /* Hardware limit is 64, but the legacy
  1600. * interrupt handler only supports 32
  1601. * channels */
  1602. .tx_dc_base = 0x130000,
  1603. .rx_dc_base = 0x100000,
  1604. .offload_features = NETIF_F_IP_CSUM | NETIF_F_RXHASH,
  1605. .reset_world_flags = ETH_RESET_IRQ,
  1606. };