iPXE
etherfabric.c
Go to the documentation of this file.
1 /**************************************************************************
2  *
3  * Etherboot driver for Level 5 Etherfabric network cards
4  *
5  * Written by Michael Brown <mbrown@fensystems.co.uk>
6  *
7  * Copyright Fen Systems Ltd. 2005
8  * Copyright Level 5 Networks Inc. 2005
9  *
10  * This software may be used and distributed according to the terms of
11  * the GNU General Public License (GPL), incorporated herein by
12  * reference. Drivers based on or derived from this code fall under
13  * the GPL and must retain the authorship, copyright and license
14  * notice.
15  *
16  **************************************************************************
17  */
18 
19 FILE_LICENCE ( GPL_ANY );
20 
21 #include <stdint.h>
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <string.h>
25 #include <unistd.h>
26 #include <errno.h>
27 #include <assert.h>
28 #include <byteswap.h>
29 #include <ipxe/io.h>
30 #include <ipxe/pci.h>
31 #include <ipxe/malloc.h>
32 #include <ipxe/ethernet.h>
33 #include <ipxe/iobuf.h>
34 #include <ipxe/netdevice.h>
35 #include <ipxe/timer.h>
36 #include <mii.h>
37 #include "etherfabric.h"
38 #include "etherfabric_nic.h"
39 
40 /**************************************************************************
41  *
42  * Constants and macros
43  *
44  **************************************************************************
45  */
46 
47 #define EFAB_REGDUMP(...)
48 #define EFAB_TRACE(...) DBGP(__VA_ARGS__)
49 
50 // printf() is not allowed within drivers. Use DBG() instead.
51 #define EFAB_LOG(...) DBG(__VA_ARGS__)
52 #define EFAB_ERR(...) DBG(__VA_ARGS__)
53 
54 #define FALCON_USE_IO_BAR 0
55 
56 #define HZ 100
57 #define EFAB_BYTE 1
58 
59 /**************************************************************************
60  *
61  * Hardware data structures and sizing
62  *
63  **************************************************************************
64  */
65 extern int __invalid_queue_size;
66 #define FQS(_prefix, _x) \
67  ( ( (_x) == 512 ) ? _prefix ## _SIZE_512 : \
68  ( ( (_x) == 1024 ) ? _prefix ## _SIZE_1K : \
69  ( ( (_x) == 2048 ) ? _prefix ## _SIZE_2K : \
70  ( ( (_x) == 4096) ? _prefix ## _SIZE_4K : \
71  __invalid_queue_size ) ) ) )
72 
73 
74 #define EFAB_MAX_FRAME_LEN(mtu) \
75  ( ( ( ( mtu ) + 4/* FCS */ ) + 7 ) & ~7 )
76 
77 /**************************************************************************
78  *
79  * GMII routines
80  *
81  **************************************************************************
82  */
83 
84 static void falcon_mdio_write (struct efab_nic *efab, int device,
85  int location, int value );
86 static int falcon_mdio_read ( struct efab_nic *efab, int device, int location );
87 
88 /* GMII registers */
89 #define GMII_PSSR 0x11 /* PHY-specific status register */
90 
91 /* Pseudo extensions to the link partner ability register */
92 #define LPA_EF_1000FULL 0x00020000
93 #define LPA_EF_1000HALF 0x00010000
94 #define LPA_EF_10000FULL 0x00040000
95 #define LPA_EF_10000HALF 0x00080000
96 
97 #define LPA_EF_1000 ( LPA_EF_1000FULL | LPA_EF_1000HALF )
98 #define LPA_EF_10000 ( LPA_EF_10000FULL | LPA_EF_10000HALF )
99 #define LPA_EF_DUPLEX ( LPA_10FULL | LPA_100FULL | LPA_EF_1000FULL | \
100  LPA_EF_10000FULL )
101 
102 /* Mask of bits not associated with speed or duplexity. */
103 #define LPA_OTHER ~( LPA_10FULL | LPA_10HALF | LPA_100FULL | \
104  LPA_100HALF | LPA_EF_1000FULL | LPA_EF_1000HALF )
105 
106 /* PHY-specific status register */
107 #define PSSR_LSTATUS 0x0400 /* Bit 10 - link status */
108 
109 /**
110  * Retrieve GMII autonegotiation advertised abilities
111  *
112  */
113 static unsigned int
115 {
116  unsigned int mii_advertise;
117  unsigned int gmii_advertise;
118 
119  /* Extended bits are in bits 8 and 9 of MII_CTRL1000 */
120  mii_advertise = falcon_mdio_read ( efab, 0, MII_ADVERTISE );
121  gmii_advertise = ( ( falcon_mdio_read ( efab, 0, MII_CTRL1000 ) >> 8 )
122  & 0x03 );
123  return ( ( gmii_advertise << 16 ) | mii_advertise );
124 }
125 
126 /**
127  * Retrieve GMII autonegotiation link partner abilities
128  *
129  */
130 static unsigned int
131 gmii_autoneg_lpa ( struct efab_nic *efab )
132 {
133  unsigned int mii_lpa;
134  unsigned int gmii_lpa;
135 
136  /* Extended bits are in bits 10 and 11 of MII_STAT1000 */
137  mii_lpa = falcon_mdio_read ( efab, 0, MII_LPA );
138  gmii_lpa = ( falcon_mdio_read ( efab, 0, MII_STAT1000 ) >> 10 ) & 0x03;
139  return ( ( gmii_lpa << 16 ) | mii_lpa );
140 }
141 
142 /**
143  * Calculate GMII autonegotiated link technology
144  *
145  */
146 static unsigned int
147 gmii_nway_result ( unsigned int negotiated )
148 {
149  unsigned int other_bits;
150 
151  /* Mask out the speed and duplexity bits */
152  other_bits = negotiated & LPA_OTHER;
153 
154  if ( negotiated & LPA_EF_1000FULL )
155  return ( other_bits | LPA_EF_1000FULL );
156  else if ( negotiated & LPA_EF_1000HALF )
157  return ( other_bits | LPA_EF_1000HALF );
158  else if ( negotiated & LPA_100FULL )
159  return ( other_bits | LPA_100FULL );
160  else if ( negotiated & LPA_100BASE4 )
161  return ( other_bits | LPA_100BASE4 );
162  else if ( negotiated & LPA_100HALF )
163  return ( other_bits | LPA_100HALF );
164  else if ( negotiated & LPA_10FULL )
165  return ( other_bits | LPA_10FULL );
166  else return ( other_bits | LPA_10HALF );
167 }
168 
169 /**
170  * Check GMII PHY link status
171  *
172  */
173 static int
174 gmii_link_ok ( struct efab_nic *efab )
175 {
176  int status;
177  int phy_status;
178 
179  /* BMSR is latching - it returns "link down" if the link has
180  * been down at any point since the last read. To get a
181  * real-time status, we therefore read the register twice and
182  * use the result of the second read.
183  */
184  (void) falcon_mdio_read ( efab, 0, MII_BMSR );
185  status = falcon_mdio_read ( efab, 0, MII_BMSR );
186 
187  /* Read the PHY-specific Status Register. This is
188  * non-latching, so we need do only a single read.
189  */
190  phy_status = falcon_mdio_read ( efab, 0, GMII_PSSR );
191 
192  return ( ( status & BMSR_LSTATUS ) && ( phy_status & PSSR_LSTATUS ) );
193 }
194 
195 /**************************************************************************
196  *
197  * MDIO routines
198  *
199  **************************************************************************
200  */
201 
202 /* Numbering of the MDIO Manageable Devices (MMDs) */
203 /* Physical Medium Attachment/ Physical Medium Dependent sublayer */
204 #define MDIO_MMD_PMAPMD (1)
205 /* WAN Interface Sublayer */
206 #define MDIO_MMD_WIS (2)
207 /* Physical Coding Sublayer */
208 #define MDIO_MMD_PCS (3)
209 /* PHY Extender Sublayer */
210 #define MDIO_MMD_PHYXS (4)
211 /* Extender Sublayer */
212 #define MDIO_MMD_DTEXS (5)
213 /* Transmission convergence */
214 #define MDIO_MMD_TC (6)
215 /* Auto negotiation */
216 #define MDIO_MMD_AN (7)
217 
218 /* Generic register locations */
219 #define MDIO_MMDREG_CTRL1 (0)
220 #define MDIO_MMDREG_STAT1 (1)
221 #define MDIO_MMDREG_DEVS0 (5)
222 #define MDIO_MMDREG_STAT2 (8)
223 
224 /* Bits in MMDREG_CTRL1 */
225 /* Reset */
226 #define MDIO_MMDREG_CTRL1_RESET_LBN (15)
227 #define MDIO_MMDREG_CTRL1_RESET_WIDTH (1)
228 
229 /* Bits in MMDREG_STAT1 */
230 #define MDIO_MMDREG_STAT1_FAULT_LBN (7)
231 #define MDIO_MMDREG_STAT1_FAULT_WIDTH (1)
232 
233 /* Link state */
234 #define MDIO_MMDREG_STAT1_LINK_LBN (2)
235 #define MDIO_MMDREG_STAT1_LINK_WIDTH (1)
236 
237 /* Bits in MMDREG_DEVS0. */
238 #define DEV_PRESENT_BIT(_b) (1 << _b)
239 
240 #define MDIO_MMDREG_DEVS0_DTEXS DEV_PRESENT_BIT(MDIO_MMD_DTEXS)
241 #define MDIO_MMDREG_DEVS0_PHYXS DEV_PRESENT_BIT(MDIO_MMD_PHYXS)
242 #define MDIO_MMDREG_DEVS0_PCS DEV_PRESENT_BIT(MDIO_MMD_PCS)
243 #define MDIO_MMDREG_DEVS0_WIS DEV_PRESENT_BIT(MDIO_MMD_WIS)
244 #define MDIO_MMDREG_DEVS0_PMAPMD DEV_PRESENT_BIT(MDIO_MMD_PMAPMD)
245 
246 #define MDIO_MMDREG_DEVS0_AN DEV_PRESENT_BIT(MDIO_MMD_AN)
247 
248 /* Bits in MMDREG_STAT2 */
249 #define MDIO_MMDREG_STAT2_PRESENT_VAL (2)
250 #define MDIO_MMDREG_STAT2_PRESENT_LBN (14)
251 #define MDIO_MMDREG_STAT2_PRESENT_WIDTH (2)
252 
253 /* PHY XGXS lane state */
254 #define MDIO_PHYXS_LANE_STATE (0x18)
255 #define MDIO_PHYXS_LANE_ALIGNED_LBN (12)
256 #define MDIO_PHYXS_LANE_SYNC0_LBN (0)
257 #define MDIO_PHYXS_LANE_SYNC1_LBN (1)
258 #define MDIO_PHYXS_LANE_SYNC2_LBN (2)
259 #define MDIO_PHYXS_LANE_SYNC3_LBN (3)
260 
261 /* This ought to be ridiculous overkill. We expect it to fail rarely */
262 #define MDIO45_RESET_TRIES 100
263 #define MDIO45_RESET_SPINTIME 10
264 
265 static int
267 {
268  int tries = MDIO45_RESET_TRIES;
269  int in_reset;
270 
271  while(tries) {
272  int mask = efab->phy_op->mmds;
273  int mmd = 0;
274  in_reset = 0;
275  while(mask) {
276  if (mask & 1) {
277  int stat = falcon_mdio_read ( efab, mmd,
279  if (stat < 0) {
280  EFAB_ERR("Failed to read status of MMD %d\n",
281  mmd );
282  in_reset = 1;
283  break;
284  }
285  if (stat & (1 << MDIO_MMDREG_CTRL1_RESET_LBN))
286  in_reset |= (1 << mmd);
287  }
288  mask = mask >> 1;
289  mmd++;
290  }
291  if (!in_reset)
292  break;
293  tries--;
295  }
296  if (in_reset != 0) {
297  EFAB_ERR("Not all MMDs came out of reset in time. MMDs "
298  "still in reset: %x\n", in_reset);
299  return -ETIMEDOUT;
300  }
301  return 0;
302 }
303 
304 static int
305 mdio_clause45_reset_mmd ( struct efab_nic *efab, int mmd )
306 {
307  int tries = MDIO45_RESET_TRIES;
308  int ctrl;
309 
311  ( 1 << MDIO_MMDREG_CTRL1_RESET_LBN ) );
312 
313  /* Wait for the reset bit to clear. */
314  do {
316 
317  ctrl = falcon_mdio_read ( efab, mmd, MDIO_MMDREG_CTRL1 );
318  if ( ~ctrl & ( 1 << MDIO_MMDREG_CTRL1_RESET_LBN ) )
319  return 0;
320  } while ( --tries );
321 
322  EFAB_ERR ( "Failed to reset mmd %d\n", mmd );
323 
324  return -ETIMEDOUT;
325 }
326 
327 static int
329 {
330  int status, good;
331  int ok = 1;
332  int mmd = 0;
333  int mmd_mask = efab->phy_op->mmds;
334 
335  while (mmd_mask) {
336  if (mmd_mask & 1) {
337  /* Double reads because link state is latched, and a
338  * read moves the current state into the register */
339  status = falcon_mdio_read ( efab, mmd,
341  status = falcon_mdio_read ( efab, mmd,
343 
344  good = status & (1 << MDIO_MMDREG_STAT1_LINK_LBN);
345  ok = ok && good;
346  }
347  mmd_mask = (mmd_mask >> 1);
348  mmd++;
349  }
350  return ok;
351 }
352 
353 static int
355 {
356  int mmd = 0;
357  int devices = falcon_mdio_read ( efab, MDIO_MMD_PHYXS,
359  int mmd_mask = efab->phy_op->mmds;
360 
361  /* Check all the expected MMDs are present */
362  if ( devices < 0 ) {
363  EFAB_ERR ( "Failed to read devices present\n" );
364  return -EIO;
365  }
366  if ( ( devices & mmd_mask ) != mmd_mask ) {
367  EFAB_ERR ( "required MMDs not present: got %x, wanted %x\n",
368  devices, mmd_mask );
369  return -EIO;
370  }
371 
372  /* Check all required MMDs are responding and happy. */
373  while ( mmd_mask ) {
374  if ( mmd_mask & 1 ) {
376  int status;
377  reg.opaque = falcon_mdio_read ( efab, mmd,
380  MDIO_MMDREG_STAT2_PRESENT );
382 
383 
384  return -EIO;
385  }
386  }
387  mmd_mask >>= 1;
388  mmd++;
389  }
390 
391  return 0;
392 }
393 
394 /* I/O BAR address register */
395 #define FCN_IOM_IND_ADR_REG 0x0
396 
397 /* I/O BAR data register */
398 #define FCN_IOM_IND_DAT_REG 0x4
399 
400 /* Address region register */
401 #define FCN_ADR_REGION_REG_KER 0x00
402 #define FCN_ADR_REGION0_LBN 0
403 #define FCN_ADR_REGION0_WIDTH 18
404 #define FCN_ADR_REGION1_LBN 32
405 #define FCN_ADR_REGION1_WIDTH 18
406 #define FCN_ADR_REGION2_LBN 64
407 #define FCN_ADR_REGION2_WIDTH 18
408 #define FCN_ADR_REGION3_LBN 96
409 #define FCN_ADR_REGION3_WIDTH 18
410 
411 /* Interrupt enable register */
412 #define FCN_INT_EN_REG_KER 0x0010
413 #define FCN_MEM_PERR_INT_EN_KER_LBN 5
414 #define FCN_MEM_PERR_INT_EN_KER_WIDTH 1
415 #define FCN_KER_INT_CHAR_LBN 4
416 #define FCN_KER_INT_CHAR_WIDTH 1
417 #define FCN_KER_INT_KER_LBN 3
418 #define FCN_KER_INT_KER_WIDTH 1
419 #define FCN_ILL_ADR_ERR_INT_EN_KER_LBN 2
420 #define FCN_ILL_ADR_ERR_INT_EN_KER_WIDTH 1
421 #define FCN_SRM_PERR_INT_EN_KER_LBN 1
422 #define FCN_SRM_PERR_INT_EN_KER_WIDTH 1
423 #define FCN_DRV_INT_EN_KER_LBN 0
424 #define FCN_DRV_INT_EN_KER_WIDTH 1
425 
426 /* Interrupt status register */
427 #define FCN_INT_ADR_REG_KER 0x0030
428 #define FCN_INT_ADR_KER_LBN 0
429 #define FCN_INT_ADR_KER_WIDTH EFAB_DMA_TYPE_WIDTH ( 64 )
430 
431 /* Interrupt status register (B0 only) */
432 #define INT_ISR0_B0 0x90
433 #define INT_ISR1_B0 0xA0
434 
435 /* Interrupt acknowledge register (A0/A1 only) */
436 #define FCN_INT_ACK_KER_REG_A1 0x0050
437 #define INT_ACK_DUMMY_DATA_LBN 0
438 #define INT_ACK_DUMMY_DATA_WIDTH 32
439 
440 /* Interrupt acknowledge work-around register (A0/A1 only )*/
441 #define WORK_AROUND_BROKEN_PCI_READS_REG_KER_A1 0x0070
442 
443 /* Hardware initialisation register */
444 #define FCN_HW_INIT_REG_KER 0x00c0
445 #define FCN_BCSR_TARGET_MASK_LBN 101
446 #define FCN_BCSR_TARGET_MASK_WIDTH 4
447 
448 /* SPI host command register */
449 #define FCN_EE_SPI_HCMD_REG 0x0100
450 #define FCN_EE_SPI_HCMD_CMD_EN_LBN 31
451 #define FCN_EE_SPI_HCMD_CMD_EN_WIDTH 1
452 #define FCN_EE_WR_TIMER_ACTIVE_LBN 28
453 #define FCN_EE_WR_TIMER_ACTIVE_WIDTH 1
454 #define FCN_EE_SPI_HCMD_SF_SEL_LBN 24
455 #define FCN_EE_SPI_HCMD_SF_SEL_WIDTH 1
456 #define FCN_EE_SPI_EEPROM 0
457 #define FCN_EE_SPI_FLASH 1
458 #define FCN_EE_SPI_HCMD_DABCNT_LBN 16
459 #define FCN_EE_SPI_HCMD_DABCNT_WIDTH 5
460 #define FCN_EE_SPI_HCMD_READ_LBN 15
461 #define FCN_EE_SPI_HCMD_READ_WIDTH 1
462 #define FCN_EE_SPI_READ 1
463 #define FCN_EE_SPI_WRITE 0
464 #define FCN_EE_SPI_HCMD_DUBCNT_LBN 12
465 #define FCN_EE_SPI_HCMD_DUBCNT_WIDTH 2
466 #define FCN_EE_SPI_HCMD_ADBCNT_LBN 8
467 #define FCN_EE_SPI_HCMD_ADBCNT_WIDTH 2
468 #define FCN_EE_SPI_HCMD_ENC_LBN 0
469 #define FCN_EE_SPI_HCMD_ENC_WIDTH 8
470 
471 /* SPI host address register */
472 #define FCN_EE_SPI_HADR_REG 0x0110
473 #define FCN_EE_SPI_HADR_DUBYTE_LBN 24
474 #define FCN_EE_SPI_HADR_DUBYTE_WIDTH 8
475 #define FCN_EE_SPI_HADR_ADR_LBN 0
476 #define FCN_EE_SPI_HADR_ADR_WIDTH 24
477 
478 /* SPI host data register */
479 #define FCN_EE_SPI_HDATA_REG 0x0120
480 #define FCN_EE_SPI_HDATA3_LBN 96
481 #define FCN_EE_SPI_HDATA3_WIDTH 32
482 #define FCN_EE_SPI_HDATA2_LBN 64
483 #define FCN_EE_SPI_HDATA2_WIDTH 32
484 #define FCN_EE_SPI_HDATA1_LBN 32
485 #define FCN_EE_SPI_HDATA1_WIDTH 32
486 #define FCN_EE_SPI_HDATA0_LBN 0
487 #define FCN_EE_SPI_HDATA0_WIDTH 32
488 
489 /* VPD Config 0 Register register */
490 #define FCN_EE_VPD_CFG_REG 0x0140
491 #define FCN_EE_VPD_EN_LBN 0
492 #define FCN_EE_VPD_EN_WIDTH 1
493 #define FCN_EE_VPD_EN_AD9_MODE_LBN 1
494 #define FCN_EE_VPD_EN_AD9_MODE_WIDTH 1
495 #define FCN_EE_EE_CLOCK_DIV_LBN 112
496 #define FCN_EE_EE_CLOCK_DIV_WIDTH 7
497 #define FCN_EE_SF_CLOCK_DIV_LBN 120
498 #define FCN_EE_SF_CLOCK_DIV_WIDTH 7
499 
500 
501 /* NIC status register */
502 #define FCN_NIC_STAT_REG 0x0200
503 #define FCN_ONCHIP_SRAM_LBN 16
504 #define FCN_ONCHIP_SRAM_WIDTH 1
505 #define FCN_SF_PRST_LBN 9
506 #define FCN_SF_PRST_WIDTH 1
507 #define FCN_EE_PRST_LBN 8
508 #define FCN_EE_PRST_WIDTH 1
509 #define FCN_EE_STRAP_LBN 7
510 #define FCN_EE_STRAP_WIDTH 1
511 #define FCN_PCI_PCIX_MODE_LBN 4
512 #define FCN_PCI_PCIX_MODE_WIDTH 3
513 #define FCN_PCI_PCIX_MODE_PCI33_DECODE 0
514 #define FCN_PCI_PCIX_MODE_PCI66_DECODE 1
515 #define FCN_PCI_PCIX_MODE_PCIX66_DECODE 5
516 #define FCN_PCI_PCIX_MODE_PCIX100_DECODE 6
517 #define FCN_PCI_PCIX_MODE_PCIX133_DECODE 7
518 #define FCN_STRAP_ISCSI_EN_LBN 3
519 #define FCN_STRAP_ISCSI_EN_WIDTH 1
520 #define FCN_STRAP_PINS_LBN 0
521 #define FCN_STRAP_PINS_WIDTH 3
522 #define FCN_STRAP_10G_LBN 2
523 #define FCN_STRAP_10G_WIDTH 1
524 #define FCN_STRAP_DUAL_PORT_LBN 1
525 #define FCN_STRAP_DUAL_PORT_WIDTH 1
526 #define FCN_STRAP_PCIE_LBN 0
527 #define FCN_STRAP_PCIE_WIDTH 1
528 
529 /* Falcon revisions */
530 #define FALCON_REV_A0 0
531 #define FALCON_REV_A1 1
532 #define FALCON_REV_B0 2
533 
534 /* GPIO control register */
535 #define FCN_GPIO_CTL_REG_KER 0x0210
536 #define FCN_GPIO_CTL_REG_KER 0x0210
537 
538 #define FCN_GPIO3_OEN_LBN 27
539 #define FCN_GPIO3_OEN_WIDTH 1
540 #define FCN_GPIO2_OEN_LBN 26
541 #define FCN_GPIO2_OEN_WIDTH 1
542 #define FCN_GPIO1_OEN_LBN 25
543 #define FCN_GPIO1_OEN_WIDTH 1
544 #define FCN_GPIO0_OEN_LBN 24
545 #define FCN_GPIO0_OEN_WIDTH 1
546 
547 #define FCN_GPIO3_OUT_LBN 19
548 #define FCN_GPIO3_OUT_WIDTH 1
549 #define FCN_GPIO2_OUT_LBN 18
550 #define FCN_GPIO2_OUT_WIDTH 1
551 #define FCN_GPIO1_OUT_LBN 17
552 #define FCN_GPIO1_OUT_WIDTH 1
553 #define FCN_GPIO0_OUT_LBN 16
554 #define FCN_GPIO0_OUT_WIDTH 1
555 
556 #define FCN_GPIO3_IN_LBN 11
557 #define FCN_GPIO3_IN_WIDTH 1
558 #define FCN_GPIO2_IN_LBN 10
559 #define FCN_GPIO2_IN_WIDTH 1
560 #define FCN_GPIO1_IN_LBN 9
561 #define FCN_GPIO1_IN_WIDTH 1
562 #define FCN_GPIO0_IN_LBN 8
563 #define FCN_GPIO0_IN_WIDTH 1
564 
565 #define FCN_FLASH_PRESENT_LBN 7
566 #define FCN_FLASH_PRESENT_WIDTH 1
567 #define FCN_EEPROM_PRESENT_LBN 6
568 #define FCN_EEPROM_PRESENT_WIDTH 1
569 #define FCN_BOOTED_USING_NVDEVICE_LBN 3
570 #define FCN_BOOTED_USING_NVDEVICE_WIDTH 1
571 
572 /* Defines for extra non-volatile storage */
573 #define FCN_NV_MAGIC_NUMBER 0xFA1C
574 
575 /* Global control register */
576 #define FCN_GLB_CTL_REG_KER 0x0220
577 #define FCN_EXT_PHY_RST_CTL_LBN 63
578 #define FCN_EXT_PHY_RST_CTL_WIDTH 1
579 #define FCN_PCIE_SD_RST_CTL_LBN 61
580 #define FCN_PCIE_SD_RST_CTL_WIDTH 1
581 #define FCN_PCIE_STCK_RST_CTL_LBN 59
582 #define FCN_PCIE_STCK_RST_CTL_WIDTH 1
583 #define FCN_PCIE_NSTCK_RST_CTL_LBN 58
584 #define FCN_PCIE_NSTCK_RST_CTL_WIDTH 1
585 #define FCN_PCIE_CORE_RST_CTL_LBN 57
586 #define FCN_PCIE_CORE_RST_CTL_WIDTH 1
587 #define FCN_EE_RST_CTL_LBN 49
588 #define FCN_EE_RST_CTL_WIDTH 1
589 #define FCN_RST_EXT_PHY_LBN 31
590 #define FCN_RST_EXT_PHY_WIDTH 1
591 #define FCN_EXT_PHY_RST_DUR_LBN 1
592 #define FCN_EXT_PHY_RST_DUR_WIDTH 3
593 #define FCN_SWRST_LBN 0
594 #define FCN_SWRST_WIDTH 1
595 #define INCLUDE_IN_RESET 0
596 #define EXCLUDE_FROM_RESET 1
597 
598 /* FPGA build version */
599 #define FCN_ALTERA_BUILD_REG_KER 0x0300
600 #define FCN_VER_MAJOR_LBN 24
601 #define FCN_VER_MAJOR_WIDTH 8
602 #define FCN_VER_MINOR_LBN 16
603 #define FCN_VER_MINOR_WIDTH 8
604 #define FCN_VER_BUILD_LBN 0
605 #define FCN_VER_BUILD_WIDTH 16
606 #define FCN_VER_ALL_LBN 0
607 #define FCN_VER_ALL_WIDTH 32
608 
609 /* Spare EEPROM bits register (flash 0x390) */
610 #define FCN_SPARE_REG_KER 0x310
611 #define FCN_MEM_PERR_EN_TX_DATA_LBN 72
612 #define FCN_MEM_PERR_EN_TX_DATA_WIDTH 2
613 
614 /* Timer table for kernel access */
615 #define FCN_TIMER_CMD_REG_KER 0x420
616 #define FCN_TIMER_MODE_LBN 12
617 #define FCN_TIMER_MODE_WIDTH 2
618 #define FCN_TIMER_MODE_DIS 0
619 #define FCN_TIMER_MODE_INT_HLDOFF 1
620 #define FCN_TIMER_VAL_LBN 0
621 #define FCN_TIMER_VAL_WIDTH 12
622 
623 /* Receive configuration register */
624 #define FCN_RX_CFG_REG_KER 0x800
625 #define FCN_RX_XOFF_EN_LBN 0
626 #define FCN_RX_XOFF_EN_WIDTH 1
627 
628 /* SRAM receive descriptor cache configuration register */
629 #define FCN_SRM_RX_DC_CFG_REG_KER 0x610
630 #define FCN_SRM_RX_DC_BASE_ADR_LBN 0
631 #define FCN_SRM_RX_DC_BASE_ADR_WIDTH 21
632 
633 /* SRAM transmit descriptor cache configuration register */
634 #define FCN_SRM_TX_DC_CFG_REG_KER 0x620
635 #define FCN_SRM_TX_DC_BASE_ADR_LBN 0
636 #define FCN_SRM_TX_DC_BASE_ADR_WIDTH 21
637 
638 /* SRAM configuration register */
639 #define FCN_SRM_CFG_REG_KER 0x630
640 #define FCN_SRAM_OOB_ADR_INTEN_LBN 5
641 #define FCN_SRAM_OOB_ADR_INTEN_WIDTH 1
642 #define FCN_SRAM_OOB_BUF_INTEN_LBN 4
643 #define FCN_SRAM_OOB_BUF_INTEN_WIDTH 1
644 #define FCN_SRAM_OOB_BT_INIT_EN_LBN 3
645 #define FCN_SRAM_OOB_BT_INIT_EN_WIDTH 1
646 #define FCN_SRM_NUM_BANK_LBN 2
647 #define FCN_SRM_NUM_BANK_WIDTH 1
648 #define FCN_SRM_BANK_SIZE_LBN 0
649 #define FCN_SRM_BANK_SIZE_WIDTH 2
650 #define FCN_SRM_NUM_BANKS_AND_BANK_SIZE_LBN 0
651 #define FCN_SRM_NUM_BANKS_AND_BANK_SIZE_WIDTH 3
652 
653 #define FCN_RX_CFG_REG_KER 0x800
654 #define FCN_RX_INGR_EN_B0_LBN 47
655 #define FCN_RX_INGR_EN_B0_WIDTH 1
656 #define FCN_RX_USR_BUF_SIZE_B0_LBN 19
657 #define FCN_RX_USR_BUF_SIZE_B0_WIDTH 9
658 #define FCN_RX_XON_MAC_TH_B0_LBN 10
659 #define FCN_RX_XON_MAC_TH_B0_WIDTH 9
660 #define FCN_RX_XOFF_MAC_TH_B0_LBN 1
661 #define FCN_RX_XOFF_MAC_TH_B0_WIDTH 9
662 #define FCN_RX_XOFF_MAC_EN_B0_LBN 0
663 #define FCN_RX_XOFF_MAC_EN_B0_WIDTH 1
664 #define FCN_RX_USR_BUF_SIZE_A1_LBN 11
665 #define FCN_RX_USR_BUF_SIZE_A1_WIDTH 9
666 #define FCN_RX_XON_MAC_TH_A1_LBN 6
667 #define FCN_RX_XON_MAC_TH_A1_WIDTH 5
668 #define FCN_RX_XOFF_MAC_TH_A1_LBN 1
669 #define FCN_RX_XOFF_MAC_TH_A1_WIDTH 5
670 #define FCN_RX_XOFF_MAC_EN_A1_LBN 0
671 #define FCN_RX_XOFF_MAC_EN_A1_WIDTH 1
672 
673 #define FCN_RX_USR_BUF_SIZE_A1_LBN 11
674 #define FCN_RX_USR_BUF_SIZE_A1_WIDTH 9
675 #define FCN_RX_XOFF_MAC_EN_A1_LBN 0
676 #define FCN_RX_XOFF_MAC_EN_A1_WIDTH 1
677 
678 /* Receive filter control register */
679 #define FCN_RX_FILTER_CTL_REG_KER 0x810
680 #define FCN_UDP_FULL_SRCH_LIMIT_LBN 32
681 #define FCN_UDP_FULL_SRCH_LIMIT_WIDTH 8
682 #define FCN_NUM_KER_LBN 24
683 #define FCN_NUM_KER_WIDTH 2
684 #define FCN_UDP_WILD_SRCH_LIMIT_LBN 16
685 #define FCN_UDP_WILD_SRCH_LIMIT_WIDTH 8
686 #define FCN_TCP_WILD_SRCH_LIMIT_LBN 8
687 #define FCN_TCP_WILD_SRCH_LIMIT_WIDTH 8
688 #define FCN_TCP_FULL_SRCH_LIMIT_LBN 0
689 #define FCN_TCP_FULL_SRCH_LIMIT_WIDTH 8
690 
691 /* RX queue flush register */
692 #define FCN_RX_FLUSH_DESCQ_REG_KER 0x0820
693 #define FCN_RX_FLUSH_DESCQ_CMD_LBN 24
694 #define FCN_RX_FLUSH_DESCQ_CMD_WIDTH 1
695 #define FCN_RX_FLUSH_DESCQ_LBN 0
696 #define FCN_RX_FLUSH_DESCQ_WIDTH 12
697 
698 /* Receive descriptor update register */
699 #define FCN_RX_DESC_UPD_REG_KER 0x0830
700 #define FCN_RX_DESC_WPTR_LBN 96
701 #define FCN_RX_DESC_WPTR_WIDTH 12
702 #define FCN_RX_DESC_UPD_REG_KER_DWORD ( FCN_RX_DESC_UPD_REG_KER + 12 )
703 #define FCN_RX_DESC_WPTR_DWORD_LBN 0
704 #define FCN_RX_DESC_WPTR_DWORD_WIDTH 12
705 
706 /* Receive descriptor cache configuration register */
707 #define FCN_RX_DC_CFG_REG_KER 0x840
708 #define FCN_RX_DC_SIZE_LBN 0
709 #define FCN_RX_DC_SIZE_WIDTH 2
710 
711 #define FCN_RX_SELF_RST_REG_KER 0x890
712 #define FCN_RX_ISCSI_DIS_LBN 17
713 #define FCN_RX_ISCSI_DIS_WIDTH 1
714 #define FCN_RX_NODESC_WAIT_DIS_LBN 9
715 #define FCN_RX_NODESC_WAIT_DIS_WIDTH 1
716 #define FCN_RX_RECOVERY_EN_LBN 8
717 #define FCN_RX_RECOVERY_EN_WIDTH 1
718 
719 /* TX queue flush register */
720 #define FCN_TX_FLUSH_DESCQ_REG_KER 0x0a00
721 #define FCN_TX_FLUSH_DESCQ_CMD_LBN 12
722 #define FCN_TX_FLUSH_DESCQ_CMD_WIDTH 1
723 #define FCN_TX_FLUSH_DESCQ_LBN 0
724 #define FCN_TX_FLUSH_DESCQ_WIDTH 12
725 
726 /* Transmit configuration register 2 */
727 #define FCN_TX_CFG2_REG_KER 0xa80
728 #define FCN_TX_DIS_NON_IP_EV_LBN 17
729 #define FCN_TX_DIS_NON_IP_EV_WIDTH 1
730 
731 /* Transmit descriptor update register */
732 #define FCN_TX_DESC_UPD_REG_KER 0x0a10
733 #define FCN_TX_DESC_WPTR_LBN 96
734 #define FCN_TX_DESC_WPTR_WIDTH 12
735 #define FCN_TX_DESC_UPD_REG_KER_DWORD ( FCN_TX_DESC_UPD_REG_KER + 12 )
736 #define FCN_TX_DESC_WPTR_DWORD_LBN 0
737 #define FCN_TX_DESC_WPTR_DWORD_WIDTH 12
738 
739 /* Transmit descriptor cache configuration register */
740 #define FCN_TX_DC_CFG_REG_KER 0xa20
741 #define FCN_TX_DC_SIZE_LBN 0
742 #define FCN_TX_DC_SIZE_WIDTH 2
743 
744 /* PHY management transmit data register */
745 #define FCN_MD_TXD_REG_KER 0xc00
746 #define FCN_MD_TXD_LBN 0
747 #define FCN_MD_TXD_WIDTH 16
748 
749 /* PHY management receive data register */
750 #define FCN_MD_RXD_REG_KER 0xc10
751 #define FCN_MD_RXD_LBN 0
752 #define FCN_MD_RXD_WIDTH 16
753 
754 /* PHY management configuration & status register */
755 #define FCN_MD_CS_REG_KER 0xc20
756 #define FCN_MD_GC_LBN 4
757 #define FCN_MD_GC_WIDTH 1
758 #define FCN_MD_RIC_LBN 2
759 #define FCN_MD_RIC_WIDTH 1
760 #define FCN_MD_RDC_LBN 1
761 #define FCN_MD_RDC_WIDTH 1
762 #define FCN_MD_WRC_LBN 0
763 #define FCN_MD_WRC_WIDTH 1
764 
765 /* PHY management PHY address register */
766 #define FCN_MD_PHY_ADR_REG_KER 0xc30
767 #define FCN_MD_PHY_ADR_LBN 0
768 #define FCN_MD_PHY_ADR_WIDTH 16
769 
770 /* PHY management ID register */
771 #define FCN_MD_ID_REG_KER 0xc40
772 #define FCN_MD_PRT_ADR_LBN 11
773 #define FCN_MD_PRT_ADR_WIDTH 5
774 #define FCN_MD_DEV_ADR_LBN 6
775 #define FCN_MD_DEV_ADR_WIDTH 5
776 
777 /* PHY management status & mask register */
778 #define FCN_MD_STAT_REG_KER 0xc50
779 #define FCN_MD_PINT_LBN 4
780 #define FCN_MD_PINT_WIDTH 1
781 #define FCN_MD_DONE_LBN 3
782 #define FCN_MD_DONE_WIDTH 1
783 #define FCN_MD_BSERR_LBN 2
784 #define FCN_MD_BSERR_WIDTH 1
785 #define FCN_MD_LNFL_LBN 1
786 #define FCN_MD_LNFL_WIDTH 1
787 #define FCN_MD_BSY_LBN 0
788 #define FCN_MD_BSY_WIDTH 1
789 
790 /* Port 0 and 1 MAC control registers */
791 #define FCN_MAC0_CTRL_REG_KER 0xc80
792 #define FCN_MAC1_CTRL_REG_KER 0xc90
793 #define FCN_MAC_XOFF_VAL_LBN 16
794 #define FCN_MAC_XOFF_VAL_WIDTH 16
795 #define FCN_MAC_BCAD_ACPT_LBN 4
796 #define FCN_MAC_BCAD_ACPT_WIDTH 1
797 #define FCN_MAC_UC_PROM_LBN 3
798 #define FCN_MAC_UC_PROM_WIDTH 1
799 #define FCN_MAC_LINK_STATUS_LBN 2
800 #define FCN_MAC_LINK_STATUS_WIDTH 1
801 #define FCN_MAC_SPEED_LBN 0
802 #define FCN_MAC_SPEED_WIDTH 2
803 
804 /* 10Gig Xaui XGXS Default Values */
805 #define XX_TXDRV_DEQ_DEFAULT 0xe /* deq=.6 */
806 #define XX_TXDRV_DTX_DEFAULT 0x5 /* 1.25 */
807 #define XX_SD_CTL_DRV_DEFAULT 0 /* 20mA */
808 
809 /* GMAC registers */
810 #define FALCON_GMAC_REGBANK 0xe00
811 #define FALCON_GMAC_REGBANK_SIZE 0x200
812 #define FALCON_GMAC_REG_SIZE 0x10
813 
814 /* XGMAC registers */
815 #define FALCON_XMAC_REGBANK 0x1200
816 #define FALCON_XMAC_REGBANK_SIZE 0x200
817 #define FALCON_XMAC_REG_SIZE 0x10
818 
819 /* XGMAC address register low */
820 #define FCN_XM_ADR_LO_REG_MAC 0x00
821 #define FCN_XM_ADR_3_LBN 24
822 #define FCN_XM_ADR_3_WIDTH 8
823 #define FCN_XM_ADR_2_LBN 16
824 #define FCN_XM_ADR_2_WIDTH 8
825 #define FCN_XM_ADR_1_LBN 8
826 #define FCN_XM_ADR_1_WIDTH 8
827 #define FCN_XM_ADR_0_LBN 0
828 #define FCN_XM_ADR_0_WIDTH 8
829 
830 /* XGMAC address register high */
831 #define FCN_XM_ADR_HI_REG_MAC 0x01
832 #define FCN_XM_ADR_5_LBN 8
833 #define FCN_XM_ADR_5_WIDTH 8
834 #define FCN_XM_ADR_4_LBN 0
835 #define FCN_XM_ADR_4_WIDTH 8
836 
837 /* XGMAC global configuration - port 0*/
838 #define FCN_XM_GLB_CFG_REG_MAC 0x02
839 #define FCN_XM_RX_STAT_EN_LBN 11
840 #define FCN_XM_RX_STAT_EN_WIDTH 1
841 #define FCN_XM_TX_STAT_EN_LBN 10
842 #define FCN_XM_TX_STAT_EN_WIDTH 1
843 #define FCN_XM_RX_JUMBO_MODE_LBN 6
844 #define FCN_XM_RX_JUMBO_MODE_WIDTH 1
845 #define FCN_XM_CORE_RST_LBN 0
846 #define FCN_XM_CORE_RST_WIDTH 1
847 
848 /* XGMAC transmit configuration - port 0 */
849 #define FCN_XM_TX_CFG_REG_MAC 0x03
850 #define FCN_XM_IPG_LBN 16
851 #define FCN_XM_IPG_WIDTH 4
852 #define FCN_XM_FCNTL_LBN 10
853 #define FCN_XM_FCNTL_WIDTH 1
854 #define FCN_XM_TXCRC_LBN 8
855 #define FCN_XM_TXCRC_WIDTH 1
856 #define FCN_XM_AUTO_PAD_LBN 5
857 #define FCN_XM_AUTO_PAD_WIDTH 1
858 #define FCN_XM_TX_PRMBL_LBN 2
859 #define FCN_XM_TX_PRMBL_WIDTH 1
860 #define FCN_XM_TXEN_LBN 1
861 #define FCN_XM_TXEN_WIDTH 1
862 
863 /* XGMAC receive configuration - port 0 */
864 #define FCN_XM_RX_CFG_REG_MAC 0x04
865 #define FCN_XM_PASS_CRC_ERR_LBN 25
866 #define FCN_XM_PASS_CRC_ERR_WIDTH 1
867 #define FCN_XM_AUTO_DEPAD_LBN 8
868 #define FCN_XM_AUTO_DEPAD_WIDTH 1
869 #define FCN_XM_RXEN_LBN 1
870 #define FCN_XM_RXEN_WIDTH 1
871 
872 /* XGMAC management interrupt mask register */
873 #define FCN_XM_MGT_INT_MSK_REG_MAC_B0 0x5
874 #define FCN_XM_MSK_PRMBLE_ERR_LBN 2
875 #define FCN_XM_MSK_PRMBLE_ERR_WIDTH 1
876 #define FCN_XM_MSK_RMTFLT_LBN 1
877 #define FCN_XM_MSK_RMTFLT_WIDTH 1
878 #define FCN_XM_MSK_LCLFLT_LBN 0
879 #define FCN_XM_MSK_LCLFLT_WIDTH 1
880 
881 /* XGMAC flow control register */
882 #define FCN_XM_FC_REG_MAC 0x7
883 #define FCN_XM_PAUSE_TIME_LBN 16
884 #define FCN_XM_PAUSE_TIME_WIDTH 16
885 #define FCN_XM_DIS_FCNTL_LBN 0
886 #define FCN_XM_DIS_FCNTL_WIDTH 1
887 
888 /* XGMAC transmit parameter register */
889 #define FCN_XM_TX_PARAM_REG_MAC 0x0d
890 #define FCN_XM_TX_JUMBO_MODE_LBN 31
891 #define FCN_XM_TX_JUMBO_MODE_WIDTH 1
892 #define FCN_XM_MAX_TX_FRM_SIZE_LBN 16
893 #define FCN_XM_MAX_TX_FRM_SIZE_WIDTH 14
894 #define FCN_XM_ACPT_ALL_MCAST_LBN 11
895 #define FCN_XM_ACPT_ALL_MCAST_WIDTH 1
896 
897 /* XGMAC receive parameter register */
898 #define FCN_XM_RX_PARAM_REG_MAC 0x0e
899 #define FCN_XM_MAX_RX_FRM_SIZE_LBN 0
900 #define FCN_XM_MAX_RX_FRM_SIZE_WIDTH 14
901 
902 /* XGMAC management interrupt status register */
903 #define FCN_XM_MGT_INT_REG_MAC_B0 0x0f
904 #define FCN_XM_PRMBLE_ERR 2
905 #define FCN_XM_PRMBLE_WIDTH 1
906 #define FCN_XM_RMTFLT_LBN 1
907 #define FCN_XM_RMTFLT_WIDTH 1
908 #define FCN_XM_LCLFLT_LBN 0
909 #define FCN_XM_LCLFLT_WIDTH 1
910 
911 /* XAUI XGXS core status register */
912 #define FCN_XX_ALIGN_DONE_LBN 20
913 #define FCN_XX_ALIGN_DONE_WIDTH 1
914 #define FCN_XX_CORE_STAT_REG_MAC 0x16
915 #define FCN_XX_SYNC_STAT_LBN 16
916 #define FCN_XX_SYNC_STAT_WIDTH 4
917 #define FCN_XX_SYNC_STAT_DECODE_SYNCED 0xf
918 #define FCN_XX_COMMA_DET_LBN 12
919 #define FCN_XX_COMMA_DET_WIDTH 4
920 #define FCN_XX_COMMA_DET_RESET 0xf
921 #define FCN_XX_CHARERR_LBN 4
922 #define FCN_XX_CHARERR_WIDTH 4
923 #define FCN_XX_CHARERR_RESET 0xf
924 #define FCN_XX_DISPERR_LBN 0
925 #define FCN_XX_DISPERR_WIDTH 4
926 #define FCN_XX_DISPERR_RESET 0xf
927 
928 /* XGXS/XAUI powerdown/reset register */
929 #define FCN_XX_PWR_RST_REG_MAC 0x10
930 #define FCN_XX_PWRDND_EN_LBN 15
931 #define FCN_XX_PWRDND_EN_WIDTH 1
932 #define FCN_XX_PWRDNC_EN_LBN 14
933 #define FCN_XX_PWRDNC_EN_WIDTH 1
934 #define FCN_XX_PWRDNB_EN_LBN 13
935 #define FCN_XX_PWRDNB_EN_WIDTH 1
936 #define FCN_XX_PWRDNA_EN_LBN 12
937 #define FCN_XX_PWRDNA_EN_WIDTH 1
938 #define FCN_XX_RSTPLLCD_EN_LBN 9
939 #define FCN_XX_RSTPLLCD_EN_WIDTH 1
940 #define FCN_XX_RSTPLLAB_EN_LBN 8
941 #define FCN_XX_RSTPLLAB_EN_WIDTH 1
942 #define FCN_XX_RESETD_EN_LBN 7
943 #define FCN_XX_RESETD_EN_WIDTH 1
944 #define FCN_XX_RESETC_EN_LBN 6
945 #define FCN_XX_RESETC_EN_WIDTH 1
946 #define FCN_XX_RESETB_EN_LBN 5
947 #define FCN_XX_RESETB_EN_WIDTH 1
948 #define FCN_XX_RESETA_EN_LBN 4
949 #define FCN_XX_RESETA_EN_WIDTH 1
950 #define FCN_XX_RSTXGXSRX_EN_LBN 2
951 #define FCN_XX_RSTXGXSRX_EN_WIDTH 1
952 #define FCN_XX_RSTXGXSTX_EN_LBN 1
953 #define FCN_XX_RSTXGXSTX_EN_WIDTH 1
954 #define FCN_XX_RST_XX_EN_LBN 0
955 #define FCN_XX_RST_XX_EN_WIDTH 1
956 
957 
958 /* XGXS/XAUI powerdown/reset control register */
959 #define FCN_XX_SD_CTL_REG_MAC 0x11
960 #define FCN_XX_TERMADJ1_LBN 17
961 #define FCN_XX_TERMADJ1_WIDTH 1
962 #define FCN_XX_TERMADJ0_LBN 16
963 #define FCN_XX_TERMADJ0_WIDTH 1
964 #define FCN_XX_HIDRVD_LBN 15
965 #define FCN_XX_HIDRVD_WIDTH 1
966 #define FCN_XX_LODRVD_LBN 14
967 #define FCN_XX_LODRVD_WIDTH 1
968 #define FCN_XX_HIDRVC_LBN 13
969 #define FCN_XX_HIDRVC_WIDTH 1
970 #define FCN_XX_LODRVC_LBN 12
971 #define FCN_XX_LODRVC_WIDTH 1
972 #define FCN_XX_HIDRVB_LBN 11
973 #define FCN_XX_HIDRVB_WIDTH 1
974 #define FCN_XX_LODRVB_LBN 10
975 #define FCN_XX_LODRVB_WIDTH 1
976 #define FCN_XX_HIDRVA_LBN 9
977 #define FCN_XX_HIDRVA_WIDTH 1
978 #define FCN_XX_LODRVA_LBN 8
979 #define FCN_XX_LODRVA_WIDTH 1
980 #define FCN_XX_LPBKD_LBN 3
981 #define FCN_XX_LPBKD_WIDTH 1
982 #define FCN_XX_LPBKC_LBN 2
983 #define FCN_XX_LPBKC_WIDTH 1
984 #define FCN_XX_LPBKB_LBN 1
985 #define FCN_XX_LPBKB_WIDTH 1
986 #define FCN_XX_LPBKA_LBN 0
987 #define FCN_XX_LPBKA_WIDTH 1
988 
989 #define FCN_XX_TXDRV_CTL_REG_MAC 0x12
990 #define FCN_XX_DEQD_LBN 28
991 #define FCN_XX_DEQD_WIDTH 4
992 #define FCN_XX_DEQC_LBN 24
993 #define FCN_XX_DEQC_WIDTH 4
994 #define FCN_XX_DEQB_LBN 20
995 #define FCN_XX_DEQB_WIDTH 4
996 #define FCN_XX_DEQA_LBN 16
997 #define FCN_XX_DEQA_WIDTH 4
998 #define FCN_XX_DTXD_LBN 12
999 #define FCN_XX_DTXD_WIDTH 4
1000 #define FCN_XX_DTXC_LBN 8
1001 #define FCN_XX_DTXC_WIDTH 4
1002 #define FCN_XX_DTXB_LBN 4
1003 #define FCN_XX_DTXB_WIDTH 4
1004 #define FCN_XX_DTXA_LBN 0
1005 #define FCN_XX_DTXA_WIDTH 4
1006 
1007 /* Receive filter table */
1008 #define FCN_RX_FILTER_TBL0 0xF00000
1009 
1010 /* Receive descriptor pointer table */
1011 #define FCN_RX_DESC_PTR_TBL_KER_A1 0x11800
1012 #define FCN_RX_DESC_PTR_TBL_KER_B0 0xF40000
1013 #define FCN_RX_ISCSI_DDIG_EN_LBN 88
1014 #define FCN_RX_ISCSI_DDIG_EN_WIDTH 1
1015 #define FCN_RX_ISCSI_HDIG_EN_LBN 87
1016 #define FCN_RX_ISCSI_HDIG_EN_WIDTH 1
1017 #define FCN_RX_DESCQ_BUF_BASE_ID_LBN 36
1018 #define FCN_RX_DESCQ_BUF_BASE_ID_WIDTH 20
1019 #define FCN_RX_DESCQ_EVQ_ID_LBN 24
1020 #define FCN_RX_DESCQ_EVQ_ID_WIDTH 12
1021 #define FCN_RX_DESCQ_OWNER_ID_LBN 10
1022 #define FCN_RX_DESCQ_OWNER_ID_WIDTH 14
1023 #define FCN_RX_DESCQ_SIZE_LBN 3
1024 #define FCN_RX_DESCQ_SIZE_WIDTH 2
1025 #define FCN_RX_DESCQ_SIZE_4K 3
1026 #define FCN_RX_DESCQ_SIZE_2K 2
1027 #define FCN_RX_DESCQ_SIZE_1K 1
1028 #define FCN_RX_DESCQ_SIZE_512 0
1029 #define FCN_RX_DESCQ_TYPE_LBN 2
1030 #define FCN_RX_DESCQ_TYPE_WIDTH 1
1031 #define FCN_RX_DESCQ_JUMBO_LBN 1
1032 #define FCN_RX_DESCQ_JUMBO_WIDTH 1
1033 #define FCN_RX_DESCQ_EN_LBN 0
1034 #define FCN_RX_DESCQ_EN_WIDTH 1
1035 
1036 /* Transmit descriptor pointer table */
1037 #define FCN_TX_DESC_PTR_TBL_KER_A1 0x11900
1038 #define FCN_TX_DESC_PTR_TBL_KER_B0 0xF50000
1039 #define FCN_TX_NON_IP_DROP_DIS_B0_LBN 91
1040 #define FCN_TX_NON_IP_DROP_DIS_B0_WIDTH 1
1041 #define FCN_TX_DESCQ_EN_LBN 88
1042 #define FCN_TX_DESCQ_EN_WIDTH 1
1043 #define FCN_TX_ISCSI_DDIG_EN_LBN 87
1044 #define FCN_TX_ISCSI_DDIG_EN_WIDTH 1
1045 #define FCN_TX_ISCSI_HDIG_EN_LBN 86
1046 #define FCN_TX_ISCSI_HDIG_EN_WIDTH 1
1047 #define FCN_TX_DESCQ_BUF_BASE_ID_LBN 36
1048 #define FCN_TX_DESCQ_BUF_BASE_ID_WIDTH 20
1049 #define FCN_TX_DESCQ_EVQ_ID_LBN 24
1050 #define FCN_TX_DESCQ_EVQ_ID_WIDTH 12
1051 #define FCN_TX_DESCQ_OWNER_ID_LBN 10
1052 #define FCN_TX_DESCQ_OWNER_ID_WIDTH 14
1053 #define FCN_TX_DESCQ_SIZE_LBN 3
1054 #define FCN_TX_DESCQ_SIZE_WIDTH 2
1055 #define FCN_TX_DESCQ_SIZE_4K 3
1056 #define FCN_TX_DESCQ_SIZE_2K 2
1057 #define FCN_TX_DESCQ_SIZE_1K 1
1058 #define FCN_TX_DESCQ_SIZE_512 0
1059 #define FCN_TX_DESCQ_TYPE_LBN 1
1060 #define FCN_TX_DESCQ_TYPE_WIDTH 2
1061 #define FCN_TX_DESCQ_FLUSH_LBN 0
1062 #define FCN_TX_DESCQ_FLUSH_WIDTH 1
1063 
1064 /* Event queue pointer */
1065 #define FCN_EVQ_PTR_TBL_KER_A1 0x11a00
1066 #define FCN_EVQ_PTR_TBL_KER_B0 0xf60000
1067 #define FCN_EVQ_EN_LBN 23
1068 #define FCN_EVQ_EN_WIDTH 1
1069 #define FCN_EVQ_SIZE_LBN 20
1070 #define FCN_EVQ_SIZE_WIDTH 3
1071 #define FCN_EVQ_SIZE_32K 6
1072 #define FCN_EVQ_SIZE_16K 5
1073 #define FCN_EVQ_SIZE_8K 4
1074 #define FCN_EVQ_SIZE_4K 3
1075 #define FCN_EVQ_SIZE_2K 2
1076 #define FCN_EVQ_SIZE_1K 1
1077 #define FCN_EVQ_SIZE_512 0
1078 #define FCN_EVQ_BUF_BASE_ID_LBN 0
1079 #define FCN_EVQ_BUF_BASE_ID_WIDTH 20
1080 
1081 /* RSS indirection table */
1082 #define FCN_RX_RSS_INDIR_TBL_B0 0xFB0000
1083 
1084 /* Event queue read pointer */
1085 #define FCN_EVQ_RPTR_REG_KER_A1 0x11b00
1086 #define FCN_EVQ_RPTR_REG_KER_B0 0xfa0000
1087 #define FCN_EVQ_RPTR_LBN 0
1088 #define FCN_EVQ_RPTR_WIDTH 14
1089 #define FCN_EVQ_RPTR_REG_KER_DWORD_A1 ( FCN_EVQ_RPTR_REG_KER_A1 + 0 )
1090 #define FCN_EVQ_RPTR_REG_KER_DWORD_B0 ( FCN_EVQ_RPTR_REG_KER_B0 + 0 )
1091 #define FCN_EVQ_RPTR_DWORD_LBN 0
1092 #define FCN_EVQ_RPTR_DWORD_WIDTH 14
1093 
1094 /* Special buffer descriptors */
1095 #define FCN_BUF_FULL_TBL_KER_A1 0x18000
1096 #define FCN_BUF_FULL_TBL_KER_B0 0x800000
1097 #define FCN_IP_DAT_BUF_SIZE_LBN 50
1098 #define FCN_IP_DAT_BUF_SIZE_WIDTH 1
1099 #define FCN_IP_DAT_BUF_SIZE_8K 1
1100 #define FCN_IP_DAT_BUF_SIZE_4K 0
1101 #define FCN_BUF_ADR_FBUF_LBN 14
1102 #define FCN_BUF_ADR_FBUF_WIDTH 34
1103 #define FCN_BUF_OWNER_ID_FBUF_LBN 0
1104 #define FCN_BUF_OWNER_ID_FBUF_WIDTH 14
1105 
1106 /** Offset of a GMAC register within Falcon */
1107 #define FALCON_GMAC_REG( efab, mac_reg ) \
1108  ( FALCON_GMAC_REGBANK + \
1109  ( (mac_reg) * FALCON_GMAC_REG_SIZE ) )
1110 
1111 /** Offset of an XMAC register within Falcon */
1112 #define FALCON_XMAC_REG( efab_port, mac_reg ) \
1113  ( FALCON_XMAC_REGBANK + \
1114  ( (mac_reg) * FALCON_XMAC_REG_SIZE ) )
1115 
1116 #define FCN_MAC_DATA_LBN 0
1117 #define FCN_MAC_DATA_WIDTH 32
1118 
1119 /* Transmit descriptor */
1120 #define FCN_TX_KER_PORT_LBN 63
1121 #define FCN_TX_KER_PORT_WIDTH 1
1122 #define FCN_TX_KER_BYTE_CNT_LBN 48
1123 #define FCN_TX_KER_BYTE_CNT_WIDTH 14
1124 #define FCN_TX_KER_BUF_ADR_LBN 0
1125 #define FCN_TX_KER_BUF_ADR_WIDTH EFAB_DMA_TYPE_WIDTH ( 46 )
1126 
1127 
1128 /* Receive descriptor */
1129 #define FCN_RX_KER_BUF_SIZE_LBN 48
1130 #define FCN_RX_KER_BUF_SIZE_WIDTH 14
1131 #define FCN_RX_KER_BUF_ADR_LBN 0
1132 #define FCN_RX_KER_BUF_ADR_WIDTH EFAB_DMA_TYPE_WIDTH ( 46 )
1133 
1134 /* Event queue entries */
1135 #define FCN_EV_CODE_LBN 60
1136 #define FCN_EV_CODE_WIDTH 4
1137 #define FCN_RX_IP_EV_DECODE 0
1138 #define FCN_TX_IP_EV_DECODE 2
1139 #define FCN_DRIVER_EV_DECODE 5
1140 
1141 /* Receive events */
1142 #define FCN_RX_EV_PKT_OK_LBN 56
1143 #define FCN_RX_EV_PKT_OK_WIDTH 1
1144 #define FCN_RX_PORT_LBN 30
1145 #define FCN_RX_PORT_WIDTH 1
1146 #define FCN_RX_EV_BYTE_CNT_LBN 16
1147 #define FCN_RX_EV_BYTE_CNT_WIDTH 14
1148 #define FCN_RX_EV_DESC_PTR_LBN 0
1149 #define FCN_RX_EV_DESC_PTR_WIDTH 12
1150 
1151 /* Transmit events */
1152 #define FCN_TX_EV_DESC_PTR_LBN 0
1153 #define FCN_TX_EV_DESC_PTR_WIDTH 12
1154 
1155 /*******************************************************************************
1156  *
1157  *
1158  * Low-level hardware access
1159  *
1160  *
1161  *******************************************************************************/
1162 
1163 #define FCN_REVISION_REG(efab, reg) \
1164  ( ( efab->pci_revision == FALCON_REV_B0 ) ? reg ## _B0 : reg ## _A1 )
1165 
1166 #define EFAB_SET_OWORD_FIELD_VER(efab, reg, field, val) \
1167  if ( efab->pci_revision == FALCON_REV_B0 ) \
1168  EFAB_SET_OWORD_FIELD ( reg, field ## _B0, val ); \
1169  else \
1170  EFAB_SET_OWORD_FIELD ( reg, field ## _A1, val );
1171 
1172 #if FALCON_USE_IO_BAR
1173 
1174 /* Write dword via the I/O BAR */
1175 static inline void _falcon_writel ( struct efab_nic *efab, uint32_t value,
1176  unsigned int reg ) {
1177  outl ( reg, efab->iobase + FCN_IOM_IND_ADR_REG );
1178  outl ( value, efab->iobase + FCN_IOM_IND_DAT_REG );
1179 }
1180 
1181 /* Read dword via the I/O BAR */
1182 static inline uint32_t _falcon_readl ( struct efab_nic *efab,
1183  unsigned int reg ) {
1184  outl ( reg, efab->iobase + FCN_IOM_IND_ADR_REG );
1185  return inl ( efab->iobase + FCN_IOM_IND_DAT_REG );
1186 }
1187 
1188 #else /* FALCON_USE_IO_BAR */
1189 
1190 #define _falcon_writel( efab, value, reg ) \
1191  writel ( (value), (efab)->membase + (reg) )
1192 #define _falcon_readl( efab, reg ) readl ( (efab)->membase + (reg) )
1193 
1194 #endif /* FALCON_USE_IO_BAR */
1195 
1196 /**
1197  * Write to a Falcon register
1198  *
1199  */
1200 static inline void
1201 falcon_write ( struct efab_nic *efab, efab_oword_t *value, unsigned int reg )
1202 {
1203 
1204  EFAB_REGDUMP ( "Writing register %x with " EFAB_OWORD_FMT "\n",
1205  reg, EFAB_OWORD_VAL ( *value ) );
1206 
1207  _falcon_writel ( efab, value->u32[0], reg + 0 );
1208  _falcon_writel ( efab, value->u32[1], reg + 4 );
1209  _falcon_writel ( efab, value->u32[2], reg + 8 );
1210  wmb();
1211  _falcon_writel ( efab, value->u32[3], reg + 12 );
1212  wmb();
1213 }
1214 
1215 /**
1216  * Write to Falcon SRAM
1217  *
1218  */
1219 static inline void
1221  unsigned int index )
1222 {
1223  unsigned int reg = ( FCN_REVISION_REG ( efab, FCN_BUF_FULL_TBL_KER ) +
1224  ( index * sizeof ( *value ) ) );
1225 
1226  EFAB_REGDUMP ( "Writing SRAM register %x with " EFAB_QWORD_FMT "\n",
1227  reg, EFAB_QWORD_VAL ( *value ) );
1228 
1229  _falcon_writel ( efab, value->u32[0], reg + 0 );
1230  _falcon_writel ( efab, value->u32[1], reg + 4 );
1231  wmb();
1232 }
1233 
1234 /**
1235  * Write dword to Falcon register that allows partial writes
1236  *
1237  */
1238 static inline void
1239 falcon_writel ( struct efab_nic *efab, efab_dword_t *value, unsigned int reg )
1240 {
1241  EFAB_REGDUMP ( "Writing partial register %x with " EFAB_DWORD_FMT "\n",
1242  reg, EFAB_DWORD_VAL ( *value ) );
1243  _falcon_writel ( efab, value->u32[0], reg );
1244 }
1245 
1246 /**
1247  * Read from a Falcon register
1248  *
1249  */
1250 static inline void
1251 falcon_read ( struct efab_nic *efab, efab_oword_t *value, unsigned int reg )
1252 {
1253  value->u32[0] = _falcon_readl ( efab, reg + 0 );
1254  wmb();
1255  value->u32[1] = _falcon_readl ( efab, reg + 4 );
1256  value->u32[2] = _falcon_readl ( efab, reg + 8 );
1257  value->u32[3] = _falcon_readl ( efab, reg + 12 );
1258 
1259  EFAB_REGDUMP ( "Read from register %x, got " EFAB_OWORD_FMT "\n",
1260  reg, EFAB_OWORD_VAL ( *value ) );
1261 }
1262 
1263 /**
1264  * Read from Falcon SRAM
1265  *
1266  */
1267 static inline void
1269  unsigned int index )
1270 {
1271  unsigned int reg = ( FCN_REVISION_REG ( efab, FCN_BUF_FULL_TBL_KER ) +
1272  ( index * sizeof ( *value ) ) );
1273 
1274  value->u32[0] = _falcon_readl ( efab, reg + 0 );
1275  value->u32[1] = _falcon_readl ( efab, reg + 4 );
1276  EFAB_REGDUMP ( "Read from SRAM register %x, got " EFAB_QWORD_FMT "\n",
1277  reg, EFAB_QWORD_VAL ( *value ) );
1278 }
1279 
1280 /**
1281  * Read dword from a portion of a Falcon register
1282  *
1283  */
1284 static inline void
1285 falcon_readl ( struct efab_nic *efab, efab_dword_t *value, unsigned int reg )
1286 {
1287  value->u32[0] = _falcon_readl ( efab, reg );
1288  EFAB_REGDUMP ( "Read from register %x, got " EFAB_DWORD_FMT "\n",
1289  reg, EFAB_DWORD_VAL ( *value ) );
1290 }
1291 
1292 #define FCN_DUMP_REG( efab, _reg ) do { \
1293  efab_oword_t reg; \
1294  falcon_read ( efab, &reg, _reg ); \
1295  EFAB_LOG ( #_reg " = " EFAB_OWORD_FMT "\n", \
1296  EFAB_OWORD_VAL ( reg ) ); \
1297  } while ( 0 );
1298 
1299 #define FCN_DUMP_MAC_REG( efab, _mac_reg ) do { \
1300  efab_dword_t reg; \
1301  efab->mac_op->mac_readl ( efab, &reg, _mac_reg ); \
1302  EFAB_LOG ( #_mac_reg " = " EFAB_DWORD_FMT "\n", \
1303  EFAB_DWORD_VAL ( reg ) ); \
1304  } while ( 0 );
1305 
1306 /**
1307  * See if an event is present
1308  *
1309  * @v event Falcon event structure
1310  * @ret True An event is pending
1311  * @ret False No event is pending
1312  *
1313  * We check both the high and low dword of the event for all ones. We
1314  * wrote all ones when we cleared the event, and no valid event can
1315  * have all ones in either its high or low dwords. This approach is
1316  * robust against reordering.
1317  *
1318  * Note that using a single 64-bit comparison is incorrect; even
1319  * though the CPU read will be atomic, the DMA write may not be.
1320  */
1321 static inline int
1323 {
1324  return ( ! ( EFAB_DWORD_IS_ALL_ONES ( event->dword[0] ) |
1325  EFAB_DWORD_IS_ALL_ONES ( event->dword[1] ) ) );
1326 }
1327 
1328 static void
1329 falcon_eventq_read_ack ( struct efab_nic *efab, struct efab_ev_queue *ev_queue )
1330 {
1331  efab_dword_t reg;
1332 
1333  EFAB_POPULATE_DWORD_1 ( reg, FCN_EVQ_RPTR_DWORD, ev_queue->read_ptr );
1334  falcon_writel ( efab, &reg,
1335  FCN_REVISION_REG ( efab, FCN_EVQ_RPTR_REG_KER_DWORD ) );
1336 }
1337 
1338 #if 0
1339 /**
1340  * Dump register contents (for debugging)
1341  *
1342  * Marked as static inline so that it will not be compiled in if not
1343  * used.
1344  */
1345 static inline void
1346 falcon_dump_regs ( struct efab_nic *efab )
1347 {
1348  FCN_DUMP_REG ( efab, FCN_INT_EN_REG_KER );
1359  FCN_DUMP_REG ( efab, FCN_REVISION_REG ( efab, FCN_RX_DESC_PTR_TBL_KER ) );
1360  FCN_DUMP_REG ( efab, FCN_REVISION_REG ( efab, FCN_TX_DESC_PTR_TBL_KER ) );
1361  FCN_DUMP_REG ( efab, FCN_REVISION_REG ( efab, FCN_EVQ_PTR_TBL_KER ) );
1374 }
1375 #endif
1376 
1377 static void
1378 falcon_interrupts ( struct efab_nic *efab, int enabled, int force )
1379 {
1380  efab_oword_t int_en_reg_ker;
1381 
1382  EFAB_POPULATE_OWORD_2 ( int_en_reg_ker,
1383  FCN_KER_INT_KER, force,
1384  FCN_DRV_INT_EN_KER, enabled );
1385  falcon_write ( efab, &int_en_reg_ker, FCN_INT_EN_REG_KER );
1386 }
1387 
1388 /*******************************************************************************
1389  *
1390  *
1391  * SPI access
1392  *
1393  *
1394  *******************************************************************************/
1395 
1396 
1397 /** Maximum length for a single SPI transaction */
1398 #define FALCON_SPI_MAX_LEN 16
1399 
1400 static int
1401 falcon_spi_wait ( struct efab_nic *efab )
1402 {
1403  efab_oword_t reg;
1404  int count;
1405 
1406  count = 0;
1407  do {
1408  udelay ( 100 );
1409  falcon_read ( efab, &reg, FCN_EE_SPI_HCMD_REG );
1410  if ( EFAB_OWORD_FIELD ( reg, FCN_EE_SPI_HCMD_CMD_EN ) == 0 )
1411  return 0;
1412  } while ( ++count < 1000 );
1413 
1414  EFAB_ERR ( "Timed out waiting for SPI\n" );
1415  return -ETIMEDOUT;
1416 }
1417 
1418 static int
1420  unsigned int command, int address,
1421  const void* data_out, void *data_in, size_t len )
1422 {
1423  struct efab_nic *efab = container_of ( bus, struct efab_nic, spi_bus );
1425  efab_oword_t reg;
1426 
1427  /* falcon_init_spi_device() should have reduced the block size
1428  * down so this constraint holds */
1429  assert ( len <= FALCON_SPI_MAX_LEN );
1430 
1431  /* Is this the FLASH or EEPROM device? */
1432  if ( device == &efab->spi_flash )
1434  else if ( device == &efab->spi_eeprom )
1436  else {
1437  EFAB_ERR ( "Unknown device %p\n", device );
1438  return -EINVAL;
1439  }
1440 
1441  EFAB_TRACE ( "Executing spi command %d on device %d at %d for %zd bytes\n",
1443 
1444  /* The bus must be idle */
1445  rc = falcon_spi_wait ( efab );
1446  if ( rc )
1447  goto fail1;
1448 
1449  /* Copy data out */
1450  if ( data_out ) {
1451  memcpy ( &reg, data_out, len );
1453  }
1454 
1455  /* Program address register */
1456  if ( address >= 0 ) {
1457  EFAB_POPULATE_OWORD_1 ( reg, FCN_EE_SPI_HADR_ADR, address );
1458  falcon_write ( efab, &reg, FCN_EE_SPI_HADR_REG );
1459  }
1460 
1461  /* Issue command */
1462  address_len = ( address >= 0 ) ? device->address_len / 8 : 0;
1463  read_cmd = ( data_in ? FCN_EE_SPI_READ : FCN_EE_SPI_WRITE );
1465  FCN_EE_SPI_HCMD_CMD_EN, 1,
1466  FCN_EE_SPI_HCMD_SF_SEL, device_id,
1467  FCN_EE_SPI_HCMD_DABCNT, len,
1468  FCN_EE_SPI_HCMD_READ, read_cmd,
1469  FCN_EE_SPI_HCMD_DUBCNT, 0,
1470  FCN_EE_SPI_HCMD_ADBCNT, address_len,
1471  FCN_EE_SPI_HCMD_ENC, command );
1472  falcon_write ( efab, &reg, FCN_EE_SPI_HCMD_REG );
1473 
1474  /* Wait for the command to complete */
1475  rc = falcon_spi_wait ( efab );
1476  if ( rc )
1477  goto fail2;
1478 
1479  /* Copy data in */
1480  if ( data_in ) {
1481  falcon_read ( efab, &reg, FCN_EE_SPI_HDATA_REG );
1482  memcpy ( data_in, &reg, len );
1483  }
1484 
1485  return 0;
1486 
1487 fail2:
1488 fail1:
1489  EFAB_ERR ( "Failed SPI command %d to device %d address 0x%x len 0x%zx\n",
1491 
1492  return rc;
1493 }
1494 
1495 /*******************************************************************************
1496  *
1497  *
1498  * Falcon bit-bashed I2C interface
1499  *
1500  *
1501  *******************************************************************************/
1502 
1503 static void
1504 falcon_i2c_bit_write ( struct bit_basher *basher, unsigned int bit_id,
1505  unsigned long data )
1506 {
1507  struct efab_nic *efab = container_of ( basher, struct efab_nic,
1508  i2c_bb.basher );
1509  efab_oword_t reg;
1510 
1511  falcon_read ( efab, &reg, FCN_GPIO_CTL_REG_KER );
1512  switch ( bit_id ) {
1513  case I2C_BIT_SCL:
1514  EFAB_SET_OWORD_FIELD ( reg, FCN_GPIO0_OEN, ( data ? 0 : 1 ) );
1515  break;
1516  case I2C_BIT_SDA:
1517  EFAB_SET_OWORD_FIELD ( reg, FCN_GPIO3_OEN, ( data ? 0 : 1 ) );
1518  break;
1519  default:
1520  EFAB_ERR ( "%s bit=%d\n", __func__, bit_id );
1521  break;
1522  }
1523 
1525 }
1526 
1527 static int
1528 falcon_i2c_bit_read ( struct bit_basher *basher, unsigned int bit_id )
1529 {
1530  struct efab_nic *efab = container_of ( basher, struct efab_nic,
1531  i2c_bb.basher );
1532  efab_oword_t reg;
1533 
1534  falcon_read ( efab, &reg, FCN_GPIO_CTL_REG_KER );
1535  switch ( bit_id ) {
1536  case I2C_BIT_SCL:
1537  return EFAB_OWORD_FIELD ( reg, FCN_GPIO0_IN );
1538  break;
1539  case I2C_BIT_SDA:
1540  return EFAB_OWORD_FIELD ( reg, FCN_GPIO3_IN );
1541  break;
1542  default:
1543  EFAB_ERR ( "%s bit=%d\n", __func__, bit_id );
1544  break;
1545  }
1546 
1547  return -1;
1548 }
1549 
1552  .write = falcon_i2c_bit_write,
1553 };
1554 
1555 
1556 /*******************************************************************************
1557  *
1558  *
1559  * MDIO access
1560  *
1561  *
1562  *******************************************************************************/
1563 
1564 static int
1565 falcon_gmii_wait ( struct efab_nic *efab )
1566 {
1567  efab_dword_t md_stat;
1568  int count;
1569 
1570  /* wait up to 10ms */
1571  for (count = 0; count < 1000; count++) {
1572  falcon_readl ( efab, &md_stat, FCN_MD_STAT_REG_KER );
1573  if ( EFAB_DWORD_FIELD ( md_stat, FCN_MD_BSY ) == 0 ) {
1574  if ( EFAB_DWORD_FIELD ( md_stat, FCN_MD_LNFL ) != 0 ||
1575  EFAB_DWORD_FIELD ( md_stat, FCN_MD_BSERR ) != 0 ) {
1576  EFAB_ERR ( "Error from GMII access "
1577  EFAB_DWORD_FMT"\n",
1578  EFAB_DWORD_VAL ( md_stat ));
1579  return -EIO;
1580  }
1581  return 0;
1582  }
1583  udelay(10);
1584  }
1585 
1586  EFAB_ERR ( "Timed out waiting for GMII\n" );
1587  return -ETIMEDOUT;
1588 }
1589 
1590 static void
1591 falcon_mdio_write ( struct efab_nic *efab, int device,
1592  int location, int value )
1593 {
1594  efab_oword_t reg;
1595 
1596  EFAB_TRACE ( "Writing GMII %d register %02x with %04x\n",
1597  device, location, value );
1598 
1599  /* Check MII not currently being accessed */
1600  if ( falcon_gmii_wait ( efab ) )
1601  return;
1602 
1603  /* Write the address/ID register */
1604  EFAB_POPULATE_OWORD_1 ( reg, FCN_MD_PHY_ADR, location );
1606 
1607  if ( efab->phy_10g ) {
1608  /* clause45 */
1610  FCN_MD_PRT_ADR, efab->phy_addr,
1611  FCN_MD_DEV_ADR, device );
1612  }
1613  else {
1614  /* clause22 */
1615  assert ( device == 0 );
1616 
1618  FCN_MD_PRT_ADR, efab->phy_addr,
1619  FCN_MD_DEV_ADR, location );
1620  }
1621  falcon_write ( efab, &reg, FCN_MD_ID_REG_KER );
1622 
1623 
1624  /* Write data */
1625  EFAB_POPULATE_OWORD_1 ( reg, FCN_MD_TXD, value );
1626  falcon_write ( efab, &reg, FCN_MD_TXD_REG_KER );
1627 
1629  FCN_MD_WRC, 1,
1630  FCN_MD_GC, ( efab->phy_10g ? 0 : 1 ) );
1631  falcon_write ( efab, &reg, FCN_MD_CS_REG_KER );
1632 
1633  /* Wait for data to be written */
1634  if ( falcon_gmii_wait ( efab ) ) {
1635  /* Abort the write operation */
1637  FCN_MD_WRC, 0,
1638  FCN_MD_GC, 1);
1639  falcon_write ( efab, &reg, FCN_MD_CS_REG_KER );
1640  udelay(10);
1641  }
1642 }
1643 
1644 static int
1645 falcon_mdio_read ( struct efab_nic *efab, int device, int location )
1646 {
1647  efab_oword_t reg;
1648  int value;
1649 
1650  /* Check MII not currently being accessed */
1651  if ( falcon_gmii_wait ( efab ) )
1652  return -1;
1653 
1654  if ( efab->phy_10g ) {
1655  /* clause45 */
1656  EFAB_POPULATE_OWORD_1 ( reg, FCN_MD_PHY_ADR, location );
1658 
1660  FCN_MD_PRT_ADR, efab->phy_addr,
1661  FCN_MD_DEV_ADR, device );
1662  falcon_write ( efab, &reg, FCN_MD_ID_REG_KER);
1663 
1664  /* request data to be read */
1666  FCN_MD_RDC, 1,
1667  FCN_MD_GC, 0 );
1668  }
1669  else {
1670  /* clause22 */
1671  assert ( device == 0 );
1672 
1674  FCN_MD_PRT_ADR, efab->phy_addr,
1675  FCN_MD_DEV_ADR, location );
1676  falcon_write ( efab, &reg, FCN_MD_ID_REG_KER );
1677 
1678  /* Request data to be read */
1680  FCN_MD_RIC, 1,
1681  FCN_MD_GC, 1 );
1682  }
1683 
1684  falcon_write ( efab, &reg, FCN_MD_CS_REG_KER );
1685 
1686  /* Wait for data to become available */
1687  if ( falcon_gmii_wait ( efab ) ) {
1688  /* Abort the read operation */
1690  FCN_MD_RIC, 0,
1691  FCN_MD_GC, 1 );
1692  falcon_write ( efab, &reg, FCN_MD_CS_REG_KER );
1693  udelay ( 10 );
1694  value = -1;
1695  }
1696  else {
1697  /* Read the data */
1698  falcon_read ( efab, &reg, FCN_MD_RXD_REG_KER );
1699  value = EFAB_OWORD_FIELD ( reg, FCN_MD_RXD );
1700  }
1701 
1702  EFAB_TRACE ( "Read from GMII %d register %02x, got %04x\n",
1703  device, location, value );
1704 
1705  return value;
1706 }
1707 
1708 /*******************************************************************************
1709  *
1710  *
1711  * MAC wrapper
1712  *
1713  *
1714  *******************************************************************************/
1715 
1716 static void
1718 {
1719  efab_oword_t reg;
1720  int link_speed;
1721 
1722  if ( efab->link_options & LPA_EF_10000 ) {
1723  link_speed = 0x3;
1724  } else if ( efab->link_options & LPA_EF_1000 ) {
1725  link_speed = 0x2;
1726  } else if ( efab->link_options & LPA_100 ) {
1727  link_speed = 0x1;
1728  } else {
1729  link_speed = 0x0;
1730  }
1732  FCN_MAC_XOFF_VAL, 0xffff /* datasheet */,
1733  FCN_MAC_BCAD_ACPT, 1,
1734  FCN_MAC_UC_PROM, 0,
1735  FCN_MAC_LINK_STATUS, 1,
1736  FCN_MAC_SPEED, link_speed );
1737 
1739 }
1740 
1741 /*******************************************************************************
1742  *
1743  *
1744  * GMAC handling
1745  *
1746  *
1747  *******************************************************************************/
1748 
1749 /* GMAC configuration register 1 */
1750 #define GM_CFG1_REG_MAC 0x00
1751 #define GM_SW_RST_LBN 31
1752 #define GM_SW_RST_WIDTH 1
1753 #define GM_RX_FC_EN_LBN 5
1754 #define GM_RX_FC_EN_WIDTH 1
1755 #define GM_TX_FC_EN_LBN 4
1756 #define GM_TX_FC_EN_WIDTH 1
1757 #define GM_RX_EN_LBN 2
1758 #define GM_RX_EN_WIDTH 1
1759 #define GM_TX_EN_LBN 0
1760 #define GM_TX_EN_WIDTH 1
1761 
1762 /* GMAC configuration register 2 */
1763 #define GM_CFG2_REG_MAC 0x01
1764 #define GM_PAMBL_LEN_LBN 12
1765 #define GM_PAMBL_LEN_WIDTH 4
1766 #define GM_IF_MODE_LBN 8
1767 #define GM_IF_MODE_WIDTH 2
1768 #define GM_PAD_CRC_EN_LBN 2
1769 #define GM_PAD_CRC_EN_WIDTH 1
1770 #define GM_FD_LBN 0
1771 #define GM_FD_WIDTH 1
1772 
1773 /* GMAC maximum frame length register */
1774 #define GM_MAX_FLEN_REG_MAC 0x04
1775 #define GM_MAX_FLEN_LBN 0
1776 #define GM_MAX_FLEN_WIDTH 16
1777 
1778 /* GMAC MII management configuration register */
1779 #define GM_MII_MGMT_CFG_REG_MAC 0x08
1780 #define GM_MGMT_CLK_SEL_LBN 0
1781 #define GM_MGMT_CLK_SEL_WIDTH 3
1782 
1783 /* GMAC MII management command register */
1784 #define GM_MII_MGMT_CMD_REG_MAC 0x09
1785 #define GM_MGMT_SCAN_CYC_LBN 1
1786 #define GM_MGMT_SCAN_CYC_WIDTH 1
1787 #define GM_MGMT_RD_CYC_LBN 0
1788 #define GM_MGMT_RD_CYC_WIDTH 1
1789 
1790 /* GMAC MII management address register */
1791 #define GM_MII_MGMT_ADR_REG_MAC 0x0a
1792 #define GM_MGMT_PHY_ADDR_LBN 8
1793 #define GM_MGMT_PHY_ADDR_WIDTH 5
1794 #define GM_MGMT_REG_ADDR_LBN 0
1795 #define GM_MGMT_REG_ADDR_WIDTH 5
1796 
1797 /* GMAC MII management control register */
1798 #define GM_MII_MGMT_CTL_REG_MAC 0x0b
1799 #define GM_MGMT_CTL_LBN 0
1800 #define GM_MGMT_CTL_WIDTH 16
1801 
1802 /* GMAC MII management status register */
1803 #define GM_MII_MGMT_STAT_REG_MAC 0x0c
1804 #define GM_MGMT_STAT_LBN 0
1805 #define GM_MGMT_STAT_WIDTH 16
1806 
1807 /* GMAC MII management indicators register */
1808 #define GM_MII_MGMT_IND_REG_MAC 0x0d
1809 #define GM_MGMT_BUSY_LBN 0
1810 #define GM_MGMT_BUSY_WIDTH 1
1811 
1812 /* GMAC station address register 1 */
1813 #define GM_ADR1_REG_MAC 0x10
1814 #define GM_HWADDR_5_LBN 24
1815 #define GM_HWADDR_5_WIDTH 8
1816 #define GM_HWADDR_4_LBN 16
1817 #define GM_HWADDR_4_WIDTH 8
1818 #define GM_HWADDR_3_LBN 8
1819 #define GM_HWADDR_3_WIDTH 8
1820 #define GM_HWADDR_2_LBN 0
1821 #define GM_HWADDR_2_WIDTH 8
1822 
1823 /* GMAC station address register 2 */
1824 #define GM_ADR2_REG_MAC 0x11
1825 #define GM_HWADDR_1_LBN 24
1826 #define GM_HWADDR_1_WIDTH 8
1827 #define GM_HWADDR_0_LBN 16
1828 #define GM_HWADDR_0_WIDTH 8
1829 
1830 /* GMAC FIFO configuration register 0 */
1831 #define GMF_CFG0_REG_MAC 0x12
1832 #define GMF_FTFENREQ_LBN 12
1833 #define GMF_FTFENREQ_WIDTH 1
1834 #define GMF_STFENREQ_LBN 11
1835 #define GMF_STFENREQ_WIDTH 1
1836 #define GMF_FRFENREQ_LBN 10
1837 #define GMF_FRFENREQ_WIDTH 1
1838 #define GMF_SRFENREQ_LBN 9
1839 #define GMF_SRFENREQ_WIDTH 1
1840 #define GMF_WTMENREQ_LBN 8
1841 #define GMF_WTMENREQ_WIDTH 1
1842 
1843 /* GMAC FIFO configuration register 1 */
1844 #define GMF_CFG1_REG_MAC 0x13
1845 #define GMF_CFGFRTH_LBN 16
1846 #define GMF_CFGFRTH_WIDTH 5
1847 #define GMF_CFGXOFFRTX_LBN 0
1848 #define GMF_CFGXOFFRTX_WIDTH 16
1849 
1850 /* GMAC FIFO configuration register 2 */
1851 #define GMF_CFG2_REG_MAC 0x14
1852 #define GMF_CFGHWM_LBN 16
1853 #define GMF_CFGHWM_WIDTH 6
1854 #define GMF_CFGLWM_LBN 0
1855 #define GMF_CFGLWM_WIDTH 6
1856 
1857 /* GMAC FIFO configuration register 3 */
1858 #define GMF_CFG3_REG_MAC 0x15
1859 #define GMF_CFGHWMFT_LBN 16
1860 #define GMF_CFGHWMFT_WIDTH 6
1861 #define GMF_CFGFTTH_LBN 0
1862 #define GMF_CFGFTTH_WIDTH 6
1863 
1864 /* GMAC FIFO configuration register 4 */
1865 #define GMF_CFG4_REG_MAC 0x16
1866 #define GMF_HSTFLTRFRM_PAUSE_LBN 12
1867 #define GMF_HSTFLTRFRM_PAUSE_WIDTH 12
1868 
1869 /* GMAC FIFO configuration register 5 */
1870 #define GMF_CFG5_REG_MAC 0x17
1871 #define GMF_CFGHDPLX_LBN 22
1872 #define GMF_CFGHDPLX_WIDTH 1
1873 #define GMF_CFGBYTMODE_LBN 19
1874 #define GMF_CFGBYTMODE_WIDTH 1
1875 #define GMF_HSTDRPLT64_LBN 18
1876 #define GMF_HSTDRPLT64_WIDTH 1
1877 #define GMF_HSTFLTRFRMDC_PAUSE_LBN 12
1878 #define GMF_HSTFLTRFRMDC_PAUSE_WIDTH 1
1879 
1880 static void
1882  unsigned int mac_reg )
1883 {
1884  efab_oword_t temp;
1885 
1886  EFAB_POPULATE_OWORD_1 ( temp, FCN_MAC_DATA,
1887  EFAB_DWORD_FIELD ( *value, FCN_MAC_DATA ) );
1888  falcon_write ( efab, &temp, FALCON_GMAC_REG ( efab, mac_reg ) );
1889 }
1890 
1891 static void
1893  unsigned int mac_reg )
1894 {
1895  efab_oword_t temp;
1896 
1897  falcon_read ( efab, &temp, FALCON_GMAC_REG ( efab, mac_reg ) );
1898  EFAB_POPULATE_DWORD_1 ( *value, FCN_MAC_DATA,
1899  EFAB_OWORD_FIELD ( temp, FCN_MAC_DATA ) );
1900 }
1901 
1902 static void
1903 mentormac_reset ( struct efab_nic *efab )
1904 {
1905  efab_dword_t reg;
1906 
1907  /* Take into reset */
1908  EFAB_POPULATE_DWORD_1 ( reg, GM_SW_RST, 1 );
1910  udelay ( 1000 );
1911 
1912  /* Take out of reset */
1913  EFAB_POPULATE_DWORD_1 ( reg, GM_SW_RST, 0 );
1915  udelay ( 1000 );
1916 
1917  /* Configure GMII interface so PHY is accessible. Note that
1918  * GMII interface is connected only to port 0, and that on
1919  * Falcon this is a no-op.
1920  */
1921  EFAB_POPULATE_DWORD_1 ( reg, GM_MGMT_CLK_SEL, 0x4 );
1923  udelay ( 10 );
1924 }
1925 
1926 static void
1927 mentormac_init ( struct efab_nic *efab )
1928 {
1929  int pause, if_mode, full_duplex, bytemode, half_duplex;
1930  efab_dword_t reg;
1931 
1932  /* Configuration register 1 */
1933  pause = ( efab->link_options & LPA_PAUSE_CAP ) ? 1 : 0;
1934  if ( ! ( efab->link_options & LPA_EF_DUPLEX ) ) {
1935  /* Half-duplex operation requires TX flow control */
1936  pause = 1;
1937  }
1939  GM_TX_EN, 1,
1940  GM_TX_FC_EN, pause,
1941  GM_RX_EN, 1,
1942  GM_RX_FC_EN, 1 );
1944  udelay ( 10 );
1945 
1946  /* Configuration register 2 */
1947  if_mode = ( efab->link_options & LPA_EF_1000 ) ? 2 : 1;
1948  full_duplex = ( efab->link_options & LPA_EF_DUPLEX ) ? 1 : 0;
1950  GM_IF_MODE, if_mode,
1951  GM_PAD_CRC_EN, 1,
1952  GM_FD, full_duplex,
1953  GM_PAMBL_LEN, 0x7 /* ? */ );
1955  udelay ( 10 );
1956 
1957  /* Max frame len register */
1958  EFAB_POPULATE_DWORD_1 ( reg, GM_MAX_FLEN,
1961  udelay ( 10 );
1962 
1963  /* FIFO configuration register 0 */
1965  GMF_FTFENREQ, 1,
1966  GMF_STFENREQ, 1,
1967  GMF_FRFENREQ, 1,
1968  GMF_SRFENREQ, 1,
1969  GMF_WTMENREQ, 1 );
1971  udelay ( 10 );
1972 
1973  /* FIFO configuration register 1 */
1975  GMF_CFGFRTH, 0x12,
1976  GMF_CFGXOFFRTX, 0xffff );
1978  udelay ( 10 );
1979 
1980  /* FIFO configuration register 2 */
1982  GMF_CFGHWM, 0x3f,
1983  GMF_CFGLWM, 0xa );
1985  udelay ( 10 );
1986 
1987  /* FIFO configuration register 3 */
1989  GMF_CFGHWMFT, 0x1c,
1990  GMF_CFGFTTH, 0x08 );
1992  udelay ( 10 );
1993 
1994  /* FIFO configuration register 4 */
1995  EFAB_POPULATE_DWORD_1 ( reg, GMF_HSTFLTRFRM_PAUSE, 1 );
1997  udelay ( 10 );
1998 
1999  /* FIFO configuration register 5 */
2000  bytemode = ( efab->link_options & LPA_EF_1000 ) ? 1 : 0;
2001  half_duplex = ( efab->link_options & LPA_EF_DUPLEX ) ? 0 : 1;
2003  EFAB_SET_DWORD_FIELD ( reg, GMF_CFGBYTMODE, bytemode );
2004  EFAB_SET_DWORD_FIELD ( reg, GMF_CFGHDPLX, half_duplex );
2005  EFAB_SET_DWORD_FIELD ( reg, GMF_HSTDRPLT64, half_duplex );
2006  EFAB_SET_DWORD_FIELD ( reg, GMF_HSTFLTRFRMDC_PAUSE, 0 );
2008  udelay ( 10 );
2009 
2010  /* MAC address */
2012  GM_HWADDR_5, efab->mac_addr[5],
2013  GM_HWADDR_4, efab->mac_addr[4],
2014  GM_HWADDR_3, efab->mac_addr[3],
2015  GM_HWADDR_2, efab->mac_addr[2] );
2017  udelay ( 10 );
2019  GM_HWADDR_1, efab->mac_addr[1],
2020  GM_HWADDR_0, efab->mac_addr[0] );
2022  udelay ( 10 );
2023 }
2024 
2025 static int
2026 falcon_init_gmac ( struct efab_nic *efab )
2027 {
2028  /* Reset the MAC */
2029  mentormac_reset ( efab );
2030 
2031  /* Initialise PHY */
2032  efab->phy_op->init ( efab );
2033 
2034  /* check the link is up */
2035  if ( !efab->link_up )
2036  return -EAGAIN;
2037 
2038  /* Initialise MAC */
2039  mentormac_init ( efab );
2040 
2041  /* reconfigure the MAC wrapper */
2043 
2044  return 0;
2045 }
2046 
2049 };
2050 
2051 
2052 /*******************************************************************************
2053  *
2054  *
2055  * XMAC handling
2056  *
2057  *
2058  *******************************************************************************/
2059 
2060 /**
2061  * Write dword to a Falcon XMAC register
2062  *
2063  */
2064 static void
2066  unsigned int mac_reg )
2067 {
2068  efab_oword_t temp;
2069 
2070  EFAB_POPULATE_OWORD_1 ( temp, FCN_MAC_DATA,
2071  EFAB_DWORD_FIELD ( *value, FCN_MAC_DATA ) );
2072  falcon_write ( efab, &temp,
2073  FALCON_XMAC_REG ( efab, mac_reg ) );
2074 }
2075 
2076 /**
2077  * Read dword from a Falcon XMAC register
2078  *
2079  */
2080 static void
2082  unsigned int mac_reg )
2083 {
2084  efab_oword_t temp;
2085 
2086  falcon_read ( efab, &temp,
2087  FALCON_XMAC_REG ( efab, mac_reg ) );
2088  EFAB_POPULATE_DWORD_1 ( *value, FCN_MAC_DATA,
2089  EFAB_OWORD_FIELD ( temp, FCN_MAC_DATA ) );
2090 }
2091 
2092 /**
2093  * Configure Falcon XAUI output
2094  */
2095 static void
2096 falcon_setup_xaui ( struct efab_nic *efab )
2097 {
2098  efab_dword_t sdctl, txdrv;
2099 
2100  falcon_xmac_readl ( efab, &sdctl, FCN_XX_SD_CTL_REG_MAC );
2101  EFAB_SET_DWORD_FIELD ( sdctl, FCN_XX_HIDRVD, XX_SD_CTL_DRV_DEFAULT );
2102  EFAB_SET_DWORD_FIELD ( sdctl, FCN_XX_LODRVD, XX_SD_CTL_DRV_DEFAULT );
2103  EFAB_SET_DWORD_FIELD ( sdctl, FCN_XX_HIDRVC, XX_SD_CTL_DRV_DEFAULT );
2104  EFAB_SET_DWORD_FIELD ( sdctl, FCN_XX_LODRVC, XX_SD_CTL_DRV_DEFAULT );
2105  EFAB_SET_DWORD_FIELD ( sdctl, FCN_XX_HIDRVB, XX_SD_CTL_DRV_DEFAULT );
2106  EFAB_SET_DWORD_FIELD ( sdctl, FCN_XX_LODRVB, XX_SD_CTL_DRV_DEFAULT );
2107  EFAB_SET_DWORD_FIELD ( sdctl, FCN_XX_HIDRVA, XX_SD_CTL_DRV_DEFAULT );
2108  EFAB_SET_DWORD_FIELD ( sdctl, FCN_XX_LODRVA, XX_SD_CTL_DRV_DEFAULT );
2109  falcon_xmac_writel ( efab, &sdctl, FCN_XX_SD_CTL_REG_MAC );
2110 
2111  EFAB_POPULATE_DWORD_8 ( txdrv,
2112  FCN_XX_DEQD, XX_TXDRV_DEQ_DEFAULT,
2113  FCN_XX_DEQC, XX_TXDRV_DEQ_DEFAULT,
2114  FCN_XX_DEQB, XX_TXDRV_DEQ_DEFAULT,
2115  FCN_XX_DEQA, XX_TXDRV_DEQ_DEFAULT,
2116  FCN_XX_DTXD, XX_TXDRV_DTX_DEFAULT,
2117  FCN_XX_DTXC, XX_TXDRV_DTX_DEFAULT,
2118  FCN_XX_DTXB, XX_TXDRV_DTX_DEFAULT,
2119  FCN_XX_DTXA, XX_TXDRV_DTX_DEFAULT);
2121 }
2122 
2123 static int
2125 {
2126  efab_dword_t reg;
2127 
2128  if ( efab->pci_revision < FALCON_REV_B0 )
2129  return 1;
2130  /* The ISR latches, so clear it and re-read */
2133 
2134  if ( EFAB_DWORD_FIELD ( reg, FCN_XM_LCLFLT ) ||
2135  EFAB_DWORD_FIELD ( reg, FCN_XM_RMTFLT ) ) {
2136  EFAB_TRACE ( "MGT_INT: "EFAB_DWORD_FMT"\n",
2137  EFAB_DWORD_VAL ( reg ) );
2138  return 0;
2139  }
2140 
2141  return 1;
2142 }
2143 
2144 static void
2145 falcon_mask_status_intr ( struct efab_nic *efab, int enable )
2146 {
2147  efab_dword_t reg;
2148 
2149  if ( efab->pci_revision < FALCON_REV_B0 )
2150  return;
2151 
2152  /* Flush the ISR */
2153  if ( enable )
2155 
2157  FCN_XM_MSK_RMTFLT, !enable,
2158  FCN_XM_MSK_LCLFLT, !enable);
2160 }
2161 
2162 /**
2163  * Reset 10G MAC connected to port
2164  *
2165  */
2166 static int
2167 falcon_reset_xmac ( struct efab_nic *efab )
2168 {
2169  efab_dword_t reg;
2170  int count;
2171 
2172  EFAB_POPULATE_DWORD_1 ( reg, FCN_XM_CORE_RST, 1 );
2174 
2175  for ( count = 0 ; count < 1000 ; count++ ) {
2176  udelay ( 10 );
2177  falcon_xmac_readl ( efab, &reg,
2179  if ( EFAB_DWORD_FIELD ( reg, FCN_XM_CORE_RST ) == 0 )
2180  return 0;
2181  }
2182  return -ETIMEDOUT;
2183 }
2184 
2185 
2186 static int
2187 falcon_reset_xaui ( struct efab_nic *efab )
2188 {
2189  efab_dword_t reg;
2190  int count;
2191 
2192  if (!efab->is_asic)
2193  return 0;
2194 
2195  EFAB_POPULATE_DWORD_1 ( reg, FCN_XX_RST_XX_EN, 1 );
2197 
2198  /* Give some time for the link to establish */
2199  for (count = 0; count < 1000; count++) { /* wait up to 10ms */
2201  if ( EFAB_DWORD_FIELD ( reg, FCN_XX_RST_XX_EN ) == 0 ) {
2202  falcon_setup_xaui ( efab );
2203  return 0;
2204  }
2205  udelay(10);
2206  }
2207  EFAB_ERR ( "timed out waiting for XAUI/XGXS reset\n" );
2208  return -ETIMEDOUT;
2209 }
2210 
2211 static int
2213 {
2214  efab_dword_t reg;
2215  int align_done, lane_status, sync;
2216  int has_phyxs;
2217  int link_ok = 1;
2218 
2219  /* Read Falcon XAUI side */
2220  if ( efab->is_asic ) {
2221  /* Read link status */
2223  align_done = EFAB_DWORD_FIELD ( reg, FCN_XX_ALIGN_DONE );
2224 
2225  sync = EFAB_DWORD_FIELD ( reg, FCN_XX_SYNC_STAT );
2227 
2228  link_ok = align_done && sync;
2229 
2230  /* Clear link status ready for next read */
2231  EFAB_SET_DWORD_FIELD ( reg, FCN_XX_COMMA_DET,
2233  EFAB_SET_DWORD_FIELD ( reg, FCN_XX_CHARERR,
2235  EFAB_SET_DWORD_FIELD ( reg, FCN_XX_DISPERR,
2238  }
2239 
2240  has_phyxs = ( efab->phy_op->mmds & ( 1 << MDIO_MMD_PHYXS ) );
2241  if ( link_ok && has_phyxs ) {
2242  lane_status = falcon_mdio_read ( efab, MDIO_MMD_PHYXS,
2244  link_ok = ( lane_status & ( 1 << MDIO_PHYXS_LANE_ALIGNED_LBN ) );
2245 
2246  if (!link_ok )
2247  EFAB_LOG ( "XGXS lane status: %x\n", lane_status );
2248  }
2249 
2250  return link_ok;
2251 }
2252 
2253 /**
2254  * Initialise XMAC
2255  *
2256  */
2257 static void
2259 {
2260  efab_dword_t reg;
2261  int max_frame_len;
2262 
2263  /* Configure MAC - cut-thru mode is hard wired on */
2265  FCN_XM_RX_JUMBO_MODE, 1,
2266  FCN_XM_TX_STAT_EN, 1,
2267  FCN_XM_RX_STAT_EN, 1);
2269 
2270  /* Configure TX */
2272  FCN_XM_TXEN, 1,
2273  FCN_XM_TX_PRMBL, 1,
2274  FCN_XM_AUTO_PAD, 1,
2275  FCN_XM_TXCRC, 1,
2276  FCN_XM_FCNTL, 1,
2277  FCN_XM_IPG, 0x3 );
2279 
2280  /* Configure RX */
2282  FCN_XM_RXEN, 1,
2283  FCN_XM_AUTO_DEPAD, 0,
2284  FCN_XM_ACPT_ALL_MCAST, 1,
2285  FCN_XM_PASS_CRC_ERR, 1 );
2287 
2288  /* Set frame length */
2289  max_frame_len = EFAB_MAX_FRAME_LEN ( ETH_FRAME_LEN );
2291  FCN_XM_MAX_RX_FRM_SIZE, max_frame_len );
2294  FCN_XM_MAX_TX_FRM_SIZE, max_frame_len,
2295  FCN_XM_TX_JUMBO_MODE, 1 );
2297 
2298  /* Enable flow control receipt */
2300  FCN_XM_PAUSE_TIME, 0xfffe,
2301  FCN_XM_DIS_FCNTL, 0 );
2303 
2304  /* Set MAC address */
2306  FCN_XM_ADR_0, efab->mac_addr[0],
2307  FCN_XM_ADR_1, efab->mac_addr[1],
2308  FCN_XM_ADR_2, efab->mac_addr[2],
2309  FCN_XM_ADR_3, efab->mac_addr[3] );
2312  FCN_XM_ADR_4, efab->mac_addr[4],
2313  FCN_XM_ADR_5, efab->mac_addr[5] );
2315 }
2316 
2317 static int
2318 falcon_init_xmac ( struct efab_nic *efab )
2319 {
2320  int count, rc;
2321 
2322  /* Mask the PHY management interrupt */
2323  falcon_mask_status_intr ( efab, 0 );
2324 
2325  /* Initialise the PHY to instantiate the clock. */
2326  rc = efab->phy_op->init ( efab );
2327  if ( rc ) {
2328  EFAB_ERR ( "unable to initialise PHY\n" );
2329  goto fail1;
2330  }
2331 
2332  falcon_reset_xaui ( efab );
2333 
2334  /* Give the PHY and MAC time to faff */
2335  mdelay ( 100 );
2336 
2337  /* Reset and reconfigure the XMAC */
2338  rc = falcon_reset_xmac ( efab );
2339  if ( rc )
2340  goto fail2;
2341  falcon_reconfigure_xmac ( efab );
2343  /**
2344  * Now wait for the link to come up. This may take a while
2345  * for some slower PHY's.
2346  */
2347  for (count=0; count<50; count++) {
2348  int link_ok = 1;
2349 
2350  /* Wait a while for the link to come up. */
2351  mdelay ( 100 );
2352  if ((count % 5) == 0)
2353  putchar ( '.' );
2354 
2355  /* Does the PHY think the wire-side link is up? */
2356  link_ok = mdio_clause45_links_ok ( efab );
2357  /* Ensure the XAUI link to the PHY is good */
2358  if ( link_ok ) {
2359  link_ok = falcon_xaui_link_ok ( efab );
2360  if ( !link_ok )
2361  falcon_reset_xaui ( efab );
2362  }
2363 
2364  /* Check fault indication */
2365  if ( link_ok )
2366  link_ok = falcon_xgmii_status ( efab );
2367 
2368  efab->link_up = link_ok;
2369  if ( link_ok ) {
2370  /* unmask the status interrupt */
2371  falcon_mask_status_intr ( efab, 1 );
2372  return 0;
2373  }
2374  }
2375 
2376  /* Link failed to come up, but initialisation was fine. */
2377  rc = -ETIMEDOUT;
2378 
2379 fail2:
2380 fail1:
2381  return rc;
2382 }
2383 
2386 };
2387 
2388 /*******************************************************************************
2389  *
2390  *
2391  * Null PHY handling
2392  *
2393  *
2394  *******************************************************************************/
2395 
2396 static int
2398 {
2399  /* CX4 is always 10000FD only */
2401 
2402  /* There is no PHY! */
2403  return 0;
2404 }
2405 
2408  .mmds = 0,
2409 };
2410 
2411 
2412 /*******************************************************************************
2413  *
2414  *
2415  * Alaska PHY
2416  *
2417  *
2418  *******************************************************************************/
2419 
2420 /**
2421  * Initialise Alaska PHY
2422  *
2423  */
2424 static int
2425 alaska_init ( struct efab_nic *efab )
2426 {
2427  unsigned int advertised, lpa;
2428 
2429  /* Read link up status */
2430  efab->link_up = gmii_link_ok ( efab );
2431 
2432  if ( ! efab->link_up )
2433  return -EIO;
2434 
2435  /* Determine link options from PHY. */
2436  advertised = gmii_autoneg_advertised ( efab );
2437  lpa = gmii_autoneg_lpa ( efab );
2438  efab->link_options = gmii_nway_result ( advertised & lpa );
2439 
2440  return 0;
2441 }
2442 
2444  .init = alaska_init,
2445 };
2446 
2447 /*******************************************************************************
2448  *
2449  *
2450  * xfp
2451  *
2452  *
2453  *******************************************************************************/
2454 
2455 #define XFP_REQUIRED_DEVS ( MDIO_MMDREG_DEVS0_PCS | \
2456  MDIO_MMDREG_DEVS0_PMAPMD | \
2457  MDIO_MMDREG_DEVS0_PHYXS )
2458 
2459 static int
2461 {
2462  int rc;
2463 
2464  /* Optical link is always 10000FD only */
2466 
2467  /* Reset the PHY */
2469  if ( rc )
2470  return rc;
2471 
2472  return 0;
2473 }
2474 
2477  .mmds = XFP_REQUIRED_DEVS,
2478 };
2479 
2480 /*******************************************************************************
2481  *
2482  *
2483  * txc43128
2484  *
2485  *
2486  *******************************************************************************/
2487 
2488 /* Command register */
2489 #define TXC_GLRGS_GLCMD (0xc004)
2490 #define TXC_GLCMD_LMTSWRST_LBN (14)
2491 
2492 /* Amplitude on lanes 0+1, 2+3 */
2493 #define TXC_ALRGS_ATXAMP0 (0xc041)
2494 #define TXC_ALRGS_ATXAMP1 (0xc042)
2495 /* Bit position of value for lane 0+2, 1+3 */
2496 #define TXC_ATXAMP_LANE02_LBN (3)
2497 #define TXC_ATXAMP_LANE13_LBN (11)
2498 
2499 #define TXC_ATXAMP_1280_mV (0)
2500 #define TXC_ATXAMP_1200_mV (8)
2501 #define TXC_ATXAMP_1120_mV (12)
2502 #define TXC_ATXAMP_1060_mV (14)
2503 #define TXC_ATXAMP_0820_mV (25)
2504 #define TXC_ATXAMP_0720_mV (26)
2505 #define TXC_ATXAMP_0580_mV (27)
2506 #define TXC_ATXAMP_0440_mV (28)
2507 
2508 #define TXC_ATXAMP_0820_BOTH ( (TXC_ATXAMP_0820_mV << TXC_ATXAMP_LANE02_LBN) | \
2509  (TXC_ATXAMP_0820_mV << TXC_ATXAMP_LANE13_LBN) )
2510 
2511 #define TXC_ATXAMP_DEFAULT (0x6060) /* From databook */
2512 
2513 /* Preemphasis on lanes 0+1, 2+3 */
2514 #define TXC_ALRGS_ATXPRE0 (0xc043)
2515 #define TXC_ALRGS_ATXPRE1 (0xc044)
2516 
2517 #define TXC_ATXPRE_NONE (0)
2518 #define TXC_ATXPRE_DEFAULT (0x1010) /* From databook */
2519 
2520 #define TXC_REQUIRED_DEVS ( MDIO_MMDREG_DEVS0_PCS | \
2521  MDIO_MMDREG_DEVS0_PMAPMD | \
2522  MDIO_MMDREG_DEVS0_PHYXS )
2523 
2524 static int
2526 {
2527  int val;
2528  int tries = 50;
2529 
2531  val |= (1 << TXC_GLCMD_LMTSWRST_LBN);
2533 
2534  while ( tries--) {
2536  if ( ~val & ( 1 << TXC_GLCMD_LMTSWRST_LBN ) )
2537  return 0;
2538  udelay(1);
2539  }
2540 
2541  EFAB_ERR ( "logic reset failed\n" );
2542 
2543  return -ETIMEDOUT;
2544 }
2545 
2546 static int
2548 {
2549  int rc;
2550 
2551  /* CX4 is always 10000FD only */
2553 
2554  /* reset the phy */
2556  if ( rc )
2557  goto fail1;
2558 
2559  rc = mdio_clause45_check_mmds ( efab );
2560  if ( rc )
2561  goto fail2;
2562 
2563  /* Turn amplitude down and preemphasis off on the host side
2564  * (PHY<->MAC) as this is believed less likely to upset falcon
2565  * and no adverse effects have been noted. It probably also
2566  * saves a picowatt or two */
2567 
2568  /* Turn off preemphasis */
2570  TXC_ATXPRE_NONE );
2572  TXC_ATXPRE_NONE );
2573 
2574  /* Turn down the amplitude */
2579 
2580  /* Set the line side amplitude and preemphasis to the databook
2581  * defaults as an erratum causes them to be 0 on at least some
2582  * PHY rev.s */
2591 
2592  rc = falcon_txc_logic_reset ( efab );
2593  if ( rc )
2594  goto fail3;
2595 
2596  return 0;
2597 
2598 fail3:
2599 fail2:
2600 fail1:
2601  return rc;
2602 }
2603 
2606  .mmds = TXC_REQUIRED_DEVS,
2607 };
2608 
2609 /*******************************************************************************
2610  *
2611  *
2612  * tenxpress
2613  *
2614  *
2615  *******************************************************************************/
2616 
2617 
2618 #define TENXPRESS_REQUIRED_DEVS ( MDIO_MMDREG_DEVS0_PMAPMD | \
2619  MDIO_MMDREG_DEVS0_PCS | \
2620  MDIO_MMDREG_DEVS0_PHYXS )
2621 
2622 #define PCS_TEST_SELECT_REG 0xd807 /* PRM 10.5.8 */
2623 #define CLK312_EN_LBN 3
2624 #define CLK312_EN_WIDTH 1
2625 
2626 #define PCS_CLOCK_CTRL_REG 0xd801
2627 #define PLL312_RST_N_LBN 2
2628 
2629 /* Special Software reset register */
2630 #define PMA_PMD_EXT_CTRL_REG 49152
2631 #define PMA_PMD_EXT_SSR_LBN 15
2632 
2633 /* Boot status register */
2634 #define PCS_BOOT_STATUS_REG 0xd000
2635 #define PCS_BOOT_FATAL_ERR_LBN 0
2636 #define PCS_BOOT_PROGRESS_LBN 1
2637 #define PCS_BOOT_PROGRESS_WIDTH 2
2638 #define PCS_BOOT_COMPLETE_LBN 3
2639 
2640 #define PCS_SOFT_RST2_REG 0xd806
2641 #define SERDES_RST_N_LBN 13
2642 #define XGXS_RST_N_LBN 12
2643 
2644 static int
2646 {
2647  int count;
2648  uint32_t boot_stat;
2649 
2650  /* Check that the C11 CPU has booted */
2651  for (count=0; count<10; count++) {
2652  boot_stat = falcon_mdio_read ( efab, MDIO_MMD_PCS,
2654  if ( boot_stat & ( 1 << PCS_BOOT_COMPLETE_LBN ) )
2655  return 0;
2656 
2657  udelay(10);
2658  }
2659 
2660  EFAB_ERR ( "C11 failed to boot\n" );
2661  return -ETIMEDOUT;
2662 }
2663 
2664 static int
2666 {
2667  int rc, reg;
2668 
2669  /* 10XPRESS is always 10000FD (at the moment) */
2671 
2672  /* Wait for the blocks to come out of reset */
2673  rc = mdio_clause45_wait_reset_mmds ( efab );
2674  if ( rc )
2675  goto fail1;
2676 
2677  rc = mdio_clause45_check_mmds ( efab );
2678  if ( rc )
2679  goto fail2;
2680 
2681  /* Turn on the clock */
2682  reg = (1 << CLK312_EN_LBN);
2684 
2685  /* Wait 200ms for the PHY to boot */
2686  mdelay(200);
2687 
2688  rc = falcon_tenxpress_check_c11 ( efab );
2689  if ( rc )
2690  goto fail3;
2691 
2692  return 0;
2693 
2694 fail3:
2695 fail2:
2696 fail1:
2697  return rc;
2698 }
2699 
2702  .mmds = TENXPRESS_REQUIRED_DEVS,
2703 };
2704 
2705 /*******************************************************************************
2706  *
2707  *
2708  * PM8358
2709  *
2710  *
2711  *******************************************************************************/
2712 
2713 /* The PM8358 just presents a DTE XS */
2714 #define PM8358_REQUIRED_DEVS (MDIO_MMDREG_DEVS0_DTEXS)
2715 
2716 /* PHY-specific definitions */
2717 /* Master ID and Global Performance Monitor Update */
2718 #define PMC_MASTER_REG (0xd000)
2719 /* Analog Tx Rx settings under software control */
2720 #define PMC_MASTER_ANLG_CTRL (1<< 11)
2721 
2722 /* Master Configuration register 2 */
2723 #define PMC_MCONF2_REG (0xd002)
2724 /* Drive Tx off centre of data eye (1) vs. clock edge (0) */
2725 #define PMC_MCONF2_TEDGE (1 << 2)
2726 /* Drive Rx off centre of data eye (1) vs. clock edge (0) */
2727 #define PMC_MCONF2_REDGE (1 << 3)
2728 
2729 /* Analog Rx settings */
2730 #define PMC_ANALOG_RX_CFG0 (0xd025)
2731 #define PMC_ANALOG_RX_CFG1 (0xd02d)
2732 #define PMC_ANALOG_RX_CFG2 (0xd035)
2733 #define PMC_ANALOG_RX_CFG3 (0xd03d)
2734 
2735 
2736 #define PMC_ANALOG_RX_TERM (1 << 15) /* Bit 15 of RX CFG: 0 for 100 ohms float,
2737  1 for 50 to 1.2V */
2738 #define PMC_ANALOG_RX_EQ_MASK (3 << 8)
2739 #define PMC_ANALOG_RX_EQ_NONE (0 << 8)
2740 #define PMC_ANALOG_RX_EQ_HALF (1 << 8)
2741 #define PMC_ANALOG_RX_EQ_FULL (2 << 8)
2742 #define PMC_ANALOG_RX_EQ_RSVD (3 << 8)
2743 
2744 static int
2746 {
2747  int rc, reg, i;
2748 
2749  /* This is a XAUI retimer part */
2751 
2753  if ( rc )
2754  return rc;
2755 
2756  /* Enable software control of analogue settings */
2760 
2761  /* Turn rx eq on for all channels */
2762  for (i=0; i< 3; i++) {
2763  /* The analog CFG registers are evenly spaced 8 apart */
2765  reg = falcon_mdio_read ( efab, MDIO_MMD_DTEXS, addr );
2768  }
2769 
2770  /* Set TEDGE, clear REDGE */
2774 
2775  return 0;
2776 }
2777 
2780  .mmds = PM8358_REQUIRED_DEVS,
2781 };
2782 
2783 /*******************************************************************************
2784  *
2785  *
2786  * SFE4001 support
2787  *
2788  *
2789  *******************************************************************************/
2790 
2791 #define MAX_TEMP_THRESH 90
2792 
2793 /* I2C Expander */
2794 #define PCA9539 0x74
2795 
2796 #define P0_IN 0x00
2797 #define P0_OUT 0x02
2798 #define P0_CONFIG 0x06
2799 
2800 #define P0_EN_1V0X_LBN 0
2801 #define P0_EN_1V0X_WIDTH 1
2802 #define P0_EN_1V2_LBN 1
2803 #define P0_EN_1V2_WIDTH 1
2804 #define P0_EN_2V5_LBN 2
2805 #define P0_EN_2V5_WIDTH 1
2806 #define P0_EN_3V3X_LBN 3
2807 #define P0_EN_3V3X_WIDTH 1
2808 #define P0_EN_5V_LBN 4
2809 #define P0_EN_5V_WIDTH 1
2810 #define P0_X_TRST_LBN 6
2811 #define P0_X_TRST_WIDTH 1
2812 
2813 #define P1_IN 0x01
2814 #define P1_CONFIG 0x07
2815 
2816 #define P1_AFE_PWD_LBN 0
2817 #define P1_AFE_PWD_WIDTH 1
2818 #define P1_DSP_PWD25_LBN 1
2819 #define P1_DSP_PWD25_WIDTH 1
2820 #define P1_SPARE_LBN 4
2821 #define P1_SPARE_WIDTH 4
2822 
2823 /* Temperature Sensor */
2824 #define MAX6647 0x4e
2825 
2826 #define RSL 0x02
2827 #define RLHN 0x05
2828 #define WLHO 0x0b
2829 
2830 static struct i2c_device i2c_pca9539 = {
2831  .dev_addr = PCA9539,
2832  .dev_addr_len = 1,
2833  .word_addr_len = 1,
2834 };
2835 
2836 
2837 static struct i2c_device i2c_max6647 = {
2838  .dev_addr = MAX6647,
2839  .dev_addr_len = 1,
2840  .word_addr_len = 1,
2841 };
2842 
2843 static int
2844 sfe4001_init ( struct efab_nic *efab )
2845 {
2846  struct i2c_interface *i2c = &efab->i2c_bb.i2c;
2847  efab_dword_t reg;
2848  uint8_t in, cfg, out;
2849  int count, rc;
2850 
2851  EFAB_LOG ( "Initialise SFE4001 board\n" );
2852 
2853  /* Ensure XGXS and XAUI SerDes are held in reset */
2855  FCN_XX_PWRDNA_EN, 1,
2856  FCN_XX_PWRDNB_EN, 1,
2857  FCN_XX_RSTPLLAB_EN, 1,
2858  FCN_XX_RESETA_EN, 1,
2859  FCN_XX_RESETB_EN, 1,
2860  FCN_XX_RSTXGXSRX_EN, 1,
2861  FCN_XX_RSTXGXSTX_EN, 1 );
2863  udelay(10);
2864 
2865  /* Set DSP over-temperature alert threshold */
2866  cfg = MAX_TEMP_THRESH;
2867  rc = i2c->write ( i2c, &i2c_max6647, WLHO, &cfg, EFAB_BYTE );
2868  if ( rc )
2869  goto fail1;
2870 
2871  /* Read it back and verify */
2872  rc = i2c->read ( i2c, &i2c_max6647, RLHN, &in, EFAB_BYTE );
2873  if ( rc )
2874  goto fail2;
2875 
2876  if ( in != MAX_TEMP_THRESH ) {
2877  EFAB_ERR ( "Unable to verify MAX6647 limit (requested=%d "
2878  "confirmed=%d)\n", cfg, in );
2879  rc = -EIO;
2880  goto fail3;
2881  }
2882 
2883  /* Clear any previous over-temperature alert */
2884  rc = i2c->read ( i2c, &i2c_max6647, RSL, &in, EFAB_BYTE );
2885  if ( rc )
2886  goto fail4;
2887 
2888  /* Enable port 0 and 1 outputs on IO expander */
2889  cfg = 0x00;
2890  rc = i2c->write ( i2c, &i2c_pca9539, P0_CONFIG, &cfg, EFAB_BYTE );
2891  if ( rc )
2892  goto fail5;
2893  cfg = 0xff & ~(1 << P1_SPARE_LBN);
2894  rc = i2c->write ( i2c, &i2c_pca9539, P1_CONFIG, &cfg, EFAB_BYTE );
2895  if ( rc )
2896  goto fail6;
2897 
2898  /* Turn all power off then wait 1 sec. This ensures PHY is reset */
2899  out = 0xff & ~((0 << P0_EN_1V2_LBN) | (0 << P0_EN_2V5_LBN) |
2900  (0 << P0_EN_3V3X_LBN) | (0 << P0_EN_5V_LBN) |
2901  (0 << P0_EN_1V0X_LBN));
2902 
2903  rc = i2c->write ( i2c, &i2c_pca9539, P0_OUT, &out, EFAB_BYTE );
2904  if ( rc )
2905  goto fail7;
2906 
2907  mdelay(1000);
2908 
2909  for (count=0; count<20; count++) {
2910  /* Turn on 1.2V, 2.5V, 3.3V and 5V power rails */
2911  out = 0xff & ~( (1 << P0_EN_1V2_LBN) | (1 << P0_EN_2V5_LBN) |
2912  (1 << P0_EN_3V3X_LBN) | (1 << P0_EN_5V_LBN) |
2913  (1 << P0_X_TRST_LBN) );
2914 
2915  rc = i2c->write ( i2c, &i2c_pca9539, P0_OUT, &out, EFAB_BYTE );
2916  if ( rc )
2917  goto fail8;
2918 
2919  mdelay ( 10 );
2920 
2921  /* Turn on the 1V power rail */
2922  out &= ~( 1 << P0_EN_1V0X_LBN );
2923  rc = i2c->write ( i2c, &i2c_pca9539, P0_OUT, &out, EFAB_BYTE );
2924  if ( rc )
2925  goto fail9;
2926 
2927  EFAB_LOG ( "Waiting for power...(attempt %d)\n", count);
2928  mdelay ( 1000 );
2929 
2930  /* Check DSP is powered */
2931  rc = i2c->read ( i2c, &i2c_pca9539, P1_IN, &in, EFAB_BYTE );
2932  if ( rc )
2933  goto fail10;
2934 
2935  if ( in & ( 1 << P1_AFE_PWD_LBN ) )
2936  return 0;
2937  }
2938 
2939  rc = -ETIMEDOUT;
2940 
2941 fail10:
2942 fail9:
2943 fail8:
2944 fail7:
2945  /* Turn off power rails */
2946  out = 0xff;
2947  (void) i2c->write ( i2c, &i2c_pca9539, P0_OUT, &out, EFAB_BYTE );
2948  /* Disable port 1 outputs on IO expander */
2949  out = 0xff;
2950  (void) i2c->write ( i2c, &i2c_pca9539, P1_CONFIG, &out, EFAB_BYTE );
2951 fail6:
2952  /* Disable port 0 outputs */
2953  out = 0xff;
2954  (void) i2c->write ( i2c, &i2c_pca9539, P1_CONFIG, &out, EFAB_BYTE );
2955 fail5:
2956 fail4:
2957 fail3:
2958 fail2:
2959 fail1:
2960  EFAB_ERR ( "Failed initialising SFE4001 board\n" );
2961  return rc;
2962 }
2963 
2964 static void
2965 sfe4001_fini ( struct efab_nic *efab )
2966 {
2967  struct i2c_interface *i2c = &efab->i2c_bb.i2c;
2968  uint8_t in, cfg, out;
2969 
2970  EFAB_ERR ( "Turning off SFE4001\n" );
2971 
2972  /* Turn off all power rails */
2973  out = 0xff;
2974  (void) i2c->write ( i2c, &i2c_pca9539, P0_OUT, &out, EFAB_BYTE );
2975 
2976  /* Disable port 1 outputs on IO expander */
2977  cfg = 0xff;
2978  (void) i2c->write ( i2c, &i2c_pca9539, P1_CONFIG, &cfg, EFAB_BYTE );
2979 
2980  /* Disable port 0 outputs on IO expander */
2981  cfg = 0xff;
2982  (void) i2c->write ( i2c, &i2c_pca9539, P0_CONFIG, &cfg, EFAB_BYTE );
2983 
2984  /* Clear any over-temperature alert */
2985  (void) i2c->read ( i2c, &i2c_max6647, RSL, &in, EFAB_BYTE );
2986 }
2987 
2989  .init = sfe4001_init,
2990  .fini = sfe4001_fini,
2991 };
2992 
2993 static int sfe4002_init ( struct efab_nic *efab __attribute__((unused)) )
2994 {
2995  return 0;
2996 }
2997 static void sfe4002_fini ( struct efab_nic *efab __attribute__((unused)) )
2998 {
2999 }
3000 
3002  .init = sfe4002_init,
3003  .fini = sfe4002_fini,
3004 };
3005 
3006 static int sfe4003_init ( struct efab_nic *efab __attribute__((unused)) )
3007 {
3008  return 0;
3009 }
3010 static void sfe4003_fini ( struct efab_nic *efab __attribute__((unused)) )
3011 {
3012 }
3013 
3015  .init = sfe4003_init,
3016  .fini = sfe4003_fini,
3017 };
3018 
3019 /*******************************************************************************
3020  *
3021  *
3022  * Hardware initialisation
3023  *
3024  *
3025  *******************************************************************************/
3026 
3027 static void
3029 {
3030  /* We don't bother cleaning up the buffer table entries -
3031  * we're hardly limited */
3032  free_phys ( p, EFAB_BUF_ALIGN );
3033 }
3034 
3035 static void*
3037  struct efab_special_buffer *entry )
3038 {
3039  void* buffer;
3040  int remaining;
3041  efab_qword_t buf_desc;
3042  unsigned long dma_addr;
3043 
3044  /* Allocate the buffer, aligned on a buffer address boundary */
3046  if ( ! buffer )
3047  return NULL;
3048 
3049  /* Push buffer table entries to back the buffer */
3050  entry->id = efab->buffer_head;
3051  entry->dma_addr = dma_addr = virt_to_bus ( buffer );
3052  assert ( ( dma_addr & ( EFAB_BUF_ALIGN - 1 ) ) == 0 );
3053 
3054  remaining = bytes;
3055  while ( remaining > 0 ) {
3056  EFAB_POPULATE_QWORD_3 ( buf_desc,
3057  FCN_IP_DAT_BUF_SIZE, FCN_IP_DAT_BUF_SIZE_4K,
3058  FCN_BUF_ADR_FBUF, ( dma_addr >> 12 ),
3059  FCN_BUF_OWNER_ID_FBUF, 0 );
3060 
3061  falcon_write_sram ( efab, &buf_desc, efab->buffer_head );
3062 
3063  ++efab->buffer_head;
3064  dma_addr += EFAB_BUF_ALIGN;
3065  remaining -= EFAB_BUF_ALIGN;
3066  }
3067 
3068  EFAB_TRACE ( "Allocated 0x%x bytes at %p backed by buffer table "
3069  "entries 0x%x..0x%x\n", bytes, buffer, entry->id,
3070  efab->buffer_head - 1 );
3071 
3072  return buffer;
3073 }
3074 
3075 static void
3077 {
3078  efab_oword_t blanko, temp;
3079  int offset;
3080 
3081  EFAB_ZERO_OWORD ( blanko );
3082 
3083  /* Clear the address region register */
3084  EFAB_POPULATE_OWORD_4 ( temp,
3085  FCN_ADR_REGION0, 0,
3086  FCN_ADR_REGION1, ( 1 << 16 ),
3087  FCN_ADR_REGION2, ( 2 << 16 ),
3088  FCN_ADR_REGION3, ( 3 << 16 ) );
3089  falcon_write ( efab, &temp, FCN_ADR_REGION_REG_KER );
3090 
3091  EFAB_TRACE ( "Clearing filter and RSS tables\n" );
3092 
3093  for ( offset = FCN_RX_FILTER_TBL0 ;
3095  offset += 0x10 ) {
3096  falcon_write ( efab, &blanko, offset );
3097  }
3098 
3099  EFAB_TRACE ( "Wiping buffer tables\n" );
3100 
3101  /* Notice the 8 byte access mode */
3102  for ( offset = 0x2800000 ;
3103  offset < 0x3000000 ;
3104  offset += 0x8) {
3105  _falcon_writel ( efab, 0, offset );
3106  _falcon_writel ( efab, 0, offset + 4 );
3107  wmb();
3108  }
3109 }
3110 
3111 static int
3112 falcon_reset ( struct efab_nic *efab )
3113 {
3114  efab_oword_t glb_ctl_reg_ker;
3115 
3116  /* Initiate software reset */
3117  EFAB_POPULATE_OWORD_6 ( glb_ctl_reg_ker,
3118  FCN_PCIE_CORE_RST_CTL, EXCLUDE_FROM_RESET,
3119  FCN_PCIE_NSTCK_RST_CTL, EXCLUDE_FROM_RESET,
3120  FCN_PCIE_SD_RST_CTL, EXCLUDE_FROM_RESET,
3121  FCN_EE_RST_CTL, EXCLUDE_FROM_RESET,
3122  FCN_EXT_PHY_RST_DUR, 0x7, /* 10ms */
3123  FCN_SWRST, 1 );
3124 
3125  falcon_write ( efab, &glb_ctl_reg_ker, FCN_GLB_CTL_REG_KER );
3126 
3127  /* Allow 50ms for reset */
3128  mdelay ( 50 );
3129 
3130  /* Check for device reset complete */
3131  falcon_read ( efab, &glb_ctl_reg_ker, FCN_GLB_CTL_REG_KER );
3132  if ( EFAB_OWORD_FIELD ( glb_ctl_reg_ker, FCN_SWRST ) != 0 ) {
3133  EFAB_ERR ( "Reset failed\n" );
3134  return -ETIMEDOUT;
3135  }
3136 
3137  if ( ( efab->pci_revision == FALCON_REV_B0 ) && !efab->is_asic ) {
3138  clear_b0_fpga_memories ( efab );
3139  }
3140 
3141  return 0;
3142 }
3143 
3144 /** Offset of MAC address within EEPROM or Flash */
3145 #define FALCON_MAC_ADDRESS_OFFSET 0x310
3146 
3147 /*
3148  * Falcon EEPROM structure
3149  */
3150 #define SF_NV_CONFIG_BASE 0x300
3151 #define SF_NV_CONFIG_EXTRA 0xA0
3152 
3162 };
3163 
3168  union {
3170  } ver_specific;
3171 };
3172 
3173 #define BOARD_TYPE(_rev) (_rev >> 8)
3174 
3175 static void
3176 falcon_probe_nic_variant ( struct efab_nic *efab, struct pci_device *pci )
3177 {
3178  efab_oword_t altera_build, nic_stat;
3179  int fpga_version;
3180  uint8_t revision;
3181 
3182  /* PCI revision */
3184  efab->pci_revision = revision;
3185 
3186  /* Asic vs FPGA */
3187  falcon_read ( efab, &altera_build, FCN_ALTERA_BUILD_REG_KER );
3188  fpga_version = EFAB_OWORD_FIELD ( altera_build, FCN_VER_ALL );
3189  efab->is_asic = (fpga_version == 0);
3190 
3191  /* MAC and PCI type */
3192  falcon_read ( efab, &nic_stat, FCN_NIC_STAT_REG );
3193  if ( efab->pci_revision == FALCON_REV_B0 ) {
3194  efab->phy_10g = EFAB_OWORD_FIELD ( nic_stat, FCN_STRAP_10G );
3195  }
3196  else if ( efab->is_asic ) {
3197  efab->phy_10g = EFAB_OWORD_FIELD ( nic_stat, FCN_STRAP_10G );
3198  }
3199  else {
3200  int minor = EFAB_OWORD_FIELD ( altera_build, FCN_VER_MINOR );
3201  efab->phy_10g = ( minor == 0x14 );
3202  }
3203 }
3204 
3205 static void
3206 falcon_init_spi_device ( struct efab_nic *efab, struct spi_device *spi )
3207 {
3208  /* Falcon's SPI interface only supports reads/writes of up to 16 bytes.
3209  * Reduce the nvs block size down to satisfy this - which means callers
3210  * should use the nvs_* functions rather than spi_*. */
3211  if ( spi->nvs.block_size > FALCON_SPI_MAX_LEN )
3213 
3214  spi->bus = &efab->spi_bus;
3215  efab->spi = spi;
3216 }
3217 
3218 static int
3219 falcon_probe_spi ( struct efab_nic *efab )
3220 {
3221  efab_oword_t nic_stat, gpio_ctl, ee_vpd_cfg;
3222  int has_flash, has_eeprom, ad9bit;
3223 
3224  falcon_read ( efab, &nic_stat, FCN_NIC_STAT_REG );
3225  falcon_read ( efab, &gpio_ctl, FCN_GPIO_CTL_REG_KER );
3226  falcon_read ( efab, &ee_vpd_cfg, FCN_EE_VPD_CFG_REG );
3227 
3228  /* determine if FLASH / EEPROM is present */
3229  if ( ( efab->pci_revision >= FALCON_REV_B0 ) || efab->is_asic ) {
3230  has_flash = EFAB_OWORD_FIELD ( nic_stat, FCN_SF_PRST );
3231  has_eeprom = EFAB_OWORD_FIELD ( nic_stat, FCN_EE_PRST );
3232  } else {
3233  has_flash = EFAB_OWORD_FIELD ( gpio_ctl, FCN_FLASH_PRESENT );
3234  has_eeprom = EFAB_OWORD_FIELD ( gpio_ctl, FCN_EEPROM_PRESENT );
3235  }
3236  ad9bit = EFAB_OWORD_FIELD ( ee_vpd_cfg, FCN_EE_VPD_EN_AD9_MODE );
3237 
3238  /* Configure the SPI and I2C bus */
3239  efab->spi_bus.rw = falcon_spi_rw;
3241 
3242  /* Configure the EEPROM SPI device. Generally, an Atmel 25040
3243  * (or similar) is used, but this is only possible if there is also
3244  * a flash device present to store the boot-time chip configuration.
3245  */
3246  if ( has_eeprom ) {
3247  if ( has_flash && ad9bit )
3248  init_at25040 ( &efab->spi_eeprom );
3249  else
3250  init_mc25xx640 ( &efab->spi_eeprom );
3251  falcon_init_spi_device ( efab, &efab->spi_eeprom );
3252  }
3253 
3254  /* Configure the FLASH SPI device */
3255  if ( has_flash ) {
3256  init_at25f1024 ( &efab->spi_flash );
3257  falcon_init_spi_device ( efab, &efab->spi_flash );
3258  }
3259 
3260  EFAB_LOG ( "flash is %s, EEPROM is %s%s\n",
3261  ( has_flash ? "present" : "absent" ),
3262  ( has_eeprom ? "present " : "absent" ),
3263  ( has_eeprom ? (ad9bit ? "(9bit)" : "(16bit)") : "") );
3264 
3265  /* The device MUST have flash or eeprom */
3266  if ( ! efab->spi ) {
3267  EFAB_ERR ( "Device appears to have no flash or eeprom\n" );
3268  return -EIO;
3269  }
3270 
3271  /* If the device has EEPROM attached, then advertise NVO space */
3272  if ( has_eeprom ) {
3273  nvo_init ( &efab->nvo, &efab->spi_eeprom.nvs, 0x100, 0xf0,
3274  NULL, &efab->netdev->refcnt );
3275  }
3276 
3277  return 0;
3278 }
3279 
3280 static int
3282 {
3283  struct nvs_device *nvs = &efab->spi->nvs;
3284  struct falcon_nv_extra nv;
3285  int rc, board_revision;
3286 
3287  /* Read the MAC address */
3289  efab->mac_addr, ETH_ALEN );
3290  if ( rc )
3291  return rc;
3292 
3293  /* Poke through the NVRAM structure for the PHY type. */
3295  &nv, sizeof ( nv ) );
3296  if ( rc )
3297  return rc;
3298 
3299  /* Handle each supported NVRAM version */
3300  if ( ( le16_to_cpu ( nv.magicnumber ) == FCN_NV_MAGIC_NUMBER ) &&
3301  ( le16_to_cpu ( nv.structure_version ) >= 2 ) ) {
3302  struct falcon_nv_config_ver2* ver2 = &nv.ver_specific.ver2;
3303 
3304  /* Get the PHY type */
3305  efab->phy_addr = le16_to_cpu ( ver2->port0_phy_addr );
3306  efab->phy_type = le16_to_cpu ( ver2->port0_phy_type );
3308  }
3309  else {
3310  EFAB_ERR ( "NVram is not recognised\n" );
3311  return -EINVAL;
3312  }
3313 
3314  efab->board_type = BOARD_TYPE ( board_revision );
3315 
3316  EFAB_TRACE ( "Falcon board %d phy %d @ addr %d\n",
3317  efab->board_type, efab->phy_type, efab->phy_addr );
3318 
3319  /* Patch in the board operations */
3320  switch ( efab->board_type ) {
3321  case EFAB_BOARD_SFE4001:
3322  efab->board_op = &sfe4001_ops;
3323  break;
3324  case EFAB_BOARD_SFE4002:
3325  efab->board_op = &sfe4002_ops;
3326  break;
3327  case EFAB_BOARD_SFE4003:
3328  efab->board_op = &sfe4003_ops;
3329  break;
3330  default:
3331  EFAB_ERR ( "Unrecognised board type\n" );
3332  return -EINVAL;
3333  }
3334 
3335  /* Patch in MAC operations */
3336  if ( efab->phy_10g )
3337  efab->mac_op = &falcon_xmac_operations;
3338  else
3339  efab->mac_op = &falcon_gmac_operations;
3340 
3341  /* Hook in the PHY ops */
3342  switch ( efab->phy_type ) {
3343  case PHY_TYPE_10XPRESS:
3345  break;
3346  case PHY_TYPE_CX4:
3347  efab->phy_op = &falcon_xaui_phy_ops;
3348  break;
3349  case PHY_TYPE_XFP:
3350  efab->phy_op = &falcon_xfp_phy_ops;
3351  break;
3352  case PHY_TYPE_CX4_RTMR:
3353  efab->phy_op = &falcon_txc_phy_ops;
3354  break;
3355  case PHY_TYPE_PM8358:
3356  efab->phy_op = &falcon_pm8358_phy_ops;
3357  break;
3358  case PHY_TYPE_1GIG_ALASKA:
3359  efab->phy_op = &falcon_alaska_phy_ops;
3360  break;
3361  default:
3362  EFAB_ERR ( "Unknown PHY type: %d\n", efab->phy_type );
3363  return -EINVAL;
3364  }
3365 
3366  return 0;
3367 }
3368 
3369 static int
3370 falcon_init_sram ( struct efab_nic *efab )
3371 {
3372  efab_oword_t reg;
3373  int count;
3374 
3375  /* use card in internal SRAM mode */
3376  falcon_read ( efab, &reg, FCN_NIC_STAT_REG );
3377  EFAB_SET_OWORD_FIELD ( reg, FCN_ONCHIP_SRAM, 1 );
3378  falcon_write ( efab, &reg, FCN_NIC_STAT_REG );
3379 
3380  /* Deactivate any external SRAM that might be present */
3382  FCN_GPIO1_OEN, 1,
3383  FCN_GPIO1_OUT, 1 );
3385 
3386  /* Initiate SRAM reset */
3388  FCN_SRAM_OOB_BT_INIT_EN, 1,
3389  FCN_SRM_NUM_BANKS_AND_BANK_SIZE, 0 );
3390  falcon_write ( efab, &reg, FCN_SRM_CFG_REG_KER );
3391 
3392  /* Wait for SRAM reset to complete */
3393  count = 0;
3394  do {
3395  /* SRAM reset is slow; expect around 16ms */
3396  mdelay ( 20 );
3397 
3398  /* Check for reset complete */
3399  falcon_read ( efab, &reg, FCN_SRM_CFG_REG_KER );
3400  if ( !EFAB_OWORD_FIELD ( reg, FCN_SRAM_OOB_BT_INIT_EN ) )
3401  return 0;
3402  } while (++count < 20); /* wait up to 0.4 sec */
3403 
3404  EFAB_ERR ( "timed out waiting for SRAM reset\n");
3405  return -ETIMEDOUT;
3406 }
3407 
3408 static void
3409 falcon_setup_nic ( struct efab_nic *efab )
3410 {
3411  efab_dword_t timer_cmd;
3412  efab_oword_t reg;
3413  int tx_fc, xoff_thresh, xon_thresh;
3414 
3415  /* bug5129: Clear the parity enables on the TX data fifos as
3416  * they produce false parity errors because of timing issues
3417  */
3418  falcon_read ( efab, &reg, FCN_SPARE_REG_KER );
3419  EFAB_SET_OWORD_FIELD ( reg, FCN_MEM_PERR_EN_TX_DATA, 0 );
3420  falcon_write ( efab, &reg, FCN_SPARE_REG_KER );
3421 
3422  /* Set up TX and RX descriptor caches in SRAM */
3423  EFAB_POPULATE_OWORD_1 ( reg, FCN_SRM_TX_DC_BASE_ADR, 0x130000 );
3425  EFAB_POPULATE_OWORD_1 ( reg, FCN_TX_DC_SIZE, 1 /* 16 descriptors */ );
3427  EFAB_POPULATE_OWORD_1 ( reg, FCN_SRM_RX_DC_BASE_ADR, 0x100000 );
3429  EFAB_POPULATE_OWORD_1 ( reg, FCN_RX_DC_SIZE, 2 /* 32 descriptors */ );
3431 
3432  /* Set number of RSS CPUs
3433  * bug7244: Increase filter depth to reduce RX_RESET likelihood
3434  */
3436  FCN_NUM_KER, 0,
3437  FCN_UDP_FULL_SRCH_LIMIT, 8,
3438  FCN_UDP_WILD_SRCH_LIMIT, 8,
3439  FCN_TCP_WILD_SRCH_LIMIT, 8,
3440  FCN_TCP_FULL_SRCH_LIMIT, 8);
3442  udelay ( 1000 );
3443 
3444  /* Setup RX. Wait for descriptor is broken and must
3445  * be disabled. RXDP recovery shouldn't be needed, but is.
3446  * disable ISCSI parsing because we don't need it
3447  */
3449  EFAB_SET_OWORD_FIELD ( reg, FCN_RX_NODESC_WAIT_DIS, 1 );
3450  EFAB_SET_OWORD_FIELD ( reg, FCN_RX_RECOVERY_EN, 1 );
3451  EFAB_SET_OWORD_FIELD ( reg, FCN_RX_ISCSI_DIS, 1 );
3453 
3454  /* Determine recommended flow control settings. *
3455  * Flow control is qualified on B0 and A1/1G, not on A1/10G */
3456  if ( efab->pci_revision == FALCON_REV_B0 ) {
3457  tx_fc = 1;
3458  xoff_thresh = 54272; /* ~80Kb - 3*max MTU */
3459  xon_thresh = 27648; /* ~3*max MTU */
3460  }
3461  else if ( !efab->phy_10g ) {
3462  tx_fc = 1;
3463  xoff_thresh = 2048;
3464  xon_thresh = 512;
3465  }
3466  else {
3467  tx_fc = xoff_thresh = xon_thresh = 0;
3468  }
3469 
3470  /* Setup TX and RX */
3471  falcon_read ( efab, &reg, FCN_TX_CFG2_REG_KER );
3472  EFAB_SET_OWORD_FIELD ( reg, FCN_TX_DIS_NON_IP_EV, 1 );
3473  falcon_write ( efab, &reg, FCN_TX_CFG2_REG_KER );
3474 
3475  falcon_read ( efab, &reg, FCN_RX_CFG_REG_KER );
3476  EFAB_SET_OWORD_FIELD_VER ( efab, reg, FCN_RX_USR_BUF_SIZE,
3477  (3*4096) / 32 );
3478  if ( efab->pci_revision == FALCON_REV_B0)
3479  EFAB_SET_OWORD_FIELD ( reg, FCN_RX_INGR_EN_B0, 1 );
3480  EFAB_SET_OWORD_FIELD_VER ( efab, reg, FCN_RX_XON_MAC_TH,
3481  xon_thresh / 256);
3482  EFAB_SET_OWORD_FIELD_VER ( efab, reg, FCN_RX_XOFF_MAC_TH,
3483  xoff_thresh / 256);
3484  EFAB_SET_OWORD_FIELD_VER ( efab, reg, FCN_RX_XOFF_MAC_EN, tx_fc);
3485  falcon_write ( efab, &reg, FCN_RX_CFG_REG_KER );
3486 
3487  /* Set timer register */
3488  EFAB_POPULATE_DWORD_2 ( timer_cmd,
3489  FCN_TIMER_MODE, FCN_TIMER_MODE_DIS,
3490  FCN_TIMER_VAL, 0 );
3491  falcon_writel ( efab, &timer_cmd, FCN_TIMER_CMD_REG_KER );
3492 }
3493 
3494 static void
3496 {
3497  struct efab_ev_queue *ev_queue = &efab->ev_queue;
3498  struct efab_rx_queue *rx_queue = &efab->rx_queue;
3499  struct efab_tx_queue *tx_queue = &efab->tx_queue;
3500 
3501  efab_oword_t reg;
3502  int jumbo;
3503 
3504  /* Initialise the ptrs */
3505  tx_queue->read_ptr = tx_queue->write_ptr = 0;
3506  rx_queue->read_ptr = rx_queue->write_ptr = 0;
3507  ev_queue->read_ptr = 0;
3508 
3509  /* Push the event queue to the hardware */
3511  FCN_EVQ_EN, 1,
3512  FCN_EVQ_SIZE, FQS(FCN_EVQ, EFAB_EVQ_SIZE),
3513  FCN_EVQ_BUF_BASE_ID, ev_queue->entry.id );
3514  falcon_write ( efab, &reg,
3515  FCN_REVISION_REG ( efab, FCN_EVQ_PTR_TBL_KER ) );
3516 
3517  /* Push the tx queue to the hardware */
3519  FCN_TX_DESCQ_EN, 1,
3520  FCN_TX_ISCSI_DDIG_EN, 0,
3521  FCN_TX_ISCSI_DDIG_EN, 0,
3522  FCN_TX_DESCQ_BUF_BASE_ID, tx_queue->entry.id,
3523  FCN_TX_DESCQ_EVQ_ID, 0,
3524  FCN_TX_DESCQ_SIZE, FQS(FCN_TX_DESCQ, EFAB_TXD_SIZE),
3525  FCN_TX_DESCQ_TYPE, 0 /* kernel queue */,
3526  FCN_TX_NON_IP_DROP_DIS_B0, 1 );
3527  falcon_write ( efab, &reg,
3528  FCN_REVISION_REG ( efab, FCN_TX_DESC_PTR_TBL_KER ) );
3529 
3530  /* Push the rx queue to the hardware */
3531  jumbo = ( efab->pci_revision == FALCON_REV_B0 ) ? 0 : 1;
3533  FCN_RX_ISCSI_DDIG_EN, 0,
3534  FCN_RX_ISCSI_HDIG_EN, 0,
3535  FCN_RX_DESCQ_BUF_BASE_ID, rx_queue->entry.id,
3536  FCN_RX_DESCQ_EVQ_ID, 0,
3537  FCN_RX_DESCQ_SIZE, FQS(FCN_RX_DESCQ, EFAB_RXD_SIZE),
3538  FCN_RX_DESCQ_TYPE, 0 /* kernel queue */,
3539  FCN_RX_DESCQ_JUMBO, jumbo,
3540  FCN_RX_DESCQ_EN, 1 );
3541  falcon_write ( efab, &reg,
3542  FCN_REVISION_REG ( efab, FCN_RX_DESC_PTR_TBL_KER ) );
3543 
3544  /* Program INT_ADR_REG_KER */
3546  FCN_INT_ADR_KER, virt_to_bus ( &efab->int_ker ) );
3547  falcon_write ( efab, &reg, FCN_INT_ADR_REG_KER );
3548 
3549  /* Ack the event queue */
3550  falcon_eventq_read_ack ( efab, ev_queue );
3551 }
3552 
3553 static void
3555 {
3556  efab_oword_t cmd;
3557 
3558  /* Disable interrupts */
3559  falcon_interrupts ( efab, 0, 0 );
3560 
3561  /* Flush the dma queues */
3563  FCN_TX_FLUSH_DESCQ_CMD, 1,
3564  FCN_TX_FLUSH_DESCQ, 0 );
3565  falcon_write ( efab, &cmd,
3566  FCN_REVISION_REG ( efab, FCN_TX_DESC_PTR_TBL_KER ) );
3567 
3569  FCN_RX_FLUSH_DESCQ_CMD, 1,
3570  FCN_RX_FLUSH_DESCQ, 0 );
3571  falcon_write ( efab, &cmd,
3572  FCN_REVISION_REG ( efab, FCN_RX_DESC_PTR_TBL_KER ) );
3573 
3574  mdelay ( 100 );
3575 
3576  /* Remove descriptor rings from card */
3577  EFAB_ZERO_OWORD ( cmd );
3578  falcon_write ( efab, &cmd,
3579  FCN_REVISION_REG ( efab, FCN_TX_DESC_PTR_TBL_KER ) );
3580  falcon_write ( efab, &cmd,
3581  FCN_REVISION_REG ( efab, FCN_RX_DESC_PTR_TBL_KER ) );
3582  falcon_write ( efab, &cmd,
3583  FCN_REVISION_REG ( efab, FCN_EVQ_PTR_TBL_KER ) );
3584 }
3585 
3586 /*******************************************************************************
3587  *
3588  *
3589  * Hardware rx path
3590  *
3591  *
3592  *******************************************************************************/
3593 
3594 static void
3596 {
3598  FCN_RX_KER_BUF_SIZE, EFAB_RX_BUF_SIZE,
3599  FCN_RX_KER_BUF_ADR, virt_to_bus ( iob->data ) );
3600 }
3601 
3602 static void
3603 falcon_notify_rx_desc ( struct efab_nic *efab, struct efab_rx_queue *rx_queue )
3604 {
3605  efab_dword_t reg;
3606  int ptr = rx_queue->write_ptr % EFAB_RXD_SIZE;
3607 
3608  EFAB_POPULATE_DWORD_1 ( reg, FCN_RX_DESC_WPTR_DWORD, ptr );
3610 }
3611 
3612 
3613 /*******************************************************************************
3614  *
3615  *
3616  * Hardware tx path
3617  *
3618  *
3619  *******************************************************************************/
3620 
3621 static void
3623 {
3625  FCN_TX_KER_BYTE_CNT, iob_len ( iob ),
3626  FCN_TX_KER_BUF_ADR, virt_to_bus ( iob->data ) );
3627 }
3628 
3629 static void
3631  struct efab_tx_queue *tx_queue )
3632 {
3633  efab_dword_t reg;
3634  int ptr = tx_queue->write_ptr % EFAB_TXD_SIZE;
3635 
3636  EFAB_POPULATE_DWORD_1 ( reg, FCN_TX_DESC_WPTR_DWORD, ptr );
3638 }
3639 
3640 
3641 /*******************************************************************************
3642  *
3643  *
3644  * Software receive interface
3645  *
3646  *
3647  *******************************************************************************/
3648 
3649 static int
3651  struct efab_rx_queue *rx_queue )
3652 {
3653  int fill_level = rx_queue->write_ptr - rx_queue->read_ptr;
3654  int space = EFAB_NUM_RX_DESC - fill_level - 1;
3655  int pushed = 0;
3656 
3657  while ( space ) {
3658  int buf_id = rx_queue->write_ptr % EFAB_NUM_RX_DESC;
3659  int desc_id = rx_queue->write_ptr % EFAB_RXD_SIZE;
3660  struct io_buffer *iob;
3662 
3663  assert ( rx_queue->buf[buf_id] == NULL );
3664  iob = alloc_iob ( EFAB_RX_BUF_SIZE );
3665  if ( !iob )
3666  break;
3667 
3668  EFAB_TRACE ( "pushing rx_buf[%d] iob %p data %p\n",
3669  buf_id, iob, iob->data );
3670 
3671  rx_queue->buf[buf_id] = iob;
3672  rxd = rx_queue->ring + desc_id;
3673  falcon_build_rx_desc ( rxd, iob );
3674  ++rx_queue->write_ptr;
3675  ++pushed;
3676  --space;
3677  }
3678 
3679  if ( pushed ) {
3680  /* Push the ptr to hardware */
3681  falcon_notify_rx_desc ( efab, rx_queue );
3682 
3683  fill_level = rx_queue->write_ptr - rx_queue->read_ptr;
3684  EFAB_TRACE ( "pushed %d rx buffers to fill level %d\n",
3685  pushed, fill_level );
3686  }
3687 
3688  if ( fill_level == 0 )
3689  return -ENOMEM;
3690  return 0;
3691 }
3692 
3693 static void
3694 efab_receive ( struct efab_nic *efab, unsigned int id, int len, int drop )
3695 {
3696  struct efab_rx_queue *rx_queue = &efab->rx_queue;
3697  struct io_buffer *iob;
3698  unsigned int read_ptr = rx_queue->read_ptr % EFAB_RXD_SIZE;
3699  unsigned int buf_ptr = rx_queue->read_ptr % EFAB_NUM_RX_DESC;
3700 
3701  assert ( id == read_ptr );
3702 
3703  /* Pop this rx buffer out of the software ring */
3704  iob = rx_queue->buf[buf_ptr];
3705  rx_queue->buf[buf_ptr] = NULL;
3706 
3707  EFAB_TRACE ( "popping rx_buf[%d] iob %p data %p with %d bytes %s\n",
3708  id, iob, iob->data, len, drop ? "bad" : "ok" );
3709 
3710  /* Pass the packet up if required */
3711  if ( drop )
3712  free_iob ( iob );
3713  else {
3714  iob_put ( iob, len );
3715  netdev_rx ( efab->netdev, iob );
3716  }
3717 
3718  ++rx_queue->read_ptr;
3719 }
3720 
3721 /*******************************************************************************
3722  *
3723  *
3724  * Software transmit interface
3725  *
3726  *
3727  *******************************************************************************/
3728 
3729 static int
3730 efab_transmit ( struct net_device *netdev, struct io_buffer *iob )
3731 {
3732  struct efab_nic *efab = netdev->priv;
3733  struct efab_tx_queue *tx_queue = &efab->tx_queue;
3734  int fill_level, space;
3736  int buf_id;
3737 
3738  fill_level = tx_queue->write_ptr - tx_queue->read_ptr;
3739  space = EFAB_TXD_SIZE - fill_level - 1;
3740  if ( space < 1 )
3741  return -ENOBUFS;
3742 
3743  /* Save the iobuffer for later completion */
3744  buf_id = tx_queue->write_ptr % EFAB_TXD_SIZE;
3745  assert ( tx_queue->buf[buf_id] == NULL );
3746  tx_queue->buf[buf_id] = iob;
3747 
3748  EFAB_TRACE ( "tx_buf[%d] for iob %p data %p len %zd\n",
3749  buf_id, iob, iob->data, iob_len ( iob ) );
3750 
3751  /* Form the descriptor, and push it to hardware */
3752  txd = tx_queue->ring + buf_id;
3753  falcon_build_tx_desc ( txd, iob );
3754  ++tx_queue->write_ptr;
3755  falcon_notify_tx_desc ( efab, tx_queue );
3756 
3757  return 0;
3758 }
3759 
3760 static int
3761 efab_transmit_done ( struct efab_nic *efab, int id )
3762 {
3763  struct efab_tx_queue *tx_queue = &efab->tx_queue;
3764  unsigned int read_ptr, stop;
3765 
3766  /* Complete all buffers from read_ptr up to and including id */
3767  read_ptr = tx_queue->read_ptr % EFAB_TXD_SIZE;
3768  stop = ( id + 1 ) % EFAB_TXD_SIZE;
3769 
3770  while ( read_ptr != stop ) {
3771  struct io_buffer *iob = tx_queue->buf[read_ptr];
3772  assert ( iob );
3773 
3774  /* Complete the tx buffer */
3775  if ( iob )
3776  netdev_tx_complete ( efab->netdev, iob );
3777  tx_queue->buf[read_ptr] = NULL;
3778 
3779  ++tx_queue->read_ptr;
3780  read_ptr = tx_queue->read_ptr % EFAB_TXD_SIZE;
3781  }
3782 
3783  return 0;
3784 }
3785 
3786 /*******************************************************************************
3787  *
3788  *
3789  * Hardware event path
3790  *
3791  *
3792  *******************************************************************************/
3793 
3794 static void
3796 {
3797  efab_dword_t reg;
3798 
3799  if ( efab->pci_revision == FALCON_REV_B0 ) {
3800  /* read the ISR */
3801  falcon_readl( efab, &reg, INT_ISR0_B0 );
3802  }
3803  else {
3804  /* write to the INT_ACK register */
3805  EFAB_ZERO_DWORD ( reg );
3807  mb();
3808  falcon_readl ( efab, &reg,
3810  }
3811 }
3812 
3813 static void
3815 {
3816  int ev_code, desc_ptr, len, drop;
3817 
3818  /* Decode event */
3819  ev_code = EFAB_QWORD_FIELD ( *evt, FCN_EV_CODE );
3820  switch ( ev_code ) {
3821  case FCN_TX_IP_EV_DECODE:
3822  desc_ptr = EFAB_QWORD_FIELD ( *evt, FCN_TX_EV_DESC_PTR );
3823  efab_transmit_done ( efab, desc_ptr );
3824  break;
3825 
3826  case FCN_RX_IP_EV_DECODE:
3827  desc_ptr = EFAB_QWORD_FIELD ( *evt, FCN_RX_EV_DESC_PTR );
3828  len = EFAB_QWORD_FIELD ( *evt, FCN_RX_EV_BYTE_CNT );
3829  drop = !EFAB_QWORD_FIELD ( *evt, FCN_RX_EV_PKT_OK );
3830 
3831  efab_receive ( efab, desc_ptr, len, drop );
3832  break;
3833 
3834  default:
3835  EFAB_TRACE ( "Unknown event type %d\n", ev_code );
3836  break;
3837  }
3838 }
3839 
3840 /*******************************************************************************
3841  *
3842  *
3843  * Software (polling) interrupt handler
3844  *
3845  *
3846  *******************************************************************************/
3847 
3848 static void
3850 {
3851  struct efab_nic *efab = netdev->priv;
3852  struct efab_ev_queue *ev_queue = &efab->ev_queue;
3853  struct efab_rx_queue *rx_queue = &efab->rx_queue;
3854  falcon_event_t *evt;
3855 
3856  /* Read the event queue by directly looking for events
3857  * (we don't even bother to read the eventq write ptr) */
3858  evt = ev_queue->ring + ev_queue->read_ptr;
3859  while ( falcon_event_present ( evt ) ) {
3860 
3861  EFAB_TRACE ( "Event at index 0x%x address %p is "
3862  EFAB_QWORD_FMT "\n", ev_queue->read_ptr,
3863  evt, EFAB_QWORD_VAL ( *evt ) );
3864 
3865  falcon_handle_event ( efab, evt );
3866 
3867  /* Clear the event */
3868  EFAB_SET_QWORD ( *evt );
3869 
3870  /* Move to the next event. We don't ack the event
3871  * queue until the end */
3872  ev_queue->read_ptr = ( ( ev_queue->read_ptr + 1 ) %
3873  EFAB_EVQ_SIZE );
3874  evt = ev_queue->ring + ev_queue->read_ptr;
3875  }
3876 
3877  /* Push more buffers if needed */
3878  (void) efab_fill_rx_queue ( efab, rx_queue );
3879 
3880  /* Clear any pending interrupts */
3881  falcon_clear_interrupts ( efab );
3882 
3883  /* Ack the event queue */
3884  falcon_eventq_read_ack ( efab, ev_queue );
3885 }
3886 
3887 static void
3888 efab_irq ( struct net_device *netdev, int enable )
3889 {
3890  struct efab_nic *efab = netdev->priv;
3891  struct efab_ev_queue *ev_queue = &efab->ev_queue;
3892 
3893  switch ( enable ) {
3894  case 0:
3895  falcon_interrupts ( efab, 0, 0 );
3896  break;
3897  case 1:
3898  falcon_interrupts ( efab, 1, 0 );
3899  falcon_eventq_read_ack ( efab, ev_queue );
3900  break;
3901  case 2:
3902  falcon_interrupts ( efab, 1, 1 );
3903  break;
3904  }
3905 }
3906 
3907 /*******************************************************************************
3908  *
3909  *
3910  * Software open/close
3911  *
3912  *
3913  *******************************************************************************/
3914 
3915 static void
3917 {
3918  struct efab_ev_queue *ev_queue = &efab->ev_queue;
3919  struct efab_rx_queue *rx_queue = &efab->rx_queue;
3920  struct efab_tx_queue *tx_queue = &efab->tx_queue;
3921  int i;
3922 
3923  for ( i = 0; i < EFAB_NUM_RX_DESC; i++ ) {
3924  if ( rx_queue->buf[i] )
3925  free_iob ( rx_queue->buf[i] );
3926  }
3927 
3928  for ( i = 0; i < EFAB_TXD_SIZE; i++ ) {
3929  if ( tx_queue->buf[i] )
3930  netdev_tx_complete ( efab->netdev, tx_queue->buf[i] );
3931  }
3932 
3933  if ( rx_queue->ring )
3934  falcon_free_special_buffer ( rx_queue->ring );
3935 
3936  if ( tx_queue->ring )
3937  falcon_free_special_buffer ( tx_queue->ring );
3938 
3939  if ( ev_queue->ring )
3940  falcon_free_special_buffer ( ev_queue->ring );
3941 
3942  memset ( rx_queue, 0, sizeof ( *rx_queue ) );
3943  memset ( tx_queue, 0, sizeof ( *tx_queue ) );
3944  memset ( ev_queue, 0, sizeof ( *ev_queue ) );
3945 
3946  /* Ensure subsequent buffer allocations start at id 0 */
3947  efab->buffer_head = 0;
3948 }
3949 
3950 static int
3952 {
3953  struct efab_ev_queue *ev_queue = &efab->ev_queue;
3954  struct efab_rx_queue *rx_queue = &efab->rx_queue;
3955  struct efab_tx_queue *tx_queue = &efab->tx_queue;
3956  size_t bytes;
3957 
3958  /* Allocate the hardware event queue */
3959  bytes = sizeof ( falcon_event_t ) * EFAB_TXD_SIZE;
3960  ev_queue->ring = falcon_alloc_special_buffer ( efab, bytes,
3961  &ev_queue->entry );
3962  if ( !ev_queue->ring )
3963  goto fail1;
3964 
3965  /* Initialise the hardware event queue */
3966  memset ( ev_queue->ring, 0xff, bytes );
3967 
3968  /* Allocate the hardware tx queue */
3969  bytes = sizeof ( falcon_tx_desc_t ) * EFAB_TXD_SIZE;
3970  tx_queue->ring = falcon_alloc_special_buffer ( efab, bytes,
3971  &tx_queue->entry );
3972  if ( ! tx_queue->ring )
3973  goto fail2;
3974 
3975  /* Allocate the hardware rx queue */
3976  bytes = sizeof ( falcon_rx_desc_t ) * EFAB_RXD_SIZE;
3977  rx_queue->ring = falcon_alloc_special_buffer ( efab, bytes,
3978  &rx_queue->entry );
3979  if ( ! rx_queue->ring )
3980  goto fail3;
3981 
3982  return 0;
3983 
3984 fail3:
3985  falcon_free_special_buffer ( tx_queue->ring );
3986  tx_queue->ring = NULL;
3987 fail2:
3988  falcon_free_special_buffer ( ev_queue->ring );
3989  ev_queue->ring = NULL;
3990 fail1:
3991  return -ENOMEM;
3992 }
3993 
3994 static int
3995 efab_init_mac ( struct efab_nic *efab )
3996 {
3997  int count, rc;
3998 
3999  /* This can take several seconds */
4000  EFAB_LOG ( "Waiting for link..\n" );
4001  for ( count=0; count<5; count++ ) {
4002  rc = efab->mac_op->init ( efab );
4003  if ( rc ) {
4004  EFAB_ERR ( "Failed reinitialising MAC, error %s\n",
4005  strerror ( rc ));
4006  return rc;
4007  }
4008 
4009  /* Sleep for 2s to wait for the link to settle, either
4010  * because we want to use it, or because we're about
4011  * to reset the mac anyway
4012  */
4013  mdelay ( 2000 );
4014 
4015  if ( ! efab->link_up ) {
4016  EFAB_ERR ( "!\n" );
4017  continue;
4018  }
4019 
4020  EFAB_LOG ( "\n%dMbps %s-duplex\n",
4021  ( efab->link_options & LPA_EF_10000 ? 10000 :
4022  ( efab->link_options & LPA_EF_1000 ? 1000 :
4023  ( efab->link_options & LPA_100 ? 100 : 10 ) ) ),
4024  ( efab->link_options & LPA_EF_DUPLEX ?
4025  "full" : "half" ) );
4026 
4027  /* TODO: Move link state handling to the poll() routine */
4028  netdev_link_up ( efab->netdev );
4029  return 0;
4030  }
4031 
4032  EFAB_ERR ( "timed initialising MAC\n" );
4033  return -ETIMEDOUT;
4034 }
4035 
4036 static void
4038 {
4039  struct efab_nic *efab = netdev->priv;
4040 
4041  falcon_fini_resources ( efab );
4042  efab_free_resources ( efab );
4043  efab->board_op->fini ( efab );
4044  falcon_reset ( efab );
4045 }
4046 
4047 static int
4049 {
4050  struct efab_nic *efab = netdev->priv;
4051  struct efab_rx_queue *rx_queue = &efab->rx_queue;
4052  int rc;
4053 
4054  rc = falcon_reset ( efab );
4055  if ( rc )
4056  goto fail1;
4057 
4058  rc = efab->board_op->init ( efab );
4059  if ( rc )
4060  goto fail2;
4061 
4062  rc = falcon_init_sram ( efab );
4063  if ( rc )
4064  goto fail3;
4065 
4066  /* Configure descriptor caches before pushing hardware queues */
4067  falcon_setup_nic ( efab );
4068 
4069  rc = efab_alloc_resources ( efab );
4070  if ( rc )
4071  goto fail4;
4072 
4073  falcon_init_resources ( efab );
4074 
4075  /* Push rx buffers */
4076  rc = efab_fill_rx_queue ( efab, rx_queue );
4077  if ( rc )
4078  goto fail5;
4079 
4080  /* Try and bring the interface up */
4081  rc = efab_init_mac ( efab );
4082  if ( rc )
4083  goto fail6;
4084 
4085  return 0;
4086 
4087 fail6:
4088 fail5:
4089  efab_free_resources ( efab );
4090 fail4:
4091 fail3:
4092  efab->board_op->fini ( efab );
4093 fail2:
4094  falcon_reset ( efab );
4095 fail1:
4096  return rc;
4097 }
4098 
4100  .open = efab_open,
4101  .close = efab_close,
4102  .transmit = efab_transmit,
4103  .poll = efab_poll,
4104  .irq = efab_irq,
4105 };
4106 
4107 static void
4108 efab_remove ( struct pci_device *pci )
4109 {
4110  struct net_device *netdev = pci_get_drvdata ( pci );
4111  struct efab_nic *efab = netdev->priv;
4112 
4113  if ( efab->membase ) {
4114  falcon_reset ( efab );
4115 
4116  iounmap ( efab->membase );
4117  efab->membase = NULL;
4118  }
4119 
4120  if ( efab->nvo.nvs ) {
4121  unregister_nvo ( &efab->nvo );
4122  efab->nvo.nvs = NULL;
4123  }
4124 
4126  netdev_nullify ( netdev );
4127  netdev_put ( netdev );
4128 }
4129 
4130 static int
4131 efab_probe ( struct pci_device *pci )
4132 {
4133  struct net_device *netdev;
4134  struct efab_nic *efab;
4135  unsigned long mmio_start, mmio_len;
4136  int rc;
4137 
4138  /* Create the network adapter */
4139  netdev = alloc_etherdev ( sizeof ( struct efab_nic ) );
4140  if ( ! netdev ) {
4141  rc = -ENOMEM;
4142  goto fail1;
4143  }
4144 
4145  /* Initialise the network adapter, and initialise private storage */
4147  pci_set_drvdata ( pci, netdev );
4148  netdev->dev = &pci->dev;
4149 
4150  efab = netdev->priv;
4151  memset ( efab, 0, sizeof ( *efab ) );
4152  efab->netdev = netdev;
4153 
4154  /* Get iobase/membase */
4155  mmio_start = pci_bar_start ( pci, PCI_BASE_ADDRESS_2 );
4156  mmio_len = pci_bar_size ( pci, PCI_BASE_ADDRESS_2 );
4157  efab->membase = pci_ioremap ( pci, mmio_start, mmio_len );
4158  EFAB_TRACE ( "BAR of %lx bytes at phys %lx mapped at %p\n",
4159  mmio_len, mmio_start, efab->membase );
4160 
4161  /* Enable the PCI device */
4162  adjust_pci_device ( pci );
4163  efab->iobase = pci->ioaddr & ~3;
4164 
4165  /* Determine the NIC variant */
4166  falcon_probe_nic_variant ( efab, pci );
4167 
4168  /* Read the SPI interface and determine the MAC address,
4169  * and the board and phy variant. Hook in the op tables */
4170  rc = falcon_probe_spi ( efab );
4171  if ( rc )
4172  goto fail2;
4173  rc = falcon_probe_nvram ( efab );
4174  if ( rc )
4175  goto fail3;
4176 
4177  memcpy ( netdev->hw_addr, efab->mac_addr, ETH_ALEN );
4178 
4179  rc = register_netdev ( netdev );
4180  if ( rc )
4181  goto fail4;
4182  netdev_link_up ( netdev );
4183 
4184  /* Advertise non-volatile storage */
4185  if ( efab->nvo.nvs ) {
4186  rc = register_nvo ( &efab->nvo, netdev_settings ( netdev ) );
4187  if ( rc )
4188  goto fail5;
4189  }
4190 
4191  EFAB_LOG ( "Found %s EtherFabric %s %s revision %d\n", pci->id->name,
4192  efab->is_asic ? "ASIC" : "FPGA",
4193  efab->phy_10g ? "10G" : "1G",
4194  efab->pci_revision );
4195 
4196  return 0;
4197 
4198 fail5:
4200 fail4:
4201 fail3:
4202 fail2:
4203  iounmap ( efab->membase );
4204  efab->membase = NULL;
4205  netdev_put ( netdev );
4206 fail1:
4207  return rc;
4208 }
4209 
4210 
4211 static struct pci_device_id efab_nics[] = {
4212  PCI_ROM(0x1924, 0x0703, "falcon", "EtherFabric Falcon", 0),
4213  PCI_ROM(0x1924, 0x0710, "falconb0", "EtherFabric FalconB0", 0),
4214 };
4215 
4216 struct pci_driver etherfabric_driver __pci_driver = {
4217  .ids = efab_nics,
4218  .id_count = sizeof ( efab_nics ) / sizeof ( efab_nics[0] ),
4219  .probe = efab_probe,
4220  .remove = efab_remove,
4221 };
4222 
4223 /*
4224  * Local variables:
4225  * c-basic-offset: 8
4226  * c-indent-level: 8
4227  * tab-width: 8
4228  * End:
4229  */
#define FCN_RX_CFG_REG_KER
Definition: etherfabric.c:653
struct nvo_block nvo
#define XX_TXDRV_DEQ_DEFAULT
Definition: etherfabric.c:805
#define FCN_XX_SD_CTL_REG_MAC
Definition: etherfabric.c:959
static void falcon_reconfigure_mac_wrapper(struct efab_nic *efab)
Definition: etherfabric.c:1717
#define MII_ADVERTISE
Definition: atl1e.h:875
#define LPA_PAUSE_CAP
Definition: mii.h:106
#define P1_IN
Definition: etherfabric.c:2813
#define LPA_10HALF
Definition: mii.h:97
#define __attribute__(x)
Definition: compiler.h:10
static void efab_free_resources(struct efab_nic *efab)
Definition: etherfabric.c:3916
#define FCN_SRM_CFG_REG_KER
Definition: etherfabric.c:639
#define EINVAL
Invalid argument.
Definition: errno.h:428
static void falcon_readl(struct efab_nic *efab, efab_dword_t *value, unsigned int reg)
Read dword from a portion of a Falcon register.
Definition: etherfabric.c:1285
#define MII_LPA
Definition: atl1e.h:876
#define P0_EN_3V3X_LBN
Definition: etherfabric.c:2806
#define FCN_DUMP_MAC_REG(efab, _mac_reg)
Definition: etherfabric.c:1299
union falcon_nv_extra::@48 ver_specific
iPXE I/O API
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static unsigned int gmii_autoneg_lpa(struct efab_nic *efab)
Retrieve GMII autonegotiation link partner abilities.
Definition: etherfabric.c:131
unsigned short uint16_t
Definition: stdint.h:11
#define FCN_MD_TXD_REG_KER
Definition: etherfabric.c:745
static void netdev_tx_complete(struct net_device *netdev, struct io_buffer *iobuf)
Complete network transmission.
Definition: netdevice.h:766
#define FCN_TX_IP_EV_DECODE
Definition: etherfabric.c:1138
struct efab_special_buffer entry
wmb()
static void falcon_xmac_readl(struct efab_nic *efab, efab_dword_t *value, unsigned int mac_reg)
Read dword from a Falcon XMAC register.
Definition: etherfabric.c:2081
static int sfe4003_init(struct efab_nic *efab)
Definition: etherfabric.c:3006
#define TXC_ALRGS_ATXAMP0
Definition: etherfabric.c:2493
static int falcon_reset_xaui(struct efab_nic *efab)
Definition: etherfabric.c:2187
#define MDIO_MMD_DTEXS
Definition: etherfabric.c:212
#define FALCON_SPI_MAX_LEN
Maximum length for a single SPI transaction.
Definition: etherfabric.c:1398
#define iob_put(iobuf, len)
Definition: iobuf.h:124
struct efab_ev_queue ev_queue
#define FCN_EE_VPD_CFG_REG
Definition: etherfabric.c:490
#define MDIO45_RESET_TRIES
Definition: etherfabric.c:262
#define FCN_XX_PWR_RST_REG_MAC
Definition: etherfabric.c:929
int(* rw)(struct spi_bus *bus, struct spi_device *device, unsigned int command, int address, const void *data_out, void *data_in, size_t len)
Read/write data via SPI bus.
Definition: spi.h:152
#define EFAB_DWORD_IS_ALL_ONES(dword)
Definition: etherfabric.h:263
#define FALCON_MAC_ADDRESS_OFFSET
Offset of MAC address within EEPROM or Flash.
Definition: etherfabric.c:3145
#define TXC_ALRGS_ATXPRE1
Definition: etherfabric.c:2515
static int falcon_spi_wait(struct efab_nic *efab)
Definition: etherfabric.c:1401
A PCI driver.
Definition: pci.h:251
#define FCN_EE_SPI_HADR_REG
Definition: etherfabric.c:472
static struct efab_mac_operations falcon_gmac_operations
Definition: etherfabric.c:2047
uint8_t mac_addr[ETH_ALEN]
MAC address.
#define FCN_RX_DESC_UPD_REG_KER_DWORD
Definition: etherfabric.c:702
static int falcon_tenxpress_check_c11(struct efab_nic *efab)
Definition: etherfabric.c:2645
uint16_t structure_version
Definition: etherfabric.c:3166
#define EFAB_OWORD_FIELD
Definition: etherfabric.h:274
static unsigned int unsigned int reg
Definition: myson.h:162
#define TXC_ALRGS_ATXAMP1
Definition: etherfabric.c:2494
__be32 in[4]
Definition: CIB_PRM.h:35
void __asmcall int val
Definition: setjmp.h:12
int(* write)(struct i2c_interface *i2c, struct i2c_device *i2cdev, unsigned int offset, const uint8_t *data, unsigned int len)
Write data to I2C device.
Definition: i2c.h:81
uint32_t stat
Completion status.
Definition: dwmac.h:12
#define PMC_MCONF2_REDGE
Definition: etherfabric.c:2727
int(* open)(struct net_device *netdev)
Open network device.
Definition: netdevice.h:222
struct efab_special_buffer entry
#define INT_ISR0_B0
Definition: etherfabric.c:432
#define P0_CONFIG
Definition: etherfabric.c:2798
#define EFAB_POPULATE_DWORD_5(dword,...)
Definition: etherfabric.h:449
static struct efab_phy_operations falcon_xaui_phy_ops
Definition: etherfabric.c:2406
#define PMC_ANALOG_RX_CFG0
Definition: etherfabric.c:2730
uint16_t device_id
Definition: ib_mad.h:19
A quadword (i.e.
Definition: etherfabric.h:111
#define FCN_RX_IP_EV_DECODE
Definition: etherfabric.c:1137
#define FCN_XM_ADR_HI_REG_MAC
Definition: etherfabric.c:831
#define FCN_XM_RX_PARAM_REG_MAC
Definition: etherfabric.c:898
unsigned long ioaddr
I/O address.
Definition: pci.h:225
#define FCN_IP_DAT_BUF_SIZE_4K
Definition: etherfabric.c:1100
static int falcon_pm8358_phy_init(struct efab_nic *efab)
Definition: etherfabric.c:2745
Error codes.
#define MAX_TEMP_THRESH
Definition: etherfabric.c:2791
Bit-bashing operations.
Definition: bitbash.h:15
static unsigned int gmii_autoneg_advertised(struct efab_nic *efab)
Retrieve GMII autonegotiation advertised abilities.
Definition: etherfabric.c:114
#define FCN_XX_CHARERR_RESET
Definition: etherfabric.c:923
static void efab_poll(struct net_device *netdev)
Definition: etherfabric.c:3849
#define EFAB_RX_BUF_SIZE
A command-line command.
Definition: command.h:9
#define MDIO_MMDREG_DEVS0_DTEXS
Definition: etherfabric.c:240
unsigned int iobase
#define FCN_XM_RX_CFG_REG_MAC
Definition: etherfabric.c:864
I/O buffers.
static int gmii_link_ok(struct efab_nic *efab)
Check GMII PHY link status.
Definition: etherfabric.c:174
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:152
A non-volatile storage device.
Definition: nvs.h:15
#define FCN_DUMP_REG(efab, _reg)
Definition: etherfabric.c:1292
struct pci_device_id * ids
PCI ID table.
Definition: pci.h:253
#define FCN_SRM_RX_DC_CFG_REG_KER
Definition: etherfabric.c:629
#define TXC_ATXAMP_0820_BOTH
Definition: etherfabric.c:2508
uint64_t address
Base address.
Definition: ena.h:24
int register_nvo(struct nvo_block *nvo, struct settings *parent)
Register non-volatile stored options.
Definition: nvo.c:293
#define FCN_EE_SPI_READ
Definition: etherfabric.c:462
#define FCN_XM_MGT_INT_REG_MAC_B0
Definition: etherfabric.c:903
#define EFAB_REGDUMP(...)
Definition: etherfabric.c:47
#define TXC_GLRGS_GLCMD
Definition: etherfabric.c:2489
#define XFP_REQUIRED_DEVS
Definition: etherfabric.c:2455
An SPI bus.
Definition: spi.h:126
static void mentormac_reset(struct efab_nic *efab)
Definition: etherfabric.c:1903
#define FALCON_REV_B0
Definition: etherfabric.c:532
#define XX_SD_CTL_DRV_DEFAULT
Definition: etherfabric.c:807
unsigned long pci_bar_size(struct pci_device *pci, unsigned int reg)
Get the size of a PCI BAR.
Definition: pci.c:163
#define XX_TXDRV_DTX_DEFAULT
Definition: etherfabric.c:806
#define PCA9539
Definition: etherfabric.c:2794
static void falcon_notify_rx_desc(struct efab_nic *efab, struct efab_rx_queue *rx_queue)
Definition: etherfabric.c:3603
#define EFAB_SET_OWORD_FIELD_VER(efab, reg, field, val)
Definition: etherfabric.c:1166
#define PMC_MCONF2_REG
Definition: etherfabric.c:2723
long index
Definition: bigint.h:62
struct efab_phy_operations * phy_op
static void falcon_write(struct efab_nic *efab, efab_oword_t *value, unsigned int reg)
Write to a Falcon register.
Definition: etherfabric.c:1201
struct net_device * netdev
#define LPA_OTHER
Definition: etherfabric.c:103
efab_qword_t falcon_rx_desc_t
#define EFAB_POPULATE_DWORD_3(dword,...)
Definition: etherfabric.h:453
#define FCN_XM_MGT_INT_MSK_REG_MAC_B0
Definition: etherfabric.c:873
#define P0_EN_1V0X_LBN
Definition: etherfabric.c:2800
static struct i2c_device i2c_pca9539
Definition: etherfabric.c:2830
#define EFAB_SET_OWORD_FIELD
Definition: etherfabric.h:531
unsigned int write_ptr
#define FCN_XX_SYNC_STAT_DECODE_SYNCED
Definition: etherfabric.c:917
#define MAX6647
Definition: etherfabric.c:2824
static void falcon_reconfigure_xmac(struct efab_nic *efab)
Initialise XMAC.
Definition: etherfabric.c:2258
#define FCN_EE_SPI_FLASH
Definition: etherfabric.c:457
iPXE timers
static void falcon_build_tx_desc(falcon_tx_desc_t *txd, struct io_buffer *iob)
Definition: etherfabric.c:3622
unsigned int write_ptr
A doubleword (i.e.
Definition: etherfabric.h:102
#define PCS_BOOT_STATUS_REG
Definition: etherfabric.c:2634
#define FCN_MD_STAT_REG_KER
Definition: etherfabric.c:778
An I2C interface.
Definition: i2c.h:57
uint32_t buffer
Buffer index (or NETVSC_RNDIS_NO_BUFFER)
Definition: netvsc.h:16
unsigned int dev_addr
Address of this device.
Definition: i2c.h:31
#define LPA_100HALF
Definition: mii.h:101
struct io_buffer * buf[EFAB_TXD_SIZE]
#define EFAB_SET_DWORD_FIELD(dword, field, value)
Definition: etherfabric.h:521
#define PM8358_REQUIRED_DEVS
Definition: etherfabric.c:2714
static struct efab_phy_operations falcon_alaska_phy_ops
Definition: etherfabric.c:2443
static struct efab_mac_operations falcon_xmac_operations
Definition: etherfabric.c:2384
#define FCN_INT_EN_REG_KER
Definition: etherfabric.c:412
#define GM_MAX_FLEN_REG_MAC
Definition: etherfabric.c:1774
#define LPA_EF_1000HALF
Definition: etherfabric.c:93
#define FCN_TIMER_CMD_REG_KER
Definition: etherfabric.c:615
static void * falcon_alloc_special_buffer(struct efab_nic *efab, int bytes, struct efab_special_buffer *entry)
Definition: etherfabric.c:3036
static void falcon_init_spi_device(struct efab_nic *efab, struct spi_device *spi)
Definition: etherfabric.c:3206
#define LPA_EF_1000
Definition: etherfabric.c:97
static int alaska_init(struct efab_nic *efab)
Initialise Alaska PHY.
Definition: etherfabric.c:2425
void adjust_pci_device(struct pci_device *pci)
Enable PCI device.
Definition: pci.c:240
static struct efab_phy_operations falcon_pm8358_phy_ops
Definition: etherfabric.c:2778
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:130
#define EFAB_RXD_SIZE
#define EFAB_DWORD_VAL(dword)
printk parameters for printing an efab_dword_t
Definition: etherfabric.h:139
__be32 out[4]
Definition: CIB_PRM.h:36
uint16_t checksum
Definition: etherfabric.c:3167
static void falcon_clear_interrupts(struct efab_nic *efab)
Definition: etherfabric.c:3795
#define LPA_EF_1000FULL
Definition: etherfabric.c:92
struct device dev
Generic device.
Definition: pci.h:212
static struct settings * netdev_settings(struct net_device *netdev)
Get per-netdevice configuration settings block.
Definition: netdevice.h:586
unsigned int read_ptr
uint16_t enabled
Single-entry bitmask of the enabled option value.
Definition: ena.h:14
#define EFAB_QWORD_FIELD
Definition: etherfabric.h:275
static struct efab_phy_operations falcon_tenxpress_phy_ops
Definition: etherfabric.c:2700
#define EFAB_BYTE
Definition: etherfabric.c:57
#define FCN_MAC1_CTRL_REG_KER
Definition: etherfabric.c:792
static void efab_receive(struct efab_nic *efab, unsigned int id, int len, int drop)
Definition: etherfabric.c:3694
#define EFAB_POPULATE_DWORD_7(dword,...)
Definition: etherfabric.h:445
efab_oword_t int_ker
INT_REG_KER.
Dynamic memory allocation.
#define EFAB_POPULATE_OWORD_2(oword,...)
Definition: etherfabric.h:399
static void falcon_writel(struct efab_nic *efab, efab_dword_t *value, unsigned int reg)
Write dword to Falcon register that allows partial writes.
Definition: etherfabric.c:1239
device address_len
Definition: threewire.h:73
static void falcon_gmac_writel(struct efab_nic *efab, efab_dword_t *value, unsigned int mac_reg)
Definition: etherfabric.c:1881
static void falcon_notify_tx_desc(struct efab_nic *efab, struct efab_tx_queue *tx_queue)
Definition: etherfabric.c:3630
struct efab_tx_queue tx_queue
static void netdev_init(struct net_device *netdev, struct net_device_operations *op)
Initialise a network device.
Definition: netdevice.h:518
struct spi_device spi_eeprom
#define FCN_XX_TXDRV_CTL_REG_MAC
Definition: etherfabric.c:989
int(* init)(struct efab_nic *efab)
#define FCN_GLB_CTL_REG_KER
Definition: etherfabric.c:576
#define FQS(_prefix, _x)
Definition: etherfabric.c:66
#define FCN_TX_CFG2_REG_KER
Definition: etherfabric.c:727
#define FCN_XM_GLB_CFG_REG_MAC
Definition: etherfabric.c:838
static void falcon_read(struct efab_nic *efab, efab_oword_t *value, unsigned int reg)
Read from a Falcon register.
Definition: etherfabric.c:1251
static struct pci_device_id efab_nics[]
Definition: etherfabric.c:4211
static void pci_set_drvdata(struct pci_device *pci, void *priv)
Set PCI driver-private data.
Definition: pci.h:365
#define PMC_MASTER_REG
Definition: etherfabric.c:2718
#define EFAB_QWORD_FMT
Format string for printing an efab_qword_t.
Definition: etherfabric.h:133
#define ENOMEM
Not enough space.
Definition: errno.h:534
A hardware device.
Definition: device.h:76
static void efab_close(struct net_device *netdev)
Definition: etherfabric.c:4037
static void falcon_mdio_write(struct efab_nic *efab, int device, int location, int value)
Definition: etherfabric.c:1591
#define RLHN
Definition: etherfabric.c:2827
void * memcpy(void *dest, const void *src, size_t len) __nonnull
#define FCN_NV_MAGIC_NUMBER
Definition: etherfabric.c:573
#define TXC_ATXPRE_DEFAULT
Definition: etherfabric.c:2518
falcon_rx_desc_t * ring
#define LPA_100FULL
Definition: mii.h:103
#define FCN_EE_SPI_HDATA_REG
Definition: etherfabric.c:479
static int falcon_txc_logic_reset(struct efab_nic *efab)
Definition: etherfabric.c:2525
static int falcon_mdio_read(struct efab_nic *efab, int device, int location)
Definition: etherfabric.c:1645
uint32_t minor
Minor version.
Definition: netvsc.h:16
#define MDIO_MMDREG_STAT2
Definition: etherfabric.c:222
static __always_inline unsigned long virt_to_bus(volatile const void *addr)
Convert virtual address to a bus address.
Definition: io.h:183
#define FCN_RX_FILTER_TBL0
Definition: etherfabric.c:1008
Etherfabric bitfield access.
#define EFAB_ZERO_DWORD(dword)
Definition: etherfabric.h:459
static int falcon_i2c_bit_read(struct bit_basher *basher, unsigned int bit_id)
Definition: etherfabric.c:1528
#define MDIO_MMDREG_CTRL1
Definition: etherfabric.c:219
#define P0_X_TRST_LBN
Definition: etherfabric.c:2810
unsigned int block_size
Data block size (in words)
Definition: nvs.h:36
Assertions.
#define EFAB_MAX_FRAME_LEN(mtu)
Definition: etherfabric.c:74
#define MDIO_PHYXS_LANE_STATE
Definition: etherfabric.c:254
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:575
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
int sync(unsigned long timeout)
Wait for pending operations to complete.
Definition: sync.c:73
#define LPA_10FULL
Definition: mii.h:99
static void falcon_interrupts(struct efab_nic *efab, int enabled, int force)
Definition: etherfabric.c:1378
Ethernet protocol.
static struct efab_phy_operations falcon_txc_phy_ops
Definition: etherfabric.c:2604
#define FCN_MD_CS_REG_KER
Definition: etherfabric.c:755
static int mdio_clause45_reset_mmd(struct efab_nic *efab, int mmd)
Definition: etherfabric.c:305
#define GMF_CFG5_REG_MAC
Definition: etherfabric.c:1870
#define FCN_RX_SELF_RST_REG_KER
Definition: etherfabric.c:711
#define EFAB_OWORD_VAL(oword)
printk parameters for printing an efab_oword_t
Definition: etherfabric.h:148
#define ETH_FRAME_LEN
Definition: if_ether.h:11
struct i2c_interface i2c
I2C interface.
Definition: i2c.h:93
void * priv
Driver private data.
Definition: netdevice.h:431
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
#define MDIO_MMD_PHYXS
Definition: etherfabric.c:210
static int falcon_spi_rw(struct spi_bus *bus, struct spi_device *device, unsigned int command, int address, const void *data_out, void *data_in, size_t len)
Definition: etherfabric.c:1419
#define EFAB_POPULATE_OWORD_7(oword,...)
Definition: etherfabric.h:389
static void netdev_link_up(struct net_device *netdev)
Mark network device as having link up.
Definition: netdevice.h:788
#define PCI_BASE_ADDRESS_2
Definition: pci.h:64
static int mdio_clause45_links_ok(struct efab_nic *efab)
Definition: etherfabric.c:328
ring len
Length.
Definition: dwmac.h:231
#define LPA_100
Definition: mii.h:114
static void falcon_init_resources(struct efab_nic *efab)
Definition: etherfabric.c:3495
void udelay(unsigned long usecs)
Delay for a fixed number of microseconds.
Definition: timer.c:60
static struct net_device * netdev
Definition: gdbudp.c:52
static int falcon_init_xmac(struct efab_nic *efab)
Definition: etherfabric.c:2318
static int falcon_probe_spi(struct efab_nic *efab)
Definition: etherfabric.c:3219
#define GM_ADR2_REG_MAC
Definition: etherfabric.c:1824
static void falcon_probe_nic_variant(struct efab_nic *efab, struct pci_device *pci)
Definition: etherfabric.c:3176
static int efab_transmit_done(struct efab_nic *efab, int id)
Definition: etherfabric.c:3761
static unsigned int count
Number of entries.
Definition: dwmac.h:225
unsigned long pci_bar_start(struct pci_device *pci, unsigned int reg)
Find the start of a PCI BAR.
Definition: pci.c:96
#define GMF_CFG1_REG_MAC
Definition: etherfabric.c:1844
static struct net_device_operations efab_operations
Definition: etherfabric.c:4099
#define MII_CTRL1000
Definition: mii.h:24
#define MDIO_PHYXS_LANE_ALIGNED_LBN
Definition: etherfabric.c:255
void * membase
Memory and IO base.
#define EFAB_TRACE(...)
Definition: etherfabric.c:48
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:941
#define TXC_REQUIRED_DEVS
Definition: etherfabric.c:2520
#define FCN_TX_DESC_UPD_REG_KER_DWORD
Definition: etherfabric.c:735
void unregister_nvo(struct nvo_block *nvo)
Unregister non-volatile stored options.
Definition: nvo.c:324
static struct bit_basher_operations falcon_i2c_bit_ops
Definition: etherfabric.c:1550
struct efab_mac_operations * mac_op
#define EFAB_POPULATE_OWORD_4(oword,...)
Definition: etherfabric.h:395
uint32_t revision
Entry point revision.
Definition: ib_mad.h:20
static int sfe4001_init(struct efab_nic *efab)
Definition: etherfabric.c:2844
struct bit_basher basher
Bit-bashing interface.
Definition: i2c.h:95
#define PCS_TEST_SELECT_REG
Definition: etherfabric.c:2622
int(* read)(struct bit_basher *basher, unsigned int bit_id)
Read input bit.
Definition: bitbash.h:51
#define P0_EN_5V_LBN
Definition: etherfabric.c:2808
#define EFAB_POPULATE_DWORD_2(dword,...)
Definition: etherfabric.h:455
void(* fini)(struct efab_nic *efab)
A bit-bashing interface.
Definition: bitbash.h:55
#define GMII_PSSR
Definition: etherfabric.c:89
struct nvs_device * nvs
Underlying non-volatile storage device.
Definition: nvo.h:26
struct spi_bus spi_bus
SPI bus and devices, and the user visible NVO area.
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define BMSR_LSTATUS
Definition: mii.h:57
struct refcnt refcnt
Reference counter.
Definition: netdevice.h:354
#define FCN_XM_TX_CFG_REG_MAC
Definition: etherfabric.c:849
static void falcon_fini_resources(struct efab_nic *efab)
Definition: etherfabric.c:3554
#define EFAB_EVQ_SIZE
#define txd
Definition: davicom.c:144
void nvo_init(struct nvo_block *nvo, struct nvs_device *nvs, size_t address, size_t len, int(*resize)(struct nvo_block *nvo, size_t len), struct refcnt *refcnt)
Initialise non-volatile stored options.
Definition: nvo.c:273
#define FCN_TX_DC_CFG_REG_KER
Definition: etherfabric.c:740
#define EFAB_POPULATE_QWORD_3(qword,...)
Definition: etherfabric.h:426
#define EFAB_BUF_ALIGN
#define MDIO_MMDREG_STAT2_PRESENT_VAL
Definition: etherfabric.c:249
unsigned int link_options
GMII link options.
#define FCN_RX_DC_CFG_REG_KER
Definition: etherfabric.c:707
#define EFAB_SET_QWORD(qword)
Definition: etherfabric.h:434
#define outl(data, io_addr)
Definition: io.h:329
PCI bus.
#define FCN_RX_FILTER_CTL_REG_KER
Definition: etherfabric.c:679
A PCI device.
Definition: pci.h:210
int register_netdev(struct net_device *netdev)
Register network device.
Definition: netdevice.c:759
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:159
#define EFAB_POPULATE_OWORD_1(oword,...)
Definition: etherfabric.h:401
#define CLK312_EN_LBN
Definition: etherfabric.c:2623
#define FCN_MD_PHY_ADR_REG_KER
Definition: etherfabric.c:766
#define PCS_BOOT_COMPLETE_LBN
Definition: etherfabric.c:2638
#define MDIO_MMD_PCS
Definition: etherfabric.c:208
static void falcon_eventq_read_ack(struct efab_nic *efab, struct efab_ev_queue *ev_queue)
Definition: etherfabric.c:1329
#define _falcon_writel(efab, value, reg)
Definition: etherfabric.c:1190
uint32_t addr
Buffer address.
Definition: dwmac.h:20
static void falcon_write_sram(struct efab_nic *efab, efab_qword_t *value, unsigned int index)
Write to Falcon SRAM.
Definition: etherfabric.c:1220
A network device.
Definition: netdevice.h:352
#define FCN_XX_COMMA_DET_RESET
Definition: etherfabric.c:920
int link_up
Link status.
falcon_tx_desc_t * ring
static int mdio_clause45_check_mmds(struct efab_nic *efab)
Definition: etherfabric.c:354
#define PSSR_LSTATUS
Definition: etherfabric.c:107
static void sfe4003_fini(struct efab_nic *efab)
Definition: etherfabric.c:3010
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:531
#define FCN_INT_ADR_REG_KER
Definition: etherfabric.c:427
struct efab_board_operations sfe4002_ops
Definition: etherfabric.c:3001
unsigned char uint8_t
Definition: stdint.h:10
#define FCN_XX_CORE_STAT_REG_MAC
Definition: etherfabric.c:914
static void falcon_xmac_writel(struct efab_nic *efab, efab_dword_t *value, unsigned int mac_reg)
Write dword to a Falcon XMAC register.
Definition: etherfabric.c:2065
#define GMF_CFG4_REG_MAC
Definition: etherfabric.c:1865
#define FCN_IOM_IND_ADR_REG
Definition: etherfabric.c:395
static void falcon_build_rx_desc(falcon_rx_desc_t *rxd, struct io_buffer *iob)
Definition: etherfabric.c:3595
#define SF_NV_CONFIG_EXTRA
Definition: etherfabric.c:3151
#define ETH_ALEN
Definition: if_ether.h:8
static int falcon_xaui_phy_init(struct efab_nic *efab)
Definition: etherfabric.c:2397
A PCI device ID list entry.
Definition: pci.h:174
#define GM_CFG1_REG_MAC
Definition: etherfabric.c:1750
#define EXCLUDE_FROM_RESET
Definition: etherfabric.c:596
#define le16_to_cpu(value)
Definition: byteswap.h:112
int(* read)(struct i2c_interface *i2c, struct i2c_device *i2cdev, unsigned int offset, uint8_t *data, unsigned int len)
Read data from I2C device.
Definition: i2c.h:68
static void falcon_setup_xaui(struct efab_nic *efab)
Configure Falcon XAUI output.
Definition: etherfabric.c:2096
unsigned int uint32_t
Definition: stdint.h:12
struct efab_board_operations sfe4003_ops
Definition: etherfabric.c:3014
#define GMF_CFG3_REG_MAC
Definition: etherfabric.c:1858
const char * name
Name.
Definition: pci.h:176
struct spi_device spi_flash
#define FCN_SRM_TX_DC_CFG_REG_KER
Definition: etherfabric.c:634
#define P1_SPARE_LBN
Definition: etherfabric.c:2820
#define FCN_REVISION_REG(efab, reg)
Definition: etherfabric.c:1163
struct spi_device * spi
An octword (eight-word, i.e.
Definition: etherfabric.h:122
static void falcon_handle_event(struct efab_nic *efab, falcon_event_t *evt)
Definition: etherfabric.c:3814
#define EFAB_NUM_RX_DESC
#define EAGAIN
Resource temporarily unavailable.
Definition: errno.h:318
static void falcon_free_special_buffer(void *p)
Definition: etherfabric.c:3028
#define P0_EN_1V2_LBN
Definition: etherfabric.c:2802
uint8_t unused
Unused.
Definition: librm.h:140
#define FCN_XM_FC_REG_MAC
Definition: etherfabric.c:882
static struct i2c_device i2c_max6647
Definition: etherfabric.c:2837
#define P0_EN_2V5_LBN
Definition: etherfabric.c:2804
uint8_t status
Status.
Definition: ena.h:16
static int falcon_reset(struct efab_nic *efab)
Definition: etherfabric.c:3112
static void sfe4001_fini(struct efab_nic *efab)
Definition: etherfabric.c:2965
Network device operations.
Definition: netdevice.h:213
void netdev_rx(struct net_device *netdev, struct io_buffer *iobuf)
Add packet to receive queue.
Definition: netdevice.c:548
struct device * dev
Underlying hardware device.
Definition: netdevice.h:364
#define EFAB_DWORD_FMT
Format string for printing an efab_dword_t.
Definition: etherfabric.h:130
static int falcon_init_sram(struct efab_nic *efab)
Definition: etherfabric.c:3370
struct efab_board_operations * board_op
Board, MAC, and PHY operations tables.
#define PMC_MASTER_ANLG_CTRL
Definition: etherfabric.c:2720
unsigned int read_ptr
Network device management.
#define EFAB_LOG(...)
Definition: etherfabric.c:51
static int mdio_clause45_wait_reset_mmds(struct efab_nic *efab)
Definition: etherfabric.c:266
#define FCN_TIMER_MODE_DIS
Definition: etherfabric.c:618
struct nvs_device nvs
NVS device.
Definition: spi.h:88
#define FALCON_XMAC_REG(efab_port, mac_reg)
Offset of an XMAC register within Falcon.
Definition: etherfabric.c:1112
static void * pci_get_drvdata(struct pci_device *pci)
Get PCI driver-private data.
Definition: pci.h:375
#define FALCON_GMAC_REG(efab, mac_reg)
Offset of a GMAC register within Falcon.
Definition: etherfabric.c:1107
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:78
Definition: sis900.h:23
#define LPA_100BASE4
Definition: mii.h:105
static int falcon_init_gmac(struct efab_nic *efab)
Definition: etherfabric.c:2026
#define P1_AFE_PWD_LBN
Definition: etherfabric.c:2816
#define FCN_EE_SPI_WRITE
Definition: etherfabric.c:463
struct efab_board_operations sfe4001_ops
Definition: etherfabric.c:2988
#define SF_NV_CONFIG_BASE
Definition: etherfabric.c:3150
#define PMC_ANALOG_RX_EQ_FULL
Definition: etherfabric.c:2741
#define EFAB_POPULATE_QWORD_2(qword,...)
Definition: etherfabric.h:428
static int falcon_gmii_wait(struct efab_nic *efab)
Definition: etherfabric.c:1565
static int efab_fill_rx_queue(struct efab_nic *efab, struct efab_rx_queue *rx_queue)
Definition: etherfabric.c:3650
#define MDIO_MMDREG_STAT1
Definition: etherfabric.c:220
static unsigned int gmii_nway_result(unsigned int negotiated)
Calculate GMII autonegotiated link technology.
Definition: etherfabric.c:147
static void sfe4002_fini(struct efab_nic *efab)
Definition: etherfabric.c:2997
#define FCN_IOM_IND_DAT_REG
Definition: etherfabric.c:398
#define ENOBUFS
No buffer space available.
Definition: errno.h:498
#define FCN_MAC0_CTRL_REG_KER
Definition: etherfabric.c:791
falcon_event_t * ring
#define WLHO
Definition: etherfabric.c:2828
Media Independent Interface constants.
static int falcon_tenxpress_phy_init(struct efab_nic *efab)
Definition: etherfabric.c:2665
static void falcon_gmac_readl(struct efab_nic *efab, efab_dword_t *value, unsigned int mac_reg)
Definition: etherfabric.c:1892
#define TXC_ALRGS_ATXPRE0
Definition: etherfabric.c:2514
#define P1_CONFIG
Definition: etherfabric.c:2814
#define MDIO_MMDREG_DEVS0
Definition: etherfabric.c:221
void * data
Start of data.
Definition: iobuf.h:52
efab_qword_t falcon_tx_desc_t
#define PMC_MCONF2_TEDGE
Definition: etherfabric.c:2725
static int falcon_reset_xmac(struct efab_nic *efab)
Reset 10G MAC connected to port.
Definition: etherfabric.c:2167
static int falcon_xaui_link_ok(struct efab_nic *efab)
Definition: etherfabric.c:2212
#define EIO
Input/output error.
Definition: errno.h:433
struct spi_bus * bus
SPI bus to which device is attached.
Definition: spi.h:90
#define MDIO_MMD_PMAPMD
Definition: etherfabric.c:204
#define TXC_ATXAMP_DEFAULT
Definition: etherfabric.c:2511
#define FCN_EE_SPI_EEPROM
Definition: etherfabric.c:456
uint32_t inl(volatile uint32_t *io_addr)
Read 32-bit dword from I/O-mapped device.
void free_phys(void *ptr, size_t size)
Free memory allocated with malloc_phys()
Definition: malloc.c:722
struct net_device * alloc_etherdev(size_t priv_size)
Allocate Ethernet device.
Definition: ethernet.c:264
static int falcon_txc_phy_init(struct efab_nic *efab)
Definition: etherfabric.c:2547
#define EFAB_POPULATE_DWORD_4(dword,...)
Definition: etherfabric.h:451
static void falcon_mask_status_intr(struct efab_nic *efab, int enable)
Definition: etherfabric.c:2145
struct pci_device_id * id
Driver device ID.
Definition: pci.h:247
#define GMF_CFG2_REG_MAC
Definition: etherfabric.c:1851
uint8_t ctrl
Ring control.
Definition: dwmac.h:18
#define LPA_EF_10000FULL
Definition: etherfabric.c:94
static int falcon_xgmii_status(struct efab_nic *efab)
Definition: etherfabric.c:2124
#define _falcon_readl(efab, reg)
Definition: etherfabric.c:1192
static int efab_init_mac(struct efab_nic *efab)
Definition: etherfabric.c:3995
static int sfe4002_init(struct efab_nic *efab)
Definition: etherfabric.c:2993
void iounmap(volatile const void *io_addr)
Unmap I/O address.
uint8_t data[48]
Additional event data.
Definition: ena.h:22
#define PCI_REVISION
PCI revision.
Definition: pci.h:44
Serial data.
Definition: i2c.h:116
static int efab_probe(struct pci_device *pci)
Definition: etherfabric.c:4131
#define FCN_ADR_REGION_REG_KER
Definition: etherfabric.c:401
#define EFAB_POPULATE_OWORD_8(oword,...)
Definition: etherfabric.h:387
#define BOARD_TYPE(_rev)
Definition: etherfabric.c:3173
#define FCN_MD_ID_REG_KER
Definition: etherfabric.c:771
#define WORK_AROUND_BROKEN_PCI_READS_REG_KER_A1
Definition: etherfabric.c:441
static void falcon_setup_nic(struct efab_nic *efab)
Definition: etherfabric.c:3409
struct efab_special_buffer entry
An SPI device.
Definition: spi.h:86
#define EFAB_ERR(...)
Definition: etherfabric.c:52
int nvs_read(struct nvs_device *nvs, unsigned int address, void *data, size_t len)
Read from non-volatile storage device.
Definition: nvs.c:75
#define EFAB_POPULATE_DWORD_1(dword,...)
Definition: etherfabric.h:457
#define EFAB_ZERO_OWORD(oword)
Definition: etherfabric.h:403
static void mentormac_init(struct efab_nic *efab)
Definition: etherfabric.c:1927
#define TXC_ATXPRE_NONE
Definition: etherfabric.c:2517
#define MDIO_MMDREG_CTRL1_RESET_LBN
Definition: etherfabric.c:226
#define P0_OUT
Definition: etherfabric.c:2797
#define EFAB_OWORD_FMT
Format string for printing an efab_oword_t.
Definition: etherfabric.h:136
static int efab_transmit(struct net_device *netdev, struct io_buffer *iob)
Definition: etherfabric.c:3730
void mb(void)
Memory barrier.
#define FCN_INT_ACK_KER_REG_A1
Definition: etherfabric.c:436
efab_dword_t dword[2]
Definition: etherfabric.h:114
#define FCN_ALTERA_BUILD_REG_KER
Definition: etherfabric.c:599
#define GMF_CFG0_REG_MAC
Definition: etherfabric.c:1831
static void clear_b0_fpga_memories(struct efab_nic *efab)
Definition: etherfabric.c:3076
#define MDIO45_RESET_SPINTIME
Definition: etherfabric.c:263
static int efab_alloc_resources(struct efab_nic *efab)
Definition: etherfabric.c:3951
#define GM_ADR1_REG_MAC
Definition: etherfabric.c:1813
uint16_t offset
Offset to command line.
Definition: bzimage.h:8
#define FCN_RX_RSS_INDIR_TBL_B0
Definition: etherfabric.c:1082
struct pci_driver etherfabric_driver __pci_driver
Definition: etherfabric.c:4216
#define LPA_EF_DUPLEX
Definition: etherfabric.c:99
#define FCN_XX_DISPERR_RESET
Definition: etherfabric.c:926
#define FCN_SPARE_REG_KER
Definition: etherfabric.c:610
unsigned int read_ptr
void * pci_ioremap(struct pci_device *pci, unsigned long bus_addr, size_t len)
Map PCI bus address as an I/O address.
#define MII_BMSR
Definition: atl1e.h:872
#define FCN_MD_RXD_REG_KER
Definition: etherfabric.c:750
#define EFAB_POPULATE_OWORD_3(oword,...)
Definition: etherfabric.h:397
uint8_t bytes[64]
Definition: ib_mad.h:16
#define PMC_ANALOG_RX_EQ_MASK
Definition: etherfabric.c:2738
struct efab_rx_queue rx_queue
#define FCN_GPIO_CTL_REG_KER
Definition: etherfabric.c:536
#define GM_MII_MGMT_CFG_REG_MAC
Definition: etherfabric.c:1779
int init_i2c_bit_basher(struct i2c_bit_basher *i2cbit, struct bit_basher_operations *bash_op)
Initialise I2C bit-bashing interface.
Definition: i2c_bit.c:387
static struct efab_phy_operations falcon_xfp_phy_ops
Definition: etherfabric.c:2475
struct io_buffer * buf[EFAB_NUM_RX_DESC]
#define EFAB_POPULATE_OWORD_6(oword,...)
Definition: etherfabric.h:391
#define FCN_EE_SPI_HCMD_REG
Definition: etherfabric.c:449
int(* init)(struct efab_nic *efab)
#define ok(success)
Definition: test.h:46
int(* init)(struct efab_nic *efab)
static struct command_descriptor read_cmd
"read" command descriptor
Definition: nvo_cmd.c:134
uint16_t magicnumber
Definition: etherfabric.c:3165
#define TXC_GLCMD_LMTSWRST_LBN
Definition: etherfabric.c:2490
uint8_t hw_addr[MAX_HW_ADDR_LEN]
Hardware address.
Definition: netdevice.h:381
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
struct golan_eqe_cmd cmd
Definition: CIB_PRM.h:29
int putchar(int character)
Write a single character to each console device.
Definition: console.c:28
static int falcon_xfp_phy_init(struct efab_nic *efab)
Definition: etherfabric.c:2460
static void efab_irq(struct net_device *netdev, int enable)
Definition: etherfabric.c:3888
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:669
static void efab_remove(struct pci_device *pci)
Definition: etherfabric.c:4108
String functions.
#define PCI_ROM(_vendor, _device, _name, _description, _data)
Definition: pci.h:307
Serial clock.
Definition: i2c.h:114
#define EFAB_POPULATE_DWORD_8(dword,...)
Definition: etherfabric.h:443
#define TENXPRESS_REQUIRED_DEVS
Definition: etherfabric.c:2618
#define EFAB_TXD_SIZE
static int efab_open(struct net_device *netdev)
Definition: etherfabric.c:4048
#define FCN_NIC_STAT_REG
Definition: etherfabric.c:502
uint8_t bus
Bus.
Definition: edd.h:14
#define EFAB_POPULATE_DWORD_6(dword,...)
Definition: etherfabric.h:447
#define FCN_XM_TX_PARAM_REG_MAC
Definition: etherfabric.c:889
#define GM_CFG2_REG_MAC
Definition: etherfabric.c:1763
static void falcon_i2c_bit_write(struct bit_basher *basher, unsigned int bit_id, unsigned long data)
Definition: etherfabric.c:1504
#define EFAB_QWORD_VAL(qword)
printk parameters for printing an efab_qword_t
Definition: etherfabric.h:143
static int falcon_event_present(falcon_event_t *event)
See if an event is present.
Definition: etherfabric.c:1322
#define RSL
Definition: etherfabric.c:2826
An I2C device.
Definition: i2c.h:20
#define LPA_EF_10000
Definition: etherfabric.c:98
struct i2c_bit_basher i2c_bb
int __invalid_queue_size
#define MDIO_MMDREG_STAT1_LINK_LBN
Definition: etherfabric.c:234
#define EFAB_POPULATE_OWORD_5(oword,...)
Definition: etherfabric.h:393
#define EFAB_DWORD_FIELD(dword, field)
Definition: etherfabric.h:229
struct falcon_nv_config_ver2 ver2
Definition: etherfabric.c:3169
#define rxd
Definition: davicom.c:146
static void falcon_read_sram(struct efab_nic *efab, efab_qword_t *value, unsigned int index)
Read from Falcon SRAM.
Definition: etherfabric.c:1268
void * malloc_phys(size_t size, size_t phys_align)
Allocate memory with specified physical alignment.
Definition: malloc.c:706
static int falcon_probe_nvram(struct efab_nic *efab)
Definition: etherfabric.c:3281
#define FCN_XM_ADR_LO_REG_MAC
Definition: etherfabric.c:820
FILE_LICENCE(GPL_ANY)
#define MII_STAT1000
Definition: mii.h:25
void * memset(void *dest, int character, size_t len) __nonnull
int pci_read_config_byte(struct pci_device *pci, unsigned int where, uint8_t *value)
Read byte from PCI configuration space.
A persistent I/O buffer.
Definition: iobuf.h:37
efab_qword_t falcon_event_t