falcon.c 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792
  1. /****************************************************************************
  2. * Driver for Solarflare Solarstorm network controllers and boards
  3. * Copyright 2005-2006 Fen Systems Ltd.
  4. * Copyright 2006-2009 Solarflare Communications Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published
  8. * by the Free Software Foundation, incorporated herein by reference.
  9. */
  10. #include <linux/bitops.h>
  11. #include <linux/delay.h>
  12. #include <linux/pci.h>
  13. #include <linux/module.h>
  14. #include <linux/seq_file.h>
  15. #include <linux/i2c.h>
  16. #include <linux/mii.h>
  17. #include <linux/slab.h>
  18. #include "net_driver.h"
  19. #include "bitfield.h"
  20. #include "efx.h"
  21. #include "mac.h"
  22. #include "spi.h"
  23. #include "nic.h"
  24. #include "regs.h"
  25. #include "io.h"
  26. #include "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. BUG_ON(!mutex_is_locked(&efx->spi_lock));
  225. /* Check that previous command is not still running */
  226. rc = falcon_spi_poll(efx);
  227. if (rc)
  228. return rc;
  229. /* Program address register, if we have an address */
  230. if (addressed) {
  231. EFX_POPULATE_OWORD_1(reg, FRF_AB_EE_SPI_HADR_ADR, address);
  232. efx_writeo(efx, &reg, FR_AB_EE_SPI_HADR);
  233. }
  234. /* Program data register, if we have data */
  235. if (in != NULL) {
  236. memcpy(&reg, in, len);
  237. efx_writeo(efx, &reg, FR_AB_EE_SPI_HDATA);
  238. }
  239. /* Issue read/write command */
  240. EFX_POPULATE_OWORD_7(reg,
  241. FRF_AB_EE_SPI_HCMD_CMD_EN, 1,
  242. FRF_AB_EE_SPI_HCMD_SF_SEL, spi->device_id,
  243. FRF_AB_EE_SPI_HCMD_DABCNT, len,
  244. FRF_AB_EE_SPI_HCMD_READ, reading,
  245. FRF_AB_EE_SPI_HCMD_DUBCNT, 0,
  246. FRF_AB_EE_SPI_HCMD_ADBCNT,
  247. (addressed ? spi->addr_len : 0),
  248. FRF_AB_EE_SPI_HCMD_ENC, command);
  249. efx_writeo(efx, &reg, FR_AB_EE_SPI_HCMD);
  250. /* Wait for read/write to complete */
  251. rc = falcon_spi_wait(efx);
  252. if (rc)
  253. return rc;
  254. /* Read data */
  255. if (out != NULL) {
  256. efx_reado(efx, &reg, FR_AB_EE_SPI_HDATA);
  257. memcpy(out, &reg, len);
  258. }
  259. return 0;
  260. }
  261. static size_t
  262. falcon_spi_write_limit(const struct efx_spi_device *spi, size_t start)
  263. {
  264. return min(FALCON_SPI_MAX_LEN,
  265. (spi->block_size - (start & (spi->block_size - 1))));
  266. }
  267. static inline u8
  268. efx_spi_munge_command(const struct efx_spi_device *spi,
  269. const u8 command, const unsigned int address)
  270. {
  271. return command | (((address >> 8) & spi->munge_address) << 3);
  272. }
  273. /* Wait up to 10 ms for buffered write completion */
  274. int
  275. falcon_spi_wait_write(struct efx_nic *efx, const struct efx_spi_device *spi)
  276. {
  277. unsigned long timeout = jiffies + 1 + DIV_ROUND_UP(HZ, 100);
  278. u8 status;
  279. int rc;
  280. for (;;) {
  281. rc = falcon_spi_cmd(efx, spi, SPI_RDSR, -1, NULL,
  282. &status, sizeof(status));
  283. if (rc)
  284. return rc;
  285. if (!(status & SPI_STATUS_NRDY))
  286. return 0;
  287. if (time_after_eq(jiffies, timeout)) {
  288. 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 = (efx->reset_pending != RESET_TYPE_NONE);
  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 = 0;
  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 upto 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. 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(&efx->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(&efx->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. efx_oword_t reg;
  649. int rc;
  650. mutex_lock(&efx->mdio_lock);
  651. /* Check MDIO not currently being accessed */
  652. rc = falcon_gmii_wait(efx);
  653. if (rc)
  654. goto out;
  655. EFX_POPULATE_OWORD_1(reg, FRF_AB_MD_PHY_ADR, addr);
  656. efx_writeo(efx, &reg, FR_AB_MD_PHY_ADR);
  657. EFX_POPULATE_OWORD_2(reg, FRF_AB_MD_PRT_ADR, prtad,
  658. FRF_AB_MD_DEV_ADR, devad);
  659. efx_writeo(efx, &reg, FR_AB_MD_ID);
  660. /* Request data to be read */
  661. EFX_POPULATE_OWORD_2(reg, FRF_AB_MD_RDC, 1, FRF_AB_MD_GC, 0);
  662. efx_writeo(efx, &reg, FR_AB_MD_CS);
  663. /* Wait for data to become available */
  664. rc = falcon_gmii_wait(efx);
  665. if (rc == 0) {
  666. efx_reado(efx, &reg, FR_AB_MD_RXD);
  667. rc = EFX_OWORD_FIELD(reg, FRF_AB_MD_RXD);
  668. netif_vdbg(efx, hw, efx->net_dev,
  669. "read from MDIO %d register %d.%d, got %04x\n",
  670. prtad, devad, addr, rc);
  671. } else {
  672. /* Abort the read operation */
  673. EFX_POPULATE_OWORD_2(reg,
  674. FRF_AB_MD_RIC, 0,
  675. FRF_AB_MD_GC, 1);
  676. efx_writeo(efx, &reg, FR_AB_MD_CS);
  677. netif_dbg(efx, hw, efx->net_dev,
  678. "read from MDIO %d register %d.%d, got error %d\n",
  679. prtad, devad, addr, rc);
  680. }
  681. out:
  682. mutex_unlock(&efx->mdio_lock);
  683. return rc;
  684. }
  685. /* This call is responsible for hooking in the MAC and PHY operations */
  686. static int falcon_probe_port(struct efx_nic *efx)
  687. {
  688. struct falcon_nic_data *nic_data = efx->nic_data;
  689. int rc;
  690. switch (efx->phy_type) {
  691. case PHY_TYPE_SFX7101:
  692. efx->phy_op = &falcon_sfx7101_phy_ops;
  693. break;
  694. case PHY_TYPE_QT2022C2:
  695. case PHY_TYPE_QT2025C:
  696. efx->phy_op = &falcon_qt202x_phy_ops;
  697. break;
  698. case PHY_TYPE_TXC43128:
  699. efx->phy_op = &falcon_txc_phy_ops;
  700. break;
  701. default:
  702. netif_err(efx, probe, efx->net_dev, "Unknown PHY type %d\n",
  703. efx->phy_type);
  704. return -ENODEV;
  705. }
  706. /* Fill out MDIO structure and loopback modes */
  707. efx->mdio.mdio_read = falcon_mdio_read;
  708. efx->mdio.mdio_write = falcon_mdio_write;
  709. rc = efx->phy_op->probe(efx);
  710. if (rc != 0)
  711. return rc;
  712. /* Initial assumption */
  713. efx->link_state.speed = 10000;
  714. efx->link_state.fd = true;
  715. /* Hardware flow ctrl. FalconA RX FIFO too small for pause generation */
  716. if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0)
  717. efx->wanted_fc = EFX_FC_RX | EFX_FC_TX;
  718. else
  719. efx->wanted_fc = EFX_FC_RX;
  720. if (efx->mdio.mmds & MDIO_DEVS_AN)
  721. efx->wanted_fc |= EFX_FC_AUTO;
  722. /* Allocate buffer for stats */
  723. rc = efx_nic_alloc_buffer(efx, &efx->stats_buffer,
  724. FALCON_MAC_STATS_SIZE);
  725. if (rc)
  726. return rc;
  727. netif_dbg(efx, probe, efx->net_dev,
  728. "stats buffer at %llx (virt %p phys %llx)\n",
  729. (u64)efx->stats_buffer.dma_addr,
  730. efx->stats_buffer.addr,
  731. (u64)virt_to_phys(efx->stats_buffer.addr));
  732. nic_data->stats_dma_done = efx->stats_buffer.addr + XgDmaDone_offset;
  733. return 0;
  734. }
  735. static void falcon_remove_port(struct efx_nic *efx)
  736. {
  737. efx->phy_op->remove(efx);
  738. efx_nic_free_buffer(efx, &efx->stats_buffer);
  739. }
  740. /**************************************************************************
  741. *
  742. * Falcon test code
  743. *
  744. **************************************************************************/
  745. static int
  746. falcon_read_nvram(struct efx_nic *efx, struct falcon_nvconfig *nvconfig_out)
  747. {
  748. struct falcon_nvconfig *nvconfig;
  749. struct efx_spi_device *spi;
  750. void *region;
  751. int rc, magic_num, struct_ver;
  752. __le16 *word, *limit;
  753. u32 csum;
  754. spi = efx->spi_flash ? efx->spi_flash : efx->spi_eeprom;
  755. if (!spi)
  756. return -EINVAL;
  757. region = kmalloc(FALCON_NVCONFIG_END, GFP_KERNEL);
  758. if (!region)
  759. return -ENOMEM;
  760. nvconfig = region + FALCON_NVCONFIG_OFFSET;
  761. mutex_lock(&efx->spi_lock);
  762. rc = falcon_spi_read(efx, spi, 0, FALCON_NVCONFIG_END, NULL, region);
  763. mutex_unlock(&efx->spi_lock);
  764. if (rc) {
  765. netif_err(efx, hw, efx->net_dev, "Failed to read %s\n",
  766. efx->spi_flash ? "flash" : "EEPROM");
  767. rc = -EIO;
  768. goto out;
  769. }
  770. magic_num = le16_to_cpu(nvconfig->board_magic_num);
  771. struct_ver = le16_to_cpu(nvconfig->board_struct_ver);
  772. rc = -EINVAL;
  773. if (magic_num != FALCON_NVCONFIG_BOARD_MAGIC_NUM) {
  774. netif_err(efx, hw, efx->net_dev,
  775. "NVRAM bad magic 0x%x\n", magic_num);
  776. goto out;
  777. }
  778. if (struct_ver < 2) {
  779. netif_err(efx, hw, efx->net_dev,
  780. "NVRAM has ancient version 0x%x\n", struct_ver);
  781. goto out;
  782. } else if (struct_ver < 4) {
  783. word = &nvconfig->board_magic_num;
  784. limit = (__le16 *) (nvconfig + 1);
  785. } else {
  786. word = region;
  787. limit = region + FALCON_NVCONFIG_END;
  788. }
  789. for (csum = 0; word < limit; ++word)
  790. csum += le16_to_cpu(*word);
  791. if (~csum & 0xffff) {
  792. netif_err(efx, hw, efx->net_dev,
  793. "NVRAM has incorrect checksum\n");
  794. goto out;
  795. }
  796. rc = 0;
  797. if (nvconfig_out)
  798. memcpy(nvconfig_out, nvconfig, sizeof(*nvconfig));
  799. out:
  800. kfree(region);
  801. return rc;
  802. }
  803. static int falcon_test_nvram(struct efx_nic *efx)
  804. {
  805. return falcon_read_nvram(efx, NULL);
  806. }
  807. static const struct efx_nic_register_test falcon_b0_register_tests[] = {
  808. { FR_AZ_ADR_REGION,
  809. EFX_OWORD32(0x0003FFFF, 0x0003FFFF, 0x0003FFFF, 0x0003FFFF) },
  810. { FR_AZ_RX_CFG,
  811. EFX_OWORD32(0xFFFFFFFE, 0x00017FFF, 0x00000000, 0x00000000) },
  812. { FR_AZ_TX_CFG,
  813. EFX_OWORD32(0x7FFF0037, 0x00000000, 0x00000000, 0x00000000) },
  814. { FR_AZ_TX_RESERVED,
  815. EFX_OWORD32(0xFFFEFE80, 0x1FFFFFFF, 0x020000FE, 0x007FFFFF) },
  816. { FR_AB_MAC_CTRL,
  817. EFX_OWORD32(0xFFFF0000, 0x00000000, 0x00000000, 0x00000000) },
  818. { FR_AZ_SRM_TX_DC_CFG,
  819. EFX_OWORD32(0x001FFFFF, 0x00000000, 0x00000000, 0x00000000) },
  820. { FR_AZ_RX_DC_CFG,
  821. EFX_OWORD32(0x0000000F, 0x00000000, 0x00000000, 0x00000000) },
  822. { FR_AZ_RX_DC_PF_WM,
  823. EFX_OWORD32(0x000003FF, 0x00000000, 0x00000000, 0x00000000) },
  824. { FR_BZ_DP_CTRL,
  825. EFX_OWORD32(0x00000FFF, 0x00000000, 0x00000000, 0x00000000) },
  826. { FR_AB_GM_CFG2,
  827. EFX_OWORD32(0x00007337, 0x00000000, 0x00000000, 0x00000000) },
  828. { FR_AB_GMF_CFG0,
  829. EFX_OWORD32(0x00001F1F, 0x00000000, 0x00000000, 0x00000000) },
  830. { FR_AB_XM_GLB_CFG,
  831. EFX_OWORD32(0x00000C68, 0x00000000, 0x00000000, 0x00000000) },
  832. { FR_AB_XM_TX_CFG,
  833. EFX_OWORD32(0x00080164, 0x00000000, 0x00000000, 0x00000000) },
  834. { FR_AB_XM_RX_CFG,
  835. EFX_OWORD32(0x07100A0C, 0x00000000, 0x00000000, 0x00000000) },
  836. { FR_AB_XM_RX_PARAM,
  837. EFX_OWORD32(0x00001FF8, 0x00000000, 0x00000000, 0x00000000) },
  838. { FR_AB_XM_FC,
  839. EFX_OWORD32(0xFFFF0001, 0x00000000, 0x00000000, 0x00000000) },
  840. { FR_AB_XM_ADR_LO,
  841. EFX_OWORD32(0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000) },
  842. { FR_AB_XX_SD_CTL,
  843. EFX_OWORD32(0x0003FF0F, 0x00000000, 0x00000000, 0x00000000) },
  844. };
  845. static int falcon_b0_test_registers(struct efx_nic *efx)
  846. {
  847. return efx_nic_test_registers(efx, falcon_b0_register_tests,
  848. ARRAY_SIZE(falcon_b0_register_tests));
  849. }
  850. /**************************************************************************
  851. *
  852. * Device reset
  853. *
  854. **************************************************************************
  855. */
  856. /* Resets NIC to known state. This routine must be called in process
  857. * context and is allowed to sleep. */
  858. static int falcon_reset_hw(struct efx_nic *efx, enum reset_type method)
  859. {
  860. struct falcon_nic_data *nic_data = efx->nic_data;
  861. efx_oword_t glb_ctl_reg_ker;
  862. int rc;
  863. netif_dbg(efx, hw, efx->net_dev, "performing %s hardware reset\n",
  864. RESET_TYPE(method));
  865. /* Initiate device reset */
  866. if (method == RESET_TYPE_WORLD) {
  867. rc = pci_save_state(efx->pci_dev);
  868. if (rc) {
  869. netif_err(efx, drv, efx->net_dev,
  870. "failed to backup PCI state of primary "
  871. "function prior to hardware reset\n");
  872. goto fail1;
  873. }
  874. if (efx_nic_is_dual_func(efx)) {
  875. rc = pci_save_state(nic_data->pci_dev2);
  876. if (rc) {
  877. netif_err(efx, drv, efx->net_dev,
  878. "failed to backup PCI state of "
  879. "secondary function prior to "
  880. "hardware reset\n");
  881. goto fail2;
  882. }
  883. }
  884. EFX_POPULATE_OWORD_2(glb_ctl_reg_ker,
  885. FRF_AB_EXT_PHY_RST_DUR,
  886. FFE_AB_EXT_PHY_RST_DUR_10240US,
  887. FRF_AB_SWRST, 1);
  888. } else {
  889. EFX_POPULATE_OWORD_7(glb_ctl_reg_ker,
  890. /* exclude PHY from "invisible" reset */
  891. FRF_AB_EXT_PHY_RST_CTL,
  892. method == RESET_TYPE_INVISIBLE,
  893. /* exclude EEPROM/flash and PCIe */
  894. FRF_AB_PCIE_CORE_RST_CTL, 1,
  895. FRF_AB_PCIE_NSTKY_RST_CTL, 1,
  896. FRF_AB_PCIE_SD_RST_CTL, 1,
  897. FRF_AB_EE_RST_CTL, 1,
  898. FRF_AB_EXT_PHY_RST_DUR,
  899. FFE_AB_EXT_PHY_RST_DUR_10240US,
  900. FRF_AB_SWRST, 1);
  901. }
  902. efx_writeo(efx, &glb_ctl_reg_ker, FR_AB_GLB_CTL);
  903. netif_dbg(efx, hw, efx->net_dev, "waiting for hardware reset\n");
  904. schedule_timeout_uninterruptible(HZ / 20);
  905. /* Restore PCI configuration if needed */
  906. if (method == RESET_TYPE_WORLD) {
  907. if (efx_nic_is_dual_func(efx)) {
  908. rc = pci_restore_state(nic_data->pci_dev2);
  909. if (rc) {
  910. netif_err(efx, drv, efx->net_dev,
  911. "failed to restore PCI config for "
  912. "the secondary function\n");
  913. goto fail3;
  914. }
  915. }
  916. rc = pci_restore_state(efx->pci_dev);
  917. if (rc) {
  918. netif_err(efx, drv, efx->net_dev,
  919. "failed to restore PCI config for the "
  920. "primary function\n");
  921. goto fail4;
  922. }
  923. netif_dbg(efx, drv, efx->net_dev,
  924. "successfully restored PCI config\n");
  925. }
  926. /* Assert that reset complete */
  927. efx_reado(efx, &glb_ctl_reg_ker, FR_AB_GLB_CTL);
  928. if (EFX_OWORD_FIELD(glb_ctl_reg_ker, FRF_AB_SWRST) != 0) {
  929. rc = -ETIMEDOUT;
  930. netif_err(efx, hw, efx->net_dev,
  931. "timed out waiting for hardware reset\n");
  932. goto fail5;
  933. }
  934. netif_dbg(efx, hw, efx->net_dev, "hardware reset complete\n");
  935. return 0;
  936. /* pci_save_state() and pci_restore_state() MUST be called in pairs */
  937. fail2:
  938. fail3:
  939. pci_restore_state(efx->pci_dev);
  940. fail1:
  941. fail4:
  942. fail5:
  943. return rc;
  944. }
  945. static void falcon_monitor(struct efx_nic *efx)
  946. {
  947. bool link_changed;
  948. int rc;
  949. BUG_ON(!mutex_is_locked(&efx->mac_lock));
  950. rc = falcon_board(efx)->type->monitor(efx);
  951. if (rc) {
  952. netif_err(efx, hw, efx->net_dev,
  953. "Board sensor %s; shutting down PHY\n",
  954. (rc == -ERANGE) ? "reported fault" : "failed");
  955. efx->phy_mode |= PHY_MODE_LOW_POWER;
  956. rc = __efx_reconfigure_port(efx);
  957. WARN_ON(rc);
  958. }
  959. if (LOOPBACK_INTERNAL(efx))
  960. link_changed = falcon_loopback_link_poll(efx);
  961. else
  962. link_changed = efx->phy_op->poll(efx);
  963. if (link_changed) {
  964. falcon_stop_nic_stats(efx);
  965. falcon_deconfigure_mac_wrapper(efx);
  966. falcon_reset_macs(efx);
  967. rc = efx->mac_op->reconfigure(efx);
  968. BUG_ON(rc);
  969. falcon_start_nic_stats(efx);
  970. efx_link_status_changed(efx);
  971. }
  972. falcon_poll_xmac(efx);
  973. }
  974. /* Zeroes out the SRAM contents. This routine must be called in
  975. * process context and is allowed to sleep.
  976. */
  977. static int falcon_reset_sram(struct efx_nic *efx)
  978. {
  979. efx_oword_t srm_cfg_reg_ker, gpio_cfg_reg_ker;
  980. int count;
  981. /* Set the SRAM wake/sleep GPIO appropriately. */
  982. efx_reado(efx, &gpio_cfg_reg_ker, FR_AB_GPIO_CTL);
  983. EFX_SET_OWORD_FIELD(gpio_cfg_reg_ker, FRF_AB_GPIO1_OEN, 1);
  984. EFX_SET_OWORD_FIELD(gpio_cfg_reg_ker, FRF_AB_GPIO1_OUT, 1);
  985. efx_writeo(efx, &gpio_cfg_reg_ker, FR_AB_GPIO_CTL);
  986. /* Initiate SRAM reset */
  987. EFX_POPULATE_OWORD_2(srm_cfg_reg_ker,
  988. FRF_AZ_SRM_INIT_EN, 1,
  989. FRF_AZ_SRM_NB_SZ, 0);
  990. efx_writeo(efx, &srm_cfg_reg_ker, FR_AZ_SRM_CFG);
  991. /* Wait for SRAM reset to complete */
  992. count = 0;
  993. do {
  994. netif_dbg(efx, hw, efx->net_dev,
  995. "waiting for SRAM reset (attempt %d)...\n", count);
  996. /* SRAM reset is slow; expect around 16ms */
  997. schedule_timeout_uninterruptible(HZ / 50);
  998. /* Check for reset complete */
  999. efx_reado(efx, &srm_cfg_reg_ker, FR_AZ_SRM_CFG);
  1000. if (!EFX_OWORD_FIELD(srm_cfg_reg_ker, FRF_AZ_SRM_INIT_EN)) {
  1001. netif_dbg(efx, hw, efx->net_dev,
  1002. "SRAM reset complete\n");
  1003. return 0;
  1004. }
  1005. } while (++count < 20); /* wait upto 0.4 sec */
  1006. netif_err(efx, hw, efx->net_dev, "timed out waiting for SRAM reset\n");
  1007. return -ETIMEDOUT;
  1008. }
  1009. static int falcon_spi_device_init(struct efx_nic *efx,
  1010. struct efx_spi_device **spi_device_ret,
  1011. unsigned int device_id, u32 device_type)
  1012. {
  1013. struct efx_spi_device *spi_device;
  1014. if (device_type != 0) {
  1015. spi_device = kzalloc(sizeof(*spi_device), GFP_KERNEL);
  1016. if (!spi_device)
  1017. return -ENOMEM;
  1018. spi_device->device_id = device_id;
  1019. spi_device->size =
  1020. 1 << SPI_DEV_TYPE_FIELD(device_type, SPI_DEV_TYPE_SIZE);
  1021. spi_device->addr_len =
  1022. SPI_DEV_TYPE_FIELD(device_type, SPI_DEV_TYPE_ADDR_LEN);
  1023. spi_device->munge_address = (spi_device->size == 1 << 9 &&
  1024. spi_device->addr_len == 1);
  1025. spi_device->erase_command =
  1026. SPI_DEV_TYPE_FIELD(device_type, SPI_DEV_TYPE_ERASE_CMD);
  1027. spi_device->erase_size =
  1028. 1 << SPI_DEV_TYPE_FIELD(device_type,
  1029. SPI_DEV_TYPE_ERASE_SIZE);
  1030. spi_device->block_size =
  1031. 1 << SPI_DEV_TYPE_FIELD(device_type,
  1032. SPI_DEV_TYPE_BLOCK_SIZE);
  1033. } else {
  1034. spi_device = NULL;
  1035. }
  1036. kfree(*spi_device_ret);
  1037. *spi_device_ret = spi_device;
  1038. return 0;
  1039. }
  1040. static void falcon_remove_spi_devices(struct efx_nic *efx)
  1041. {
  1042. kfree(efx->spi_eeprom);
  1043. efx->spi_eeprom = NULL;
  1044. kfree(efx->spi_flash);
  1045. efx->spi_flash = NULL;
  1046. }
  1047. /* Extract non-volatile configuration */
  1048. static int falcon_probe_nvconfig(struct efx_nic *efx)
  1049. {
  1050. struct falcon_nvconfig *nvconfig;
  1051. int rc;
  1052. nvconfig = kmalloc(sizeof(*nvconfig), GFP_KERNEL);
  1053. if (!nvconfig)
  1054. return -ENOMEM;
  1055. rc = falcon_read_nvram(efx, nvconfig);
  1056. if (rc)
  1057. goto fail1;
  1058. efx->phy_type = nvconfig->board_v2.port0_phy_type;
  1059. efx->mdio.prtad = nvconfig->board_v2.port0_phy_addr;
  1060. if (le16_to_cpu(nvconfig->board_struct_ver) >= 3) {
  1061. rc = falcon_spi_device_init(
  1062. efx, &efx->spi_flash, FFE_AB_SPI_DEVICE_FLASH,
  1063. le32_to_cpu(nvconfig->board_v3
  1064. .spi_device_type[FFE_AB_SPI_DEVICE_FLASH]));
  1065. if (rc)
  1066. goto fail2;
  1067. rc = falcon_spi_device_init(
  1068. efx, &efx->spi_eeprom, FFE_AB_SPI_DEVICE_EEPROM,
  1069. le32_to_cpu(nvconfig->board_v3
  1070. .spi_device_type[FFE_AB_SPI_DEVICE_EEPROM]));
  1071. if (rc)
  1072. goto fail2;
  1073. }
  1074. /* Read the MAC addresses */
  1075. memcpy(efx->mac_address, nvconfig->mac_address[0], ETH_ALEN);
  1076. netif_dbg(efx, probe, efx->net_dev, "PHY is %d phy_id %d\n",
  1077. efx->phy_type, efx->mdio.prtad);
  1078. rc = falcon_probe_board(efx,
  1079. le16_to_cpu(nvconfig->board_v2.board_revision));
  1080. if (rc)
  1081. goto fail2;
  1082. kfree(nvconfig);
  1083. return 0;
  1084. fail2:
  1085. falcon_remove_spi_devices(efx);
  1086. fail1:
  1087. kfree(nvconfig);
  1088. return rc;
  1089. }
  1090. /* Probe all SPI devices on the NIC */
  1091. static void falcon_probe_spi_devices(struct efx_nic *efx)
  1092. {
  1093. efx_oword_t nic_stat, gpio_ctl, ee_vpd_cfg;
  1094. int boot_dev;
  1095. efx_reado(efx, &gpio_ctl, FR_AB_GPIO_CTL);
  1096. efx_reado(efx, &nic_stat, FR_AB_NIC_STAT);
  1097. efx_reado(efx, &ee_vpd_cfg, FR_AB_EE_VPD_CFG0);
  1098. if (EFX_OWORD_FIELD(gpio_ctl, FRF_AB_GPIO3_PWRUP_VALUE)) {
  1099. boot_dev = (EFX_OWORD_FIELD(nic_stat, FRF_AB_SF_PRST) ?
  1100. FFE_AB_SPI_DEVICE_FLASH : FFE_AB_SPI_DEVICE_EEPROM);
  1101. netif_dbg(efx, probe, efx->net_dev, "Booted from %s\n",
  1102. boot_dev == FFE_AB_SPI_DEVICE_FLASH ?
  1103. "flash" : "EEPROM");
  1104. } else {
  1105. /* Disable VPD and set clock dividers to safe
  1106. * values for initial programming. */
  1107. boot_dev = -1;
  1108. netif_dbg(efx, probe, efx->net_dev,
  1109. "Booted from internal ASIC settings;"
  1110. " setting SPI config\n");
  1111. EFX_POPULATE_OWORD_3(ee_vpd_cfg, FRF_AB_EE_VPD_EN, 0,
  1112. /* 125 MHz / 7 ~= 20 MHz */
  1113. FRF_AB_EE_SF_CLOCK_DIV, 7,
  1114. /* 125 MHz / 63 ~= 2 MHz */
  1115. FRF_AB_EE_EE_CLOCK_DIV, 63);
  1116. efx_writeo(efx, &ee_vpd_cfg, FR_AB_EE_VPD_CFG0);
  1117. }
  1118. if (boot_dev == FFE_AB_SPI_DEVICE_FLASH)
  1119. falcon_spi_device_init(efx, &efx->spi_flash,
  1120. FFE_AB_SPI_DEVICE_FLASH,
  1121. default_flash_type);
  1122. if (boot_dev == FFE_AB_SPI_DEVICE_EEPROM)
  1123. falcon_spi_device_init(efx, &efx->spi_eeprom,
  1124. FFE_AB_SPI_DEVICE_EEPROM,
  1125. large_eeprom_type);
  1126. }
  1127. static int falcon_probe_nic(struct efx_nic *efx)
  1128. {
  1129. struct falcon_nic_data *nic_data;
  1130. struct falcon_board *board;
  1131. int rc;
  1132. /* Allocate storage for hardware specific data */
  1133. nic_data = kzalloc(sizeof(*nic_data), GFP_KERNEL);
  1134. if (!nic_data)
  1135. return -ENOMEM;
  1136. efx->nic_data = nic_data;
  1137. rc = -ENODEV;
  1138. if (efx_nic_fpga_ver(efx) != 0) {
  1139. netif_err(efx, probe, efx->net_dev,
  1140. "Falcon FPGA not supported\n");
  1141. goto fail1;
  1142. }
  1143. if (efx_nic_rev(efx) <= EFX_REV_FALCON_A1) {
  1144. efx_oword_t nic_stat;
  1145. struct pci_dev *dev;
  1146. u8 pci_rev = efx->pci_dev->revision;
  1147. if ((pci_rev == 0xff) || (pci_rev == 0)) {
  1148. netif_err(efx, probe, efx->net_dev,
  1149. "Falcon rev A0 not supported\n");
  1150. goto fail1;
  1151. }
  1152. efx_reado(efx, &nic_stat, FR_AB_NIC_STAT);
  1153. if (EFX_OWORD_FIELD(nic_stat, FRF_AB_STRAP_10G) == 0) {
  1154. netif_err(efx, probe, efx->net_dev,
  1155. "Falcon rev A1 1G not supported\n");
  1156. goto fail1;
  1157. }
  1158. if (EFX_OWORD_FIELD(nic_stat, FRF_AA_STRAP_PCIE) == 0) {
  1159. netif_err(efx, probe, efx->net_dev,
  1160. "Falcon rev A1 PCI-X not supported\n");
  1161. goto fail1;
  1162. }
  1163. dev = pci_dev_get(efx->pci_dev);
  1164. while ((dev = pci_get_device(EFX_VENDID_SFC, FALCON_A_S_DEVID,
  1165. dev))) {
  1166. if (dev->bus == efx->pci_dev->bus &&
  1167. dev->devfn == efx->pci_dev->devfn + 1) {
  1168. nic_data->pci_dev2 = dev;
  1169. break;
  1170. }
  1171. }
  1172. if (!nic_data->pci_dev2) {
  1173. netif_err(efx, probe, efx->net_dev,
  1174. "failed to find secondary function\n");
  1175. rc = -ENODEV;
  1176. goto fail2;
  1177. }
  1178. }
  1179. /* Now we can reset the NIC */
  1180. rc = falcon_reset_hw(efx, RESET_TYPE_ALL);
  1181. if (rc) {
  1182. netif_err(efx, probe, efx->net_dev, "failed to reset NIC\n");
  1183. goto fail3;
  1184. }
  1185. /* Allocate memory for INT_KER */
  1186. rc = efx_nic_alloc_buffer(efx, &efx->irq_status, sizeof(efx_oword_t));
  1187. if (rc)
  1188. goto fail4;
  1189. BUG_ON(efx->irq_status.dma_addr & 0x0f);
  1190. netif_dbg(efx, probe, efx->net_dev,
  1191. "INT_KER at %llx (virt %p phys %llx)\n",
  1192. (u64)efx->irq_status.dma_addr,
  1193. efx->irq_status.addr,
  1194. (u64)virt_to_phys(efx->irq_status.addr));
  1195. falcon_probe_spi_devices(efx);
  1196. /* Read in the non-volatile configuration */
  1197. rc = falcon_probe_nvconfig(efx);
  1198. if (rc) {
  1199. if (rc == -EINVAL)
  1200. netif_err(efx, probe, efx->net_dev, "NVRAM is invalid\n");
  1201. goto fail5;
  1202. }
  1203. /* Initialise I2C adapter */
  1204. board = falcon_board(efx);
  1205. board->i2c_adap.owner = THIS_MODULE;
  1206. board->i2c_data = falcon_i2c_bit_operations;
  1207. board->i2c_data.data = efx;
  1208. board->i2c_adap.algo_data = &board->i2c_data;
  1209. board->i2c_adap.dev.parent = &efx->pci_dev->dev;
  1210. strlcpy(board->i2c_adap.name, "SFC4000 GPIO",
  1211. sizeof(board->i2c_adap.name));
  1212. rc = i2c_bit_add_bus(&board->i2c_adap);
  1213. if (rc)
  1214. goto fail5;
  1215. rc = falcon_board(efx)->type->init(efx);
  1216. if (rc) {
  1217. netif_err(efx, probe, efx->net_dev,
  1218. "failed to initialise board\n");
  1219. goto fail6;
  1220. }
  1221. nic_data->stats_disable_count = 1;
  1222. setup_timer(&nic_data->stats_timer, &falcon_stats_timer_func,
  1223. (unsigned long)efx);
  1224. return 0;
  1225. fail6:
  1226. BUG_ON(i2c_del_adapter(&board->i2c_adap));
  1227. memset(&board->i2c_adap, 0, sizeof(board->i2c_adap));
  1228. fail5:
  1229. falcon_remove_spi_devices(efx);
  1230. efx_nic_free_buffer(efx, &efx->irq_status);
  1231. fail4:
  1232. fail3:
  1233. if (nic_data->pci_dev2) {
  1234. pci_dev_put(nic_data->pci_dev2);
  1235. nic_data->pci_dev2 = NULL;
  1236. }
  1237. fail2:
  1238. fail1:
  1239. kfree(efx->nic_data);
  1240. return rc;
  1241. }
  1242. static void falcon_init_rx_cfg(struct efx_nic *efx)
  1243. {
  1244. /* Prior to Siena the RX DMA engine will split each frame at
  1245. * intervals of RX_USR_BUF_SIZE (32-byte units). We set it to
  1246. * be so large that that never happens. */
  1247. const unsigned huge_buf_size = (3 * 4096) >> 5;
  1248. /* RX control FIFO thresholds (32 entries) */
  1249. const unsigned ctrl_xon_thr = 20;
  1250. const unsigned ctrl_xoff_thr = 25;
  1251. /* RX data FIFO thresholds (256-byte units; size varies) */
  1252. int data_xon_thr = efx_nic_rx_xon_thresh >> 8;
  1253. int data_xoff_thr = efx_nic_rx_xoff_thresh >> 8;
  1254. efx_oword_t reg;
  1255. efx_reado(efx, &reg, FR_AZ_RX_CFG);
  1256. if (efx_nic_rev(efx) <= EFX_REV_FALCON_A1) {
  1257. /* Data FIFO size is 5.5K */
  1258. if (data_xon_thr < 0)
  1259. data_xon_thr = 512 >> 8;
  1260. if (data_xoff_thr < 0)
  1261. data_xoff_thr = 2048 >> 8;
  1262. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_DESC_PUSH_EN, 0);
  1263. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_USR_BUF_SIZE,
  1264. huge_buf_size);
  1265. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XON_MAC_TH, data_xon_thr);
  1266. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XOFF_MAC_TH, data_xoff_thr);
  1267. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XON_TX_TH, ctrl_xon_thr);
  1268. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XOFF_TX_TH, ctrl_xoff_thr);
  1269. } else {
  1270. /* Data FIFO size is 80K; register fields moved */
  1271. if (data_xon_thr < 0)
  1272. data_xon_thr = 27648 >> 8; /* ~3*max MTU */
  1273. if (data_xoff_thr < 0)
  1274. data_xoff_thr = 54272 >> 8; /* ~80Kb - 3*max MTU */
  1275. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_DESC_PUSH_EN, 0);
  1276. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_USR_BUF_SIZE,
  1277. huge_buf_size);
  1278. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XON_MAC_TH, data_xon_thr);
  1279. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XOFF_MAC_TH, data_xoff_thr);
  1280. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XON_TX_TH, ctrl_xon_thr);
  1281. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XOFF_TX_TH, ctrl_xoff_thr);
  1282. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_INGR_EN, 1);
  1283. /* Enable hash insertion. This is broken for the
  1284. * 'Falcon' hash so also select Toeplitz TCP/IPv4 and
  1285. * IPv4 hashes. */
  1286. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_HASH_INSRT_HDR, 1);
  1287. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_HASH_ALG, 1);
  1288. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_IP_HASH, 1);
  1289. }
  1290. /* Always enable XOFF signal from RX FIFO. We enable
  1291. * or disable transmission of pause frames at the MAC. */
  1292. EFX_SET_OWORD_FIELD(reg, FRF_AZ_RX_XOFF_MAC_EN, 1);
  1293. efx_writeo(efx, &reg, FR_AZ_RX_CFG);
  1294. }
  1295. /* This call performs hardware-specific global initialisation, such as
  1296. * defining the descriptor cache sizes and number of RSS channels.
  1297. * It does not set up any buffers, descriptor rings or event queues.
  1298. */
  1299. static int falcon_init_nic(struct efx_nic *efx)
  1300. {
  1301. efx_oword_t temp;
  1302. int rc;
  1303. /* Use on-chip SRAM */
  1304. efx_reado(efx, &temp, FR_AB_NIC_STAT);
  1305. EFX_SET_OWORD_FIELD(temp, FRF_AB_ONCHIP_SRAM, 1);
  1306. efx_writeo(efx, &temp, FR_AB_NIC_STAT);
  1307. rc = falcon_reset_sram(efx);
  1308. if (rc)
  1309. return rc;
  1310. /* Clear the parity enables on the TX data fifos as
  1311. * they produce false parity errors because of timing issues
  1312. */
  1313. if (EFX_WORKAROUND_5129(efx)) {
  1314. efx_reado(efx, &temp, FR_AZ_CSR_SPARE);
  1315. EFX_SET_OWORD_FIELD(temp, FRF_AB_MEM_PERR_EN_TX_DATA, 0);
  1316. efx_writeo(efx, &temp, FR_AZ_CSR_SPARE);
  1317. }
  1318. if (EFX_WORKAROUND_7244(efx)) {
  1319. efx_reado(efx, &temp, FR_BZ_RX_FILTER_CTL);
  1320. EFX_SET_OWORD_FIELD(temp, FRF_BZ_UDP_FULL_SRCH_LIMIT, 8);
  1321. EFX_SET_OWORD_FIELD(temp, FRF_BZ_UDP_WILD_SRCH_LIMIT, 8);
  1322. EFX_SET_OWORD_FIELD(temp, FRF_BZ_TCP_FULL_SRCH_LIMIT, 8);
  1323. EFX_SET_OWORD_FIELD(temp, FRF_BZ_TCP_WILD_SRCH_LIMIT, 8);
  1324. efx_writeo(efx, &temp, FR_BZ_RX_FILTER_CTL);
  1325. }
  1326. /* XXX This is documented only for Falcon A0/A1 */
  1327. /* Setup RX. Wait for descriptor is broken and must
  1328. * be disabled. RXDP recovery shouldn't be needed, but is.
  1329. */
  1330. efx_reado(efx, &temp, FR_AA_RX_SELF_RST);
  1331. EFX_SET_OWORD_FIELD(temp, FRF_AA_RX_NODESC_WAIT_DIS, 1);
  1332. EFX_SET_OWORD_FIELD(temp, FRF_AA_RX_SELF_RST_EN, 1);
  1333. if (EFX_WORKAROUND_5583(efx))
  1334. EFX_SET_OWORD_FIELD(temp, FRF_AA_RX_ISCSI_DIS, 1);
  1335. efx_writeo(efx, &temp, FR_AA_RX_SELF_RST);
  1336. /* Do not enable TX_NO_EOP_DISC_EN, since it limits packets to 16
  1337. * descriptors (which is bad).
  1338. */
  1339. efx_reado(efx, &temp, FR_AZ_TX_CFG);
  1340. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_NO_EOP_DISC_EN, 0);
  1341. efx_writeo(efx, &temp, FR_AZ_TX_CFG);
  1342. falcon_init_rx_cfg(efx);
  1343. if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0) {
  1344. /* Set hash key for IPv4 */
  1345. memcpy(&temp, efx->rx_hash_key, sizeof(temp));
  1346. efx_writeo(efx, &temp, FR_BZ_RX_RSS_TKEY);
  1347. /* Set destination of both TX and RX Flush events */
  1348. EFX_POPULATE_OWORD_1(temp, FRF_BZ_FLS_EVQ_ID, 0);
  1349. efx_writeo(efx, &temp, FR_BZ_DP_CTRL);
  1350. }
  1351. efx_nic_init_common(efx);
  1352. return 0;
  1353. }
  1354. static void falcon_remove_nic(struct efx_nic *efx)
  1355. {
  1356. struct falcon_nic_data *nic_data = efx->nic_data;
  1357. struct falcon_board *board = falcon_board(efx);
  1358. int rc;
  1359. board->type->fini(efx);
  1360. /* Remove I2C adapter and clear it in preparation for a retry */
  1361. rc = i2c_del_adapter(&board->i2c_adap);
  1362. BUG_ON(rc);
  1363. memset(&board->i2c_adap, 0, sizeof(board->i2c_adap));
  1364. falcon_remove_spi_devices(efx);
  1365. efx_nic_free_buffer(efx, &efx->irq_status);
  1366. falcon_reset_hw(efx, RESET_TYPE_ALL);
  1367. /* Release the second function after the reset */
  1368. if (nic_data->pci_dev2) {
  1369. pci_dev_put(nic_data->pci_dev2);
  1370. nic_data->pci_dev2 = NULL;
  1371. }
  1372. /* Tear down the private nic state */
  1373. kfree(efx->nic_data);
  1374. efx->nic_data = NULL;
  1375. }
  1376. static void falcon_update_nic_stats(struct efx_nic *efx)
  1377. {
  1378. struct falcon_nic_data *nic_data = efx->nic_data;
  1379. efx_oword_t cnt;
  1380. if (nic_data->stats_disable_count)
  1381. return;
  1382. efx_reado(efx, &cnt, FR_AZ_RX_NODESC_DROP);
  1383. efx->n_rx_nodesc_drop_cnt +=
  1384. EFX_OWORD_FIELD(cnt, FRF_AB_RX_NODESC_DROP_CNT);
  1385. if (nic_data->stats_pending &&
  1386. *nic_data->stats_dma_done == FALCON_STATS_DONE) {
  1387. nic_data->stats_pending = false;
  1388. rmb(); /* read the done flag before the stats */
  1389. efx->mac_op->update_stats(efx);
  1390. }
  1391. }
  1392. void falcon_start_nic_stats(struct efx_nic *efx)
  1393. {
  1394. struct falcon_nic_data *nic_data = efx->nic_data;
  1395. spin_lock_bh(&efx->stats_lock);
  1396. if (--nic_data->stats_disable_count == 0)
  1397. falcon_stats_request(efx);
  1398. spin_unlock_bh(&efx->stats_lock);
  1399. }
  1400. void falcon_stop_nic_stats(struct efx_nic *efx)
  1401. {
  1402. struct falcon_nic_data *nic_data = efx->nic_data;
  1403. int i;
  1404. might_sleep();
  1405. spin_lock_bh(&efx->stats_lock);
  1406. ++nic_data->stats_disable_count;
  1407. spin_unlock_bh(&efx->stats_lock);
  1408. del_timer_sync(&nic_data->stats_timer);
  1409. /* Wait enough time for the most recent transfer to
  1410. * complete. */
  1411. for (i = 0; i < 4 && nic_data->stats_pending; i++) {
  1412. if (*nic_data->stats_dma_done == FALCON_STATS_DONE)
  1413. break;
  1414. msleep(1);
  1415. }
  1416. spin_lock_bh(&efx->stats_lock);
  1417. falcon_stats_complete(efx);
  1418. spin_unlock_bh(&efx->stats_lock);
  1419. }
  1420. static void falcon_set_id_led(struct efx_nic *efx, enum efx_led_mode mode)
  1421. {
  1422. falcon_board(efx)->type->set_id_led(efx, mode);
  1423. }
  1424. /**************************************************************************
  1425. *
  1426. * Wake on LAN
  1427. *
  1428. **************************************************************************
  1429. */
  1430. static void falcon_get_wol(struct efx_nic *efx, struct ethtool_wolinfo *wol)
  1431. {
  1432. wol->supported = 0;
  1433. wol->wolopts = 0;
  1434. memset(&wol->sopass, 0, sizeof(wol->sopass));
  1435. }
  1436. static int falcon_set_wol(struct efx_nic *efx, u32 type)
  1437. {
  1438. if (type != 0)
  1439. return -EINVAL;
  1440. return 0;
  1441. }
  1442. /**************************************************************************
  1443. *
  1444. * Revision-dependent attributes used by efx.c and nic.c
  1445. *
  1446. **************************************************************************
  1447. */
  1448. struct efx_nic_type falcon_a1_nic_type = {
  1449. .probe = falcon_probe_nic,
  1450. .remove = falcon_remove_nic,
  1451. .init = falcon_init_nic,
  1452. .fini = efx_port_dummy_op_void,
  1453. .monitor = falcon_monitor,
  1454. .reset = falcon_reset_hw,
  1455. .probe_port = falcon_probe_port,
  1456. .remove_port = falcon_remove_port,
  1457. .prepare_flush = falcon_prepare_flush,
  1458. .update_stats = falcon_update_nic_stats,
  1459. .start_stats = falcon_start_nic_stats,
  1460. .stop_stats = falcon_stop_nic_stats,
  1461. .set_id_led = falcon_set_id_led,
  1462. .push_irq_moderation = falcon_push_irq_moderation,
  1463. .push_multicast_hash = falcon_push_multicast_hash,
  1464. .reconfigure_port = falcon_reconfigure_port,
  1465. .get_wol = falcon_get_wol,
  1466. .set_wol = falcon_set_wol,
  1467. .resume_wol = efx_port_dummy_op_void,
  1468. .test_nvram = falcon_test_nvram,
  1469. .default_mac_ops = &falcon_xmac_operations,
  1470. .revision = EFX_REV_FALCON_A1,
  1471. .mem_map_size = 0x20000,
  1472. .txd_ptr_tbl_base = FR_AA_TX_DESC_PTR_TBL_KER,
  1473. .rxd_ptr_tbl_base = FR_AA_RX_DESC_PTR_TBL_KER,
  1474. .buf_tbl_base = FR_AA_BUF_FULL_TBL_KER,
  1475. .evq_ptr_tbl_base = FR_AA_EVQ_PTR_TBL_KER,
  1476. .evq_rptr_tbl_base = FR_AA_EVQ_RPTR_KER,
  1477. .max_dma_mask = DMA_BIT_MASK(FSF_AZ_TX_KER_BUF_ADDR_WIDTH),
  1478. .rx_buffer_padding = 0x24,
  1479. .max_interrupt_mode = EFX_INT_MODE_MSI,
  1480. .phys_addr_channels = 4,
  1481. .tx_dc_base = 0x130000,
  1482. .rx_dc_base = 0x100000,
  1483. .offload_features = NETIF_F_IP_CSUM,
  1484. .reset_world_flags = ETH_RESET_IRQ,
  1485. };
  1486. struct efx_nic_type falcon_b0_nic_type = {
  1487. .probe = falcon_probe_nic,
  1488. .remove = falcon_remove_nic,
  1489. .init = falcon_init_nic,
  1490. .fini = efx_port_dummy_op_void,
  1491. .monitor = falcon_monitor,
  1492. .reset = falcon_reset_hw,
  1493. .probe_port = falcon_probe_port,
  1494. .remove_port = falcon_remove_port,
  1495. .prepare_flush = falcon_prepare_flush,
  1496. .update_stats = falcon_update_nic_stats,
  1497. .start_stats = falcon_start_nic_stats,
  1498. .stop_stats = falcon_stop_nic_stats,
  1499. .set_id_led = falcon_set_id_led,
  1500. .push_irq_moderation = falcon_push_irq_moderation,
  1501. .push_multicast_hash = falcon_push_multicast_hash,
  1502. .reconfigure_port = falcon_reconfigure_port,
  1503. .get_wol = falcon_get_wol,
  1504. .set_wol = falcon_set_wol,
  1505. .resume_wol = efx_port_dummy_op_void,
  1506. .test_registers = falcon_b0_test_registers,
  1507. .test_nvram = falcon_test_nvram,
  1508. .default_mac_ops = &falcon_xmac_operations,
  1509. .revision = EFX_REV_FALCON_B0,
  1510. /* Map everything up to and including the RSS indirection
  1511. * table. Don't map MSI-X table, MSI-X PBA since Linux
  1512. * requires that they not be mapped. */
  1513. .mem_map_size = (FR_BZ_RX_INDIRECTION_TBL +
  1514. FR_BZ_RX_INDIRECTION_TBL_STEP *
  1515. FR_BZ_RX_INDIRECTION_TBL_ROWS),
  1516. .txd_ptr_tbl_base = FR_BZ_TX_DESC_PTR_TBL,
  1517. .rxd_ptr_tbl_base = FR_BZ_RX_DESC_PTR_TBL,
  1518. .buf_tbl_base = FR_BZ_BUF_FULL_TBL,
  1519. .evq_ptr_tbl_base = FR_BZ_EVQ_PTR_TBL,
  1520. .evq_rptr_tbl_base = FR_BZ_EVQ_RPTR,
  1521. .max_dma_mask = DMA_BIT_MASK(FSF_AZ_TX_KER_BUF_ADDR_WIDTH),
  1522. .rx_buffer_hash_size = 0x10,
  1523. .rx_buffer_padding = 0,
  1524. .max_interrupt_mode = EFX_INT_MODE_MSIX,
  1525. .phys_addr_channels = 32, /* Hardware limit is 64, but the legacy
  1526. * interrupt handler only supports 32
  1527. * channels */
  1528. .tx_dc_base = 0x130000,
  1529. .rx_dc_base = 0x100000,
  1530. .offload_features = NETIF_F_IP_CSUM | NETIF_F_RXHASH | NETIF_F_NTUPLE,
  1531. .reset_world_flags = ETH_RESET_IRQ,
  1532. };