falcon.c 49 KB

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