3 #define DRV_VERSION "0.1"
4 #define PFX DRV_NAME ": "
7 #define dprintk(fmt, args...) \
8 printk(KERN_DEBUG PFX "%s: " fmt, jme->dev->name, ## args);
10 #define dprintk(fmt, args...)
13 #define jprintk(fmt, args...) \
14 printk(KERN_INFO PFX "%s: " fmt, jme->dev->name, ## args);
18 #define DEFAULT_MSG_ENABLE \
27 #define CHECK_AND_GOTO(fun, label, msg) \
31 printk(KERN_ERR PFX msg "\n"); \
38 #define RING_DESC_NR 512 /* Must be power of 2 */
39 #define TX_DESC_SIZE 16
41 #define TX_RING_ALLOC_SIZE (RING_DESC_NR * TX_DESC_SIZE) + TX_DESC_SIZE
42 #define TX_RING_SIZE (RING_DESC_NR * TX_DESC_SIZE)
44 #define TX_BUF_DMA_ALIGN 8
45 #define TX_BUF_SIZE 1600
46 #define TX_BUF_ALLOC_SIZE TX_BUF_SIZE + TX_BUF_DMA_ALIGN
71 enum jme_txdesc_flag_bits {
82 #define RX_DESC_SIZE 16
84 #define RX_RING_ALLOC_SIZE (RING_DESC_NR * RX_DESC_SIZE) + RX_DESC_SIZE
85 #define RX_RING_SIZE (RING_DESC_NR * RX_DESC_SIZE)
87 #define RX_BUF_DMA_ALIGN 8
88 #define RX_BUF_SIZE 1600
89 #define RX_BUF_ALLOC_SIZE RX_BUF_SIZE + RX_BUF_DMA_ALIGN
131 enum jme_rxdesc_flags_bits {
136 enum jme_rxwbdesc_flags_bits {
137 RXWBFLAG_OWN = 0x8000,
138 RXWBFLAG_INT = 0x4000,
139 RXWBFLAG_MF = 0x2000,
140 RXWBFLAG_64BIT = 0x2000,
141 RXWBFLAG_TCPON = 0x1000,
142 RXWBFLAG_UDPON = 0x0800,
143 RXWBFLAG_IPCS = 0x0400,
144 RXWBFLAG_TCPCS = 0x0200,
145 RXWBFLAG_UDPCS = 0x0100,
146 RXWBFLAG_TAGON = 0x0080,
147 RXWBFLAG_IPV4 = 0x0040,
148 RXWBFLAG_IPV6 = 0x0020,
149 RXWBFLAG_PAUSE = 0x0010,
150 RXWBFLAG_MAGIC = 0x0008,
151 RXWBFLAG_WAKEUP = 0x0004,
152 RXWBFLAG_DEST = 0x0003,
154 enum jme_rxwbdesc_desccnt_mask {
155 RXWBDCNT_WBCPL = 0x80,
156 RXWBDCNT_DCNT = 0x7F,
160 void *alloc; /* pointer to allocated memory */
161 void *desc; /* pointer to ring memory */
162 dma_addr_t dmaalloc; /* phys address of ring alloc */
163 dma_addr_t dma; /* phys address for ring dma */
165 /* Virtual addresses for each buffer of Desc */
166 void* buf_virt[RING_DESC_NR];
167 /* Physical addresses for each buffer of Desc */
168 dma_addr_t buf_dma[RING_DESC_NR];
174 * Kernel requested TX sk_buffs
175 * should be cleared after tx complete
177 struct sk_buff *tx_skb[RING_DESC_NR];
181 * Jmac Adapter Private data
184 struct pci_dev *pdev;
185 struct net_device *dev;
187 struct mii_if_info mii_if;
188 struct jme_ring rxring[RX_RING_NR];
189 struct jme_ring txring[TX_RING_NR];
190 spinlock_t xmit_lock;
191 spinlock_t recv_lock;
192 spinlock_t macaddr_lock;
199 enum jme_iomap_offsets {
206 enum jme_iomap_regs {
207 JME_TXCS = JME_MAC | 0x00, /* Transmit Control and Status */
208 JME_TXDBA = JME_MAC | 0x04, /* Transmit Queue Desc Base Addr */
209 JME_TXQDC = JME_MAC | 0x0C, /* Transmit Queue Desc Count */
210 JME_TXNDA = JME_MAC | 0x10, /* Transmit Queue Next Desc Addr */
211 JME_TXMCS = JME_MAC | 0x14, /* Transmit MAC Control Status */
212 JME_TXPFC = JME_MAC | 0x18, /* Transmit Pause Frame Control */
213 JME_TXTRHD = JME_MAC | 0x1C, /* Transmit Timer/Retry@Half-Dup */
215 JME_RXCS = JME_MAC | 0x20, /* Receive Control and Status */
216 JME_RXDBA = JME_MAC | 0x24, /* Receive Queue Desc Base Addr */
217 JME_RXQDC = JME_MAC | 0x2C, /* Receive Queue Desc Count */
218 JME_RXNDA = JME_MAC | 0x30, /* Receive Queue Next Desc Addr */
219 JME_RXMCS = JME_MAC | 0x34, /* Receive MAC Control Status */
220 JME_RXUMA = JME_MAC | 0x38, /* Receive Unicast MAC Address */
221 JME_RXMCHT = JME_MAC | 0x40, /* Receive Multicast Addr HashTable */
222 JME_WFODP = JME_MAC | 0x48, /* Wakeup Frame Output Data Port */
223 JME_WFOI = JME_MAC | 0x4C, /* Wakeup Frame Output Interface */
225 JME_SMI = JME_MAC | 0x50, /* Station Management Interface */
226 JME_GHC = JME_MAC | 0x54, /* Global Host Control */
227 JME_PMCS = JME_MAC | 0x60, /* Power Management Control/Stat */
230 JME_PHY_CS = JME_PHY | 0x28, /* PHY Control and Status Register */
231 JME_PHY_LINK = JME_PHY | 0x30, /* PHY Link Status Register */
232 JME_SMBCSR = JME_PHY | 0x40, /* SMB Control and Status */
235 JME_IEVE = JME_MISC| 0x20, /* Interrupt Event Status */
236 JME_IREQ = JME_MISC| 0x24, /* Interrupt Req Status (For Debug) */
237 JME_IENS = JME_MISC| 0x28, /* Interrupt Enable - Setting Port */
238 JME_IENC = JME_MISC| 0x2C, /* Interrupt Enable - Clearing Port */
242 * TX Control/Status Bits
245 TXCS_QUEUE7S = 0x00008000,
246 TXCS_QUEUE6S = 0x00004000,
247 TXCS_QUEUE5S = 0x00002000,
248 TXCS_QUEUE4S = 0x00001000,
249 TXCS_QUEUE3S = 0x00000800,
250 TXCS_QUEUE2S = 0x00000400,
251 TXCS_QUEUE1S = 0x00000200,
252 TXCS_QUEUE0S = 0x00000100,
253 TXCS_FIFOTH = 0x000000C0,
254 TXCS_DMASIZE = 0x00000030,
255 TXCS_BURST = 0x00000004,
256 TXCS_ENABLE = 0x00000001,
258 enum jme_txcs_value {
259 TXCS_FIFOTH_16QW = 0x000000C0,
260 TXCS_FIFOTH_12QW = 0x00000080,
261 TXCS_FIFOTH_8QW = 0x00000040,
262 TXCS_FIFOTH_4QW = 0x00000000,
264 TXCS_DMASIZE_64B = 0x00000000,
265 TXCS_DMASIZE_128B = 0x00000010,
266 TXCS_DMASIZE_256B = 0x00000020,
267 TXCS_DMASIZE_512B = 0x00000030,
269 TXCS_SELECT_QUEUE0 = 0x00000000,
270 TXCS_SELECT_QUEUE1 = 0x00010000,
271 TXCS_SELECT_QUEUE2 = 0x00020000,
272 TXCS_SELECT_QUEUE3 = 0x00030000,
273 TXCS_SELECT_QUEUE4 = 0x00040000,
274 TXCS_SELECT_QUEUE5 = 0x00050000,
275 TXCS_SELECT_QUEUE6 = 0x00060000,
276 TXCS_SELECT_QUEUE7 = 0x00070000,
278 TXCS_DEFAULT = TXCS_FIFOTH_4QW |
282 #define JME_TX_DISABLE_TIMEOUT 200 /* 200 usec */
285 * TX MAC Control/Status Bits
287 enum jme_txmcs_bit_masks {
288 TXMCS_IFG2 = 0xC0000000,
289 TXMCS_IFG1 = 0x30000000,
290 TXMCS_TTHOLD = 0x00000300,
291 TXMCS_FBURST = 0x00000080,
292 TXMCS_CARRIEREXT = 0x00000040,
293 TXMCS_DEFER = 0x00000020,
294 TXMCS_BACKOFF = 0x00000010,
295 TXMCS_CARRIERSENSE = 0x00000008,
296 TXMCS_COLLISION = 0x00000004,
297 TXMCS_CRC = 0x00000002,
298 TXMCS_PADDING = 0x00000001,
300 enum jme_txmcs_values {
301 TXMCS_IFG2_6_4 = 0x00000000,
302 TXMCS_IFG2_8_5 = 0x40000000,
303 TXMCS_IFG2_10_6 = 0x80000000,
304 TXMCS_IFG2_12_7 = 0xC0000000,
306 TXMCS_IFG1_8_4 = 0x00000000,
307 TXMCS_IFG1_12_6 = 0x10000000,
308 TXMCS_IFG1_16_8 = 0x20000000,
309 TXMCS_IFG1_20_10 = 0x30000000,
311 TXMCS_TTHOLD_1_8 = 0x00000000,
312 TXMCS_TTHOLD_1_4 = 0x00000100,
313 TXMCS_TTHOLD_1_2 = 0x00000200,
314 TXMCS_TTHOLD_FULL = 0x00000300,
316 TXMCS_DEFAULT = TXMCS_IFG2_8_5 |
326 * RX Control/Status Bits
329 RXCS_QST = 0x00000004,
330 RXCS_ENABLE = 0x00000001,
332 #define JME_RX_DISABLE_TIMEOUT 200 /* 200 usec */
335 * RX MAC Control/Status Bits
337 enum jme_rxmcs_bits {
338 RXMCS_ALLFRAME = 0x00000800,
339 RXMCS_BRDFRAME = 0x00000400,
340 RXMCS_MULFRAME = 0x00000200,
341 RXMCS_UNIFRAME = 0x00000100,
342 RXMCS_ALLMULFRAME = 0x00000080,
343 RXMCS_MULFILTERED = 0x00000040,
347 * SMI Related definitions
349 enum jme_smi_bit_mask
351 SMI_DATA_MASK = 0xFFFF0000,
352 SMI_REG_ADDR_MASK = 0x0000F800,
353 SMI_PHY_ADDR_MASK = 0x000007C0,
354 SMI_OP_WRITE = 0x00000020,
355 SMI_OP_REQ = 0x00000010, /* Set to 1, after req done it'll be cleared to 0 */
356 SMI_OP_MDIO = 0x00000008, /* Software assess In/Out */
357 SMI_OP_MDOE = 0x00000004, /* Software Output Enable */
358 SMI_OP_MDC = 0x00000002, /* Software CLK Control */
359 SMI_OP_MDEN = 0x00000001, /* Software access Enable */
361 enum jme_smi_bit_shift
364 SMI_REG_ADDR_SHIFT = 11,
365 SMI_PHY_ADDR_SHIFT = 6,
367 __always_inline __u32 smi_reg_addr(int x)
369 return (((x) << SMI_REG_ADDR_SHIFT) & SMI_REG_ADDR_MASK);
371 __always_inline __u32 smi_phy_addr(int x)
373 return (((x) << SMI_PHY_ADDR_SHIFT) & SMI_PHY_ADDR_MASK);
375 #define JME_PHY_TIMEOUT 1000 /* 1000 usec */
378 * Global Host Control
380 enum jme_ghc_bit_mask {
381 GHC_SWRST = 0x40000000,
382 GHC_DPX = 0x00000040,
383 GHC_SPEED = 0x00000030,
384 GHC_LINK_POLL = 0x00000001,
386 enum jme_ghc_speed_val {
387 GHC_SPEED_10M = 0x00000010,
388 GHC_SPEED_100M = 0x00000020,
389 GHC_SPEED_1000M = 0x00000030,
393 * Giga PHY Status Registers
395 enum jme_phy_link_bit_mask {
396 PHY_LINK_SPEED_MASK = 0x0000C000,
397 PHY_LINK_DUPLEX = 0x00002000,
398 PHY_LINK_SPEEDDPU_RESOLVED = 0x00000800,
399 PHY_LINK_UP = 0x00000400,
400 PHY_LINK_AUTONEG_COMPLETE = 0x00000200,
402 enum jme_phy_link_speed_val {
403 PHY_LINK_SPEED_10M = 0x00000000,
404 PHY_LINK_SPEED_100M = 0x00004000,
405 PHY_LINK_SPEED_1000M = 0x00008000,
407 #define JME_AUTONEG_TIMEOUT 500 /* 500 ms */
410 * SMB Control and Status
412 enum jme_smbcsr_bit_mask
414 SMBCSR_CNACK = 0x00020000,
415 SMBCSR_RELOAD = 0x00010000,
416 SMBCSR_EEPROMD = 0x00000020,
418 #define JME_SMB_TIMEOUT 10 /* 10 msec */
422 * Interrupt Status Bits
424 enum jme_interrupt_bits
426 INTR_SWINTR = 0x80000000,
427 INTR_TMINTR = 0x40000000,
428 INTR_LINKCH = 0x20000000,
429 INTR_PAUSERCV = 0x10000000,
430 INTR_MAGICRCV = 0x08000000,
431 INTR_WAKERCV = 0x04000000,
432 INTR_PCCRX0TO = 0x02000000,
433 INTR_PCCRX1TO = 0x01000000,
434 INTR_PCCRX2TO = 0x00800000,
435 INTR_PCCRX3TO = 0x00400000,
436 INTR_PCCTXTO = 0x00200000,
437 INTR_PCCRX0 = 0x00100000,
438 INTR_PCCRX1 = 0x00080000,
439 INTR_PCCRX2 = 0x00040000,
440 INTR_PCCRX3 = 0x00020000,
441 INTR_PCCTX = 0x00010000,
442 INTR_RX3EMP = 0x00008000,
443 INTR_RX2EMP = 0x00004000,
444 INTR_RX1EMP = 0x00002000,
445 INTR_RX0EMP = 0x00001000,
446 INTR_RX3 = 0x00000800,
447 INTR_RX2 = 0x00000400,
448 INTR_RX1 = 0x00000200,
449 INTR_RX0 = 0x00000100,
450 INTR_TX7 = 0x00000080,
451 INTR_TX6 = 0x00000040,
452 INTR_TX5 = 0x00000020,
453 INTR_TX4 = 0x00000010,
454 INTR_TX3 = 0x00000008,
455 INTR_TX2 = 0x00000004,
456 INTR_TX1 = 0x00000002,
457 INTR_TX0 = 0x00000001,
459 static const __u32 INTR_ENABLE = INTR_LINKCH |
465 * Read/Write MMaped I/O Registers
467 __always_inline __u32 jread32(struct jme_adapter *jme, __u32 reg)
469 return le32_to_cpu(readl(jme->regs + reg));
471 __always_inline void jwrite32(struct jme_adapter *jme, __u32 reg, __u32 val)
473 writel(cpu_to_le32(val), jme->regs + reg);
475 __always_inline void jwrite32f(struct jme_adapter *jme, __u32 reg, __u32 val)
478 * Read after write should cause flush
480 writel(cpu_to_le32(val), jme->regs + reg);
481 readl(jme->regs + reg);
485 * Function prototypes for ethtool
487 static void jme_get_drvinfo(struct net_device *netdev,
488 struct ethtool_drvinfo *info);
489 static int jme_get_settings(struct net_device *netdev,
490 struct ethtool_cmd *ecmd);
491 static int jme_set_settings(struct net_device *netdev,
492 struct ethtool_cmd *ecmd);
493 static u32 jme_get_link(struct net_device *netdev);
497 * Function prototypes for netdev
499 static int jme_open(struct net_device *netdev);
500 static int jme_close(struct net_device *netdev);
501 static int jme_start_xmit(struct sk_buff *skb, struct net_device *netdev);
502 static int jme_set_macaddr(struct net_device *netdev, void *p);
503 static void jme_set_multi(struct net_device *netdev);