falcon.c 49 KB

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