falcon.c 51 KB

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