falcon.c 51 KB

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