falcon.c 51 KB

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