falcon.c 49 KB

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