iPXE
Functions | Variables
jme.c File Reference
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ipxe/io.h>
#include <errno.h>
#include <unistd.h>
#include <byteswap.h>
#include <ipxe/pci.h>
#include <ipxe/if_ether.h>
#include <ipxe/ethernet.h>
#include <ipxe/iobuf.h>
#include <ipxe/netdevice.h>
#include <ipxe/malloc.h>
#include <mii.h>
#include "jme.h"

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER)
 
static int jme_mdio_read (struct net_device *netdev, int phy, int reg)
 
static void jme_mdio_write (struct net_device *netdev, int phy, int reg, int val)
 
static void jme_reset_phy_processor (struct jme_adapter *jme)
 
static void jme_phy_init (struct jme_adapter *jme)
 
static void jme_set_phyfifoa (struct jme_adapter *jme)
 
static void jme_set_phyfifob (struct jme_adapter *jme)
 
static void jme_phy_off (struct jme_adapter *jme)
 
static void jme_restart_an (struct jme_adapter *jme)
 
static void jme_reset_ghc_speed (struct jme_adapter *jme)
 
static void jme_start_irq (struct jme_adapter *jme)
 
static void jme_stop_irq (struct jme_adapter *jme)
 
static void jme_setup_wakeup_frame (struct jme_adapter *jme, u32 *mask, u32 crc, int fnr)
 
static void jme_reset_mac_processor (struct jme_adapter *jme)
 
static void jme_free_tx_buffers (struct jme_adapter *jme)
 
static void jme_free_tx_resources (struct jme_adapter *jme)
 
static int jme_alloc_tx_resources (struct jme_adapter *jme)
 
static void jme_init_tx_ring (struct jme_adapter *jme)
 
static void jme_enable_tx_engine (struct jme_adapter *jme)
 
static void jme_disable_tx_engine (struct jme_adapter *jme)
 
static void jme_set_clean_rxdesc (struct jme_adapter *jme, int i)
 
static int jme_make_new_rx_buf (struct io_buffer **rxbip)
 
static void jme_free_rx_buf (struct jme_adapter *jme, int i)
 
static void jme_free_rx_resources (struct jme_adapter *jme)
 
static int jme_alloc_rx_resources (struct jme_adapter *jme)
 
static void jme_init_rx_ring (struct jme_adapter *jme)
 
static void jme_set_multi (struct jme_adapter *jme)
 
static void jme_enable_rx_engine (struct jme_adapter *jme)
 
static void jme_restart_rx_engine (struct jme_adapter *jme)
 
static void jme_disable_rx_engine (struct jme_adapter *jme)
 
static void jme_refill_rx_ring (struct jme_adapter *jme, int curhole)
 
static void jme_alloc_and_feed_iob (struct jme_adapter *jme, int idx)
 
static void jme_process_receive (struct jme_adapter *jme)
 
static void jme_set_custom_macaddr (struct net_device *netdev)
 
static int jme_open (struct net_device *netdev)
 Open NIC. More...
 
static void jme_close (struct net_device *netdev)
 Close NIC. More...
 
static int jme_alloc_txdesc (struct jme_adapter *jme)
 
static void jme_fill_tx_desc (struct jme_adapter *jme, struct io_buffer *iob, int idx)
 
static int jme_transmit (struct net_device *netdev, struct io_buffer *iobuf)
 Transmit packet. More...
 
static int jme_check_link (struct net_device *netdev, int testonly)
 
static void jme_link_change (struct net_device *netdev)
 
static void jme_tx_clean (struct jme_adapter *jme)
 
static void jme_poll (struct net_device *netdev)
 Poll for received packets. More...
 
static void jme_irq (struct net_device *netdev, int enable)
 Enable/disable interrupts. More...
 
static void jme_check_hw_ver (struct jme_adapter *jme)
 
static int jme_reload_eeprom (struct jme_adapter *jme)
 
static void jme_load_macaddr (struct net_device *netdev)
 
static int jme_probe (struct pci_device *pci)
 Probe PCI device. More...
 
static void jme_remove (struct pci_device *pci)
 Remove PCI device. More...
 

Variables

static struct net_device_operations jme_operations
 JME net device operations. More...
 
static struct pci_device_id jm_nics []
 
struct pci_driver jme_driver __pci_driver
 

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER  )

◆ jme_mdio_read()

static int jme_mdio_read ( struct net_device netdev,
int  phy,
int  reg 
)
static

Definition at line 41 of file jme.c.

42 {
43  struct jme_adapter *jme = netdev->priv;
44  int i, val, again = (reg == MII_BMSR) ? 1 : 0;
45 
46 read_again:
48  smi_phy_addr(phy) |
49  smi_reg_addr(reg));
50 
51  for (i = JME_PHY_TIMEOUT * 50 ; i > 0 ; --i) {
52  udelay(20);
53  val = jread32(jme, JME_SMI);
54  if ((val & SMI_OP_REQ) == 0)
55  break;
56  }
57 
58  if (i == 0) {
59  DBG("phy(%d) read timeout : %d\n", phy, reg);
60  return 0;
61  }
62 
63  if (again--)
64  goto read_again;
65 
66  return (val & SMI_DATA_MASK) >> SMI_DATA_SHIFT;
67 }
static void jwrite32(struct jme_adapter *jme, uint32_t reg, uint32_t val)
Definition: jme.h:901
static uint32_t jread32(struct jme_adapter *jme, uint32_t reg)
Definition: jme.h:896
void * priv
Driver private data.
Definition: netdevice.h:425
Definition: jme.h:315
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 unsigned int unsigned int reg
Definition: intel.h:245
static uint32_t smi_reg_addr(int x)
Definition: jme.h:583
void __asmcall int val
Definition: setjmp.h:28
#define JME_PHY_TIMEOUT
Definition: jme.h:593
static uint32_t smi_phy_addr(int x)
Definition: jme.h:588
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
#define MII_BMSR
Definition: atl1e.h:872

References DBG, JME_PHY_TIMEOUT, JME_SMI, jread32(), jwrite32(), MII_BMSR, netdev, net_device::priv, reg, SMI_DATA_MASK, SMI_DATA_SHIFT, SMI_OP_REQ, smi_phy_addr(), smi_reg_addr(), udelay(), and val.

Referenced by jme_phy_init(), jme_probe(), jme_reset_phy_processor(), and jme_restart_an().

◆ jme_mdio_write()

static void jme_mdio_write ( struct net_device netdev,
int  phy,
int  reg,
int  val 
)
static

Definition at line 70 of file jme.c.

72 {
73  struct jme_adapter *jme = netdev->priv;
74  int i;
75 
78  smi_phy_addr(phy) | smi_reg_addr(reg));
79 
80  wmb();
81  for (i = JME_PHY_TIMEOUT * 50 ; i > 0 ; --i) {
82  udelay(20);
83  if ((jread32(jme, JME_SMI) & SMI_OP_REQ) == 0)
84  break;
85  }
86 
87  if (i == 0)
88  DBG("phy(%d) write timeout : %d\n", phy, reg);
89 
90  return;
91 }
wmb()
static void jwrite32(struct jme_adapter *jme, uint32_t reg, uint32_t val)
Definition: jme.h:901
static uint32_t jread32(struct jme_adapter *jme, uint32_t reg)
Definition: jme.h:896
void * priv
Driver private data.
Definition: netdevice.h:425
Definition: jme.h:315
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 unsigned int unsigned int reg
Definition: intel.h:245
static uint32_t smi_reg_addr(int x)
Definition: jme.h:583
void __asmcall int val
Definition: setjmp.h:28
#define JME_PHY_TIMEOUT
Definition: jme.h:593
static uint32_t smi_phy_addr(int x)
Definition: jme.h:588
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498

References DBG, JME_PHY_TIMEOUT, JME_SMI, jread32(), jwrite32(), netdev, net_device::priv, reg, SMI_DATA_MASK, SMI_DATA_SHIFT, SMI_OP_REQ, SMI_OP_WRITE, smi_phy_addr(), smi_reg_addr(), udelay(), val, and wmb().

Referenced by jme_phy_init(), jme_phy_off(), jme_probe(), jme_reset_phy_processor(), jme_restart_an(), jme_set_phyfifoa(), and jme_set_phyfifob().

◆ jme_reset_phy_processor()

static void jme_reset_phy_processor ( struct jme_adapter jme)
static

Definition at line 94 of file jme.c.

95 {
96  u32 val;
97 
99  jme->mii_if.phy_id,
102 
105  jme->mii_if.phy_id,
106  MII_CTRL1000,
108 
109  val = jme_mdio_read(jme->mii_if.dev,
110  jme->mii_if.phy_id,
111  MII_BMCR);
112 
114  jme->mii_if.phy_id,
115  MII_BMCR, val | BMCR_RESET);
116 
117  return;
118 }
#define MII_ADVERTISE
Definition: atl1e.h:875
int phy_id
Definition: mii.h:143
struct net_device * dev
Definition: mii.h:152
#define ADVERTISE_1000FULL
Definition: mii.h:131
#define PCI_DEVICE_ID_JMICRON_JMC250
Definition: jme.h:27
struct mii_if_info mii_if
Definition: jme.h:254
static void jme_mdio_write(struct net_device *netdev, int phy, int reg, int val)
Definition: jme.c:70
static int jme_mdio_read(struct net_device *netdev, int phy, int reg)
Definition: jme.c:41
uint16_t device
Device ID.
Definition: pci.h:204
struct pci_device * pdev
Definition: jme.h:255
#define MII_CTRL1000
Definition: mii.h:24
#define ADVERTISE_PAUSE_ASYM
Definition: mii.h:82
#define ADVERTISE_ALL
Definition: mii.h:90
#define MII_BMCR
Definition: atl1e.h:871
#define ADVERTISE_1000HALF
Definition: mii.h:132
void __asmcall int val
Definition: setjmp.h:28
#define BMCR_RESET
Definition: mii.h:50
#define ADVERTISE_PAUSE_CAP
Definition: mii.h:81
uint32_t u32
Definition: stdint.h:23

References ADVERTISE_1000FULL, ADVERTISE_1000HALF, ADVERTISE_ALL, ADVERTISE_PAUSE_ASYM, ADVERTISE_PAUSE_CAP, BMCR_RESET, mii_if_info::dev, pci_device::device, jme_mdio_read(), jme_mdio_write(), MII_ADVERTISE, MII_BMCR, MII_CTRL1000, jme_adapter::mii_if, PCI_DEVICE_ID_JMICRON_JMC250, jme_adapter::pdev, mii_if_info::phy_id, and val.

Referenced by jme_open().

◆ jme_phy_init()

static void jme_phy_init ( struct jme_adapter jme)
static

Definition at line 121 of file jme.c.

122 {
123  u16 reg26;
124 
125  reg26 = jme_mdio_read(jme->mii_if.dev, jme->mii_if.phy_id, 26);
126  jme_mdio_write(jme->mii_if.dev, jme->mii_if.phy_id, 26, reg26 | 0x1000);
127 }
uint16_t u16
Definition: stdint.h:21
int phy_id
Definition: mii.h:143
struct net_device * dev
Definition: mii.h:152
struct mii_if_info mii_if
Definition: jme.h:254
static void jme_mdio_write(struct net_device *netdev, int phy, int reg, int val)
Definition: jme.c:70
static int jme_mdio_read(struct net_device *netdev, int phy, int reg)
Definition: jme.c:41

References mii_if_info::dev, jme_mdio_read(), jme_mdio_write(), jme_adapter::mii_if, and mii_if_info::phy_id.

Referenced by jme_probe().

◆ jme_set_phyfifoa()

static void jme_set_phyfifoa ( struct jme_adapter jme)
static

Definition at line 130 of file jme.c.

131 {
132  jme_mdio_write(jme->mii_if.dev, jme->mii_if.phy_id, 27, 0x0004);
133 }
int phy_id
Definition: mii.h:143
struct net_device * dev
Definition: mii.h:152
struct mii_if_info mii_if
Definition: jme.h:254
static void jme_mdio_write(struct net_device *netdev, int phy, int reg, int val)
Definition: jme.c:70

References mii_if_info::dev, jme_mdio_write(), jme_adapter::mii_if, and mii_if_info::phy_id.

Referenced by jme_check_link(), and jme_probe().

◆ jme_set_phyfifob()

static void jme_set_phyfifob ( struct jme_adapter jme)
static

Definition at line 136 of file jme.c.

137 {
138  jme_mdio_write(jme->mii_if.dev, jme->mii_if.phy_id, 27, 0x0000);
139 }
int phy_id
Definition: mii.h:143
struct net_device * dev
Definition: mii.h:152
struct mii_if_info mii_if
Definition: jme.h:254
static void jme_mdio_write(struct net_device *netdev, int phy, int reg, int val)
Definition: jme.c:70

References mii_if_info::dev, jme_mdio_write(), jme_adapter::mii_if, and mii_if_info::phy_id.

Referenced by jme_check_link().

◆ jme_phy_off()

static void jme_phy_off ( struct jme_adapter jme)
static

Definition at line 142 of file jme.c.

143 {
145 }
int phy_id
Definition: mii.h:143
struct net_device * dev
Definition: mii.h:152
struct mii_if_info mii_if
Definition: jme.h:254
static void jme_mdio_write(struct net_device *netdev, int phy, int reg, int val)
Definition: jme.c:70
#define MII_BMCR
Definition: atl1e.h:871
#define BMCR_PDOWN
Definition: mii.h:46

References BMCR_PDOWN, mii_if_info::dev, jme_mdio_write(), MII_BMCR, jme_adapter::mii_if, and mii_if_info::phy_id.

Referenced by jme_close(), and jme_probe().

◆ jme_restart_an()

static void jme_restart_an ( struct jme_adapter jme)
static

Definition at line 148 of file jme.c.

149 {
150  uint32_t bmcr;
151 
152  bmcr = jme_mdio_read(jme->mii_if.dev, jme->mii_if.phy_id, MII_BMCR);
153  bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
154  jme_mdio_write(jme->mii_if.dev, jme->mii_if.phy_id, MII_BMCR, bmcr);
155 }
int phy_id
Definition: mii.h:143
struct net_device * dev
Definition: mii.h:152
#define BMCR_ANRESTART
Definition: mii.h:44
struct mii_if_info mii_if
Definition: jme.h:254
static void jme_mdio_write(struct net_device *netdev, int phy, int reg, int val)
Definition: jme.c:70
static int jme_mdio_read(struct net_device *netdev, int phy, int reg)
Definition: jme.c:41
#define MII_BMCR
Definition: atl1e.h:871
unsigned int uint32_t
Definition: stdint.h:12
#define BMCR_ANENABLE
Definition: mii.h:47

References BMCR_ANENABLE, BMCR_ANRESTART, mii_if_info::dev, jme_mdio_read(), jme_mdio_write(), MII_BMCR, jme_adapter::mii_if, and mii_if_info::phy_id.

Referenced by jme_open().

◆ jme_reset_ghc_speed()

static void jme_reset_ghc_speed ( struct jme_adapter jme)
static

Definition at line 158 of file jme.c.

159 {
160  jme->reg_ghc &= ~(GHC_SPEED_1000M | GHC_DPX);
161  jwrite32(jme, JME_GHC, jme->reg_ghc);
162 }
static void jwrite32(struct jme_adapter *jme, uint32_t reg, uint32_t val)
Definition: jme.h:901
Definition: jme.h:316
uint32_t reg_ghc
Definition: jme.h:258
Definition: jme.h:601

References GHC_DPX, GHC_SPEED_1000M, JME_GHC, jwrite32(), and jme_adapter::reg_ghc.

Referenced by jme_link_change().

◆ jme_start_irq()

static void jme_start_irq ( struct jme_adapter jme)
static

Definition at line 165 of file jme.c.

166 {
167  /*
168  * Enable Interrupts
169  */
171 }
static void jwrite32(struct jme_adapter *jme, uint32_t reg, uint32_t val)
Definition: jme.h:901
static const uint32_t INTR_ENABLE
Definition: jme.h:831
Definition: jme.h:331

References INTR_ENABLE, JME_IENS, and jwrite32().

Referenced by jme_irq().

◆ jme_stop_irq()

static void jme_stop_irq ( struct jme_adapter jme)
static

Definition at line 174 of file jme.c.

175 {
176  /*
177  * Disable Interrupts
178  */
180 }
Definition: jme.h:332
static const uint32_t INTR_ENABLE
Definition: jme.h:831
static void jwrite32f(struct jme_adapter *jme, uint32_t reg, uint32_t val)
Definition: jme.h:906

References INTR_ENABLE, JME_IENC, and jwrite32f().

Referenced by jme_irq().

◆ jme_setup_wakeup_frame()

static void jme_setup_wakeup_frame ( struct jme_adapter jme,
u32 mask,
u32  crc,
int  fnr 
)
static

Definition at line 183 of file jme.c.

185 {
186  int i;
187 
188  /*
189  * Setup CRC pattern
190  */
191  jwrite32(jme, JME_WFOI, WFOI_CRC_SEL | (fnr & WFOI_FRAME_SEL));
192  wmb();
193  jwrite32(jme, JME_WFODP, crc);
194  wmb();
195 
196  /*
197  * Setup Mask
198  */
199  for (i = 0 ; i < WAKEUP_FRAME_MASK_DWNR ; ++i) {
200  jwrite32(jme, JME_WFOI,
201  ((i << WFOI_MASK_SHIFT) & WFOI_MASK_SEL) |
202  (fnr & WFOI_FRAME_SEL));
203  wmb();
204  jwrite32(jme, JME_WFODP, mask[i]);
205  wmb();
206  }
207 }
wmb()
#define WAKEUP_FRAME_MASK_DWNR
Definition: jme.h:549
static void jwrite32(struct jme_adapter *jme, uint32_t reg, uint32_t val)
Definition: jme.h:901
Definition: jme.h:312
Definition: jme.h:313

References JME_WFODP, JME_WFOI, jwrite32(), WAKEUP_FRAME_MASK_DWNR, WFOI_CRC_SEL, WFOI_FRAME_SEL, WFOI_MASK_SEL, WFOI_MASK_SHIFT, and wmb().

Referenced by jme_reset_mac_processor().

◆ jme_reset_mac_processor()

static void jme_reset_mac_processor ( struct jme_adapter jme)
static

Definition at line 210 of file jme.c.

211 {
212  u32 mask[WAKEUP_FRAME_MASK_DWNR] = {0, 0, 0, 0};
213  u32 crc = 0xCDCDCDCD;
214  int i;
215 
216  jwrite32(jme, JME_GHC, jme->reg_ghc | GHC_SWRST);
217  udelay(2);
218  jwrite32(jme, JME_GHC, jme->reg_ghc);
219 
220  jwrite32(jme, JME_RXDBA_LO, 0x00000000);
221  jwrite32(jme, JME_RXDBA_HI, 0x00000000);
222  jwrite32(jme, JME_RXQDC, 0x00000000);
223  jwrite32(jme, JME_RXNDA, 0x00000000);
224  jwrite32(jme, JME_TXDBA_LO, 0x00000000);
225  jwrite32(jme, JME_TXDBA_HI, 0x00000000);
226  jwrite32(jme, JME_TXQDC, 0x00000000);
227  jwrite32(jme, JME_TXNDA, 0x00000000);
228 
229  jwrite32(jme, JME_RXMCHT_LO, 0x00000000);
230  jwrite32(jme, JME_RXMCHT_HI, 0x00000000);
231  for (i = 0 ; i < WAKEUP_FRAME_NR ; ++i)
232  jme_setup_wakeup_frame(jme, mask, crc, i);
235 }
#define WAKEUP_FRAME_MASK_DWNR
Definition: jme.h:549
static void jwrite32(struct jme_adapter *jme, uint32_t reg, uint32_t val)
Definition: jme.h:901
Definition: jme.h:600
Definition: jme.h:296
Definition: jme.h:297
void udelay(unsigned long usecs)
Delay for a fixed number of microseconds.
Definition: timer.c:60
Definition: jme.h:316
uint32_t reg_ghc
Definition: jme.h:258
Definition: jme.h:306
#define WAKEUP_FRAME_NR
Definition: jme.h:548
static void jme_setup_wakeup_frame(struct jme_adapter *jme, u32 *mask, u32 crc, int fnr)
Definition: jme.c:183
Definition: jme.h:305
uint32_t u32
Definition: stdint.h:23

References GHC_SWRST, GPREG0_DEFAULT, GPREG1_DEFAULT, JME_GHC, JME_GPREG0, JME_GPREG1, JME_RXDBA_HI, JME_RXDBA_LO, JME_RXMCHT_HI, JME_RXMCHT_LO, JME_RXNDA, JME_RXQDC, jme_setup_wakeup_frame(), JME_TXDBA_HI, JME_TXDBA_LO, JME_TXNDA, JME_TXQDC, jwrite32(), jme_adapter::reg_ghc, udelay(), WAKEUP_FRAME_MASK_DWNR, and WAKEUP_FRAME_NR.

Referenced by jme_close(), jme_link_change(), and jme_probe().

◆ jme_free_tx_buffers()

static void jme_free_tx_buffers ( struct jme_adapter jme)
static

Definition at line 238 of file jme.c.

239 {
240  struct jme_ring *txring = &jme->txring;
241  struct io_buffer *txbi;
242  unsigned int i;
243 
244  for (i = 0; i < jme->tx_ring_size; ++i) {
245  txbi = txring->bufinf[i];
246  if (txbi) {
248  txbi, -ENOLINK);
249  txring->bufinf[i] = NULL;
250  }
251  }
252 }
struct net_device * dev
Definition: mii.h:152
struct mii_if_info mii_if
Definition: jme.h:254
uint32_t tx_ring_size
Definition: jme.h:267
struct io_buffer ** bufinf
Definition: jme.h:241
#define ENOLINK
Link has been severed.
Definition: errno.h:529
struct jme_ring txring
Definition: jme.h:266
void netdev_tx_complete_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Complete network transmission.
Definition: netdevice.c:395
Definition: jme.h:236
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
A persistent I/O buffer.
Definition: iobuf.h:32

References jme_ring::bufinf, mii_if_info::dev, ENOLINK, jme_adapter::mii_if, netdev_tx_complete_err(), NULL, jme_adapter::tx_ring_size, and jme_adapter::txring.

Referenced by jme_init_tx_ring().

◆ jme_free_tx_resources()

static void jme_free_tx_resources ( struct jme_adapter jme)
static

Definition at line 255 of file jme.c.

256 {
257  struct jme_ring *txring = &jme->txring;
258 
259  if (txring->desc) {
260  if (txring->bufinf) {
261  memset(txring->bufinf, 0,
262  sizeof(struct io_buffer *) * jme->tx_ring_size);
263  free(txring->bufinf);
264  }
265  free_dma(txring->desc, jme->tx_ring_size * TX_DESC_SIZE);
266  txring->desc = NULL;
267  txring->dma = 0;
268  txring->bufinf = NULL;
269  }
270  txring->next_to_use = 0;
271  txring->next_to_clean = 0;
272  txring->nr_free = 0;
273 }
unsigned long dma
Definition: jme.h:238
uint32_t tx_ring_size
Definition: jme.h:267
struct io_buffer ** bufinf
Definition: jme.h:241
void * desc
Definition: jme.h:237
int next_to_use
Definition: jme.h:245
int next_to_clean
Definition: jme.h:243
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
struct jme_ring txring
Definition: jme.h:266
int nr_free
Definition: jme.h:246
Definition: jme.h:236
#define TX_DESC_SIZE
Definition: jme.h:51
static void free_dma(void *ptr, size_t size)
Free memory allocated with malloc_dma()
Definition: malloc.h:81
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
void * memset(void *dest, int character, size_t len) __nonnull
A persistent I/O buffer.
Definition: iobuf.h:32

References jme_ring::bufinf, jme_ring::desc, jme_ring::dma, free, free_dma(), memset(), jme_ring::next_to_clean, jme_ring::next_to_use, jme_ring::nr_free, NULL, TX_DESC_SIZE, jme_adapter::tx_ring_size, and jme_adapter::txring.

Referenced by jme_alloc_tx_resources(), and jme_close().

◆ jme_alloc_tx_resources()

static int jme_alloc_tx_resources ( struct jme_adapter jme)
static

Definition at line 276 of file jme.c.

277 {
278  struct jme_ring *txring = &jme->txring;
279 
280  txring->desc = malloc_dma(jme->tx_ring_size * TX_DESC_SIZE,
282  if (!txring->desc) {
283  DBG("Can not allocate transmit ring descriptors.\n");
284  goto err_out;
285  }
286 
287  /*
288  * 16 Bytes align
289  */
290  txring->dma = virt_to_bus(txring->desc);
291  txring->bufinf = malloc(sizeof(struct io_buffer *) *
292  jme->tx_ring_size);
293  if (!(txring->bufinf)) {
294  DBG("Can not allocate transmit buffer info.\n");
295  goto err_out;
296  }
297 
298  /*
299  * Initialize Transmit Buffer Pointers
300  */
301  memset(txring->bufinf, 0,
302  sizeof(struct io_buffer *) * jme->tx_ring_size);
303 
304  return 0;
305 
306 err_out:
308  return -ENOMEM;
309 }
#define RING_DESC_ALIGN
Definition: jme.h:50
unsigned long dma
Definition: jme.h:238
uint32_t tx_ring_size
Definition: jme.h:267
struct io_buffer ** bufinf
Definition: jme.h:241
void * desc
Definition: jme.h:237
#define ENOMEM
Not enough space.
Definition: errno.h:534
static __always_inline unsigned long virt_to_bus(volatile const void *addr)
Convert virtual address to a bus address.
Definition: io.h:183
struct jme_ring txring
Definition: jme.h:266
void * malloc(size_t size)
Allocate memory.
Definition: malloc.c:583
Definition: jme.h:236
static void *__malloc malloc_dma(size_t size, size_t phys_align)
Allocate memory for DMA.
Definition: malloc.h:66
#define TX_DESC_SIZE
Definition: jme.h:51
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
static void jme_free_tx_resources(struct jme_adapter *jme)
Definition: jme.c:255
void * memset(void *dest, int character, size_t len) __nonnull
A persistent I/O buffer.
Definition: iobuf.h:32

References jme_ring::bufinf, DBG, jme_ring::desc, jme_ring::dma, ENOMEM, jme_free_tx_resources(), malloc(), malloc_dma(), memset(), RING_DESC_ALIGN, TX_DESC_SIZE, jme_adapter::tx_ring_size, jme_adapter::txring, and virt_to_bus().

Referenced by jme_open().

◆ jme_init_tx_ring()

static void jme_init_tx_ring ( struct jme_adapter jme)
static

Definition at line 312 of file jme.c.

313 {
314  struct jme_ring *txring = &jme->txring;
315 
316  txring->next_to_clean = 0;
317  txring->next_to_use = 0;
318  txring->nr_free = jme->tx_ring_size;
319 
320  /*
321  * Initialize Transmit Descriptors
322  */
323  memset(txring->desc, 0, jme->tx_ring_size * TX_DESC_SIZE);
324  jme_free_tx_buffers(jme);
325 }
uint32_t tx_ring_size
Definition: jme.h:267
void * desc
Definition: jme.h:237
int next_to_use
Definition: jme.h:245
int next_to_clean
Definition: jme.h:243
struct jme_ring txring
Definition: jme.h:266
int nr_free
Definition: jme.h:246
Definition: jme.h:236
static void jme_free_tx_buffers(struct jme_adapter *jme)
Definition: jme.c:238
#define TX_DESC_SIZE
Definition: jme.h:51
void * memset(void *dest, int character, size_t len) __nonnull

References jme_ring::desc, jme_free_tx_buffers(), memset(), jme_ring::next_to_clean, jme_ring::next_to_use, jme_ring::nr_free, TX_DESC_SIZE, jme_adapter::tx_ring_size, and jme_adapter::txring.

Referenced by jme_link_change().

◆ jme_enable_tx_engine()

static void jme_enable_tx_engine ( struct jme_adapter jme)
static

Definition at line 328 of file jme.c.

329 {
330  /*
331  * Select Queue 0
332  */
334  wmb();
335 
336  /*
337  * Setup TX Queue 0 DMA Bass Address
338  */
339  jwrite32(jme, JME_TXDBA_LO, (uint64_t)jme->txring.dma & 0xFFFFFFFFUL);
340  jwrite32(jme, JME_TXDBA_HI, (uint64_t)(jme->txring.dma) >> 32);
341  jwrite32(jme, JME_TXNDA, (uint64_t)jme->txring.dma & 0xFFFFFFFFUL);
342 
343  /*
344  * Setup TX Descptor Count
345  */
346  jwrite32(jme, JME_TXQDC, jme->tx_ring_size);
347 
348  /*
349  * Enable TX Engine
350  */
351  wmb();
352  jwrite32(jme, JME_TXCS, jme->reg_txcs |
354  TXCS_ENABLE);
355 
356 }
wmb()
unsigned long dma
Definition: jme.h:238
static void jwrite32(struct jme_adapter *jme, uint32_t reg, uint32_t val)
Definition: jme.h:901
Definition: jme.h:296
unsigned long long uint64_t
Definition: stdint.h:13
uint32_t tx_ring_size
Definition: jme.h:267
Definition: jme.h:293
Definition: jme.h:297
struct jme_ring txring
Definition: jme.h:266
uint32_t reg_txcs
Definition: jme.h:259

References jme_ring::dma, JME_TXCS, JME_TXDBA_HI, JME_TXDBA_LO, JME_TXNDA, JME_TXQDC, jwrite32(), jme_adapter::reg_txcs, jme_adapter::tx_ring_size, TXCS_DEFAULT, TXCS_ENABLE, TXCS_SELECT_QUEUE0, jme_adapter::txring, and wmb().

Referenced by jme_link_change().

◆ jme_disable_tx_engine()

static void jme_disable_tx_engine ( struct jme_adapter jme)
static

Definition at line 359 of file jme.c.

360 {
361  int i;
362  u32 val;
363 
364  /*
365  * Disable TX Engine
366  */
368  wmb();
369 
370  val = jread32(jme, JME_TXCS);
371  for (i = JME_TX_DISABLE_TIMEOUT ; (val & TXCS_ENABLE) && i > 0 ; --i) {
372  mdelay(1);
373  val = jread32(jme, JME_TXCS);
374  rmb();
375  }
376 
377  if (!i)
378  DBG("Disable TX engine timeout.\n");
379 }
wmb()
static void jwrite32(struct jme_adapter *jme, uint32_t reg, uint32_t val)
Definition: jme.h:901
static uint32_t jread32(struct jme_adapter *jme, uint32_t reg)
Definition: jme.h:896
#define JME_TX_DISABLE_TIMEOUT
Definition: jme.h:386
#define rmb()
Definition: io.h:484
Definition: jme.h:293
void __asmcall int val
Definition: setjmp.h:28
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:78
uint32_t reg_txcs
Definition: jme.h:259
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
uint32_t u32
Definition: stdint.h:23

References DBG, JME_TX_DISABLE_TIMEOUT, JME_TXCS, jread32(), jwrite32(), mdelay(), jme_adapter::reg_txcs, rmb, TXCS_ENABLE, TXCS_SELECT_QUEUE0, val, and wmb().

Referenced by jme_link_change().

◆ jme_set_clean_rxdesc()

static void jme_set_clean_rxdesc ( struct jme_adapter jme,
int  i 
)
static

Definition at line 383 of file jme.c.

384 {
385  struct jme_ring *rxring = &jme->rxring;
386  register struct rxdesc *rxdesc = rxring->desc;
387  struct io_buffer *rxbi = rxring->bufinf[i];
388  uint64_t mapping;
389 
390  rxdesc += i;
391  mapping = virt_to_bus(rxbi->data);
392 
393  rxdesc->dw[0] = 0;
394  rxdesc->dw[1] = 0;
395  rxdesc->desc1.bufaddrh = cpu_to_le32(mapping >> 32);
396  rxdesc->desc1.bufaddrl = cpu_to_le32(mapping & 0xFFFFFFFFUL);
397  rxdesc->desc1.datalen = cpu_to_le16(RX_ALLOC_LEN);
398  wmb();
399  rxdesc->desc1.flags |= RXFLAG_OWN | RXFLAG_INT;
400 }
wmb()
struct rxdesc::@71::@73 desc1
unsigned long long uint64_t
Definition: stdint.h:13
struct io_buffer ** bufinf
Definition: jme.h:241
void * desc
Definition: jme.h:237
uint32_t dw[4]
Definition: jme.h:150
static __always_inline unsigned long virt_to_bus(volatile const void *addr)
Convert virtual address to a bus address.
Definition: io.h:183
#define cpu_to_le32(value)
Definition: byteswap.h:107
Definition: jme.h:236
void * data
Start of data.
Definition: iobuf.h:44
#define RX_ALLOC_LEN
Definition: jme.h:145
#define cpu_to_le16(value)
Definition: byteswap.h:106
struct jme_ring rxring
Definition: jme.h:263
A persistent I/O buffer.
Definition: iobuf.h:32

References jme_ring::bufinf, cpu_to_le16, cpu_to_le32, io_buffer::data, jme_ring::desc, rxdesc::desc1, rxdesc::dw, RX_ALLOC_LEN, RXFLAG_INT, RXFLAG_OWN, jme_adapter::rxring, virt_to_bus(), and wmb().

Referenced by jme_init_rx_ring(), jme_process_receive(), and jme_refill_rx_ring().

◆ jme_make_new_rx_buf()

static int jme_make_new_rx_buf ( struct io_buffer **  rxbip)
static

Definition at line 403 of file jme.c.

404 {
405  struct io_buffer *inbuf;
406 
407  /*
408  * IOB_ALIGN == 2048
409  */
410  inbuf = alloc_iob(RX_ALLOC_LEN);
411  if (!inbuf) {
412  DBG("Allocate receive iob error.\n");
413  return -ENOMEM;
414  }
415  *rxbip = inbuf;
416 
417  return 0;
418 }
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:128
#define ENOMEM
Not enough space.
Definition: errno.h:534
#define RX_ALLOC_LEN
Definition: jme.h:145
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
A persistent I/O buffer.
Definition: iobuf.h:32

References alloc_iob(), DBG, ENOMEM, and RX_ALLOC_LEN.

Referenced by jme_alloc_rx_resources(), and jme_refill_rx_ring().

◆ jme_free_rx_buf()

static void jme_free_rx_buf ( struct jme_adapter jme,
int  i 
)
static

Definition at line 421 of file jme.c.

422 {
423  struct jme_ring *rxring = &jme->rxring;
424  struct io_buffer *rxbi = rxring->bufinf[i];
425 
426  if (rxbi) {
427  free_iob(rxbi);
428  rxring->bufinf[i] = NULL;
429  }
430 }
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:145
struct io_buffer ** bufinf
Definition: jme.h:241
Definition: jme.h:236
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
struct jme_ring rxring
Definition: jme.h:263
A persistent I/O buffer.
Definition: iobuf.h:32

References jme_ring::bufinf, free_iob(), NULL, and jme_adapter::rxring.

Referenced by jme_free_rx_resources().

◆ jme_free_rx_resources()

static void jme_free_rx_resources ( struct jme_adapter jme)
static

Definition at line 433 of file jme.c.

434 {
435  unsigned int i;
436  struct jme_ring *rxring = &jme->rxring;
437 
438  if (rxring->desc) {
439  if (rxring->bufinf) {
440  for (i = 0 ; i < jme->rx_ring_size ; ++i)
441  jme_free_rx_buf(jme, i);
442  free(rxring->bufinf);
443  }
444 
445  free_dma(rxring->desc, jme->rx_ring_size * RX_DESC_SIZE);
446  rxring->desc = NULL;
447  rxring->dma = 0;
448  rxring->bufinf = NULL;
449  }
450  rxring->next_to_fill = 0;
451  rxring->next_to_clean = 0;
452 }
unsigned long dma
Definition: jme.h:238
static void jme_free_rx_buf(struct jme_adapter *jme, int i)
Definition: jme.c:421
struct io_buffer ** bufinf
Definition: jme.h:241
void * desc
Definition: jme.h:237
int next_to_clean
Definition: jme.h:243
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
Definition: jme.h:236
int next_to_fill
Definition: jme.h:244
#define RX_DESC_SIZE
Definition: jme.h:135
uint32_t rx_ring_size
Definition: jme.h:264
static void free_dma(void *ptr, size_t size)
Free memory allocated with malloc_dma()
Definition: malloc.h:81
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
struct jme_ring rxring
Definition: jme.h:263

References jme_ring::bufinf, jme_ring::desc, jme_ring::dma, free, free_dma(), jme_free_rx_buf(), jme_ring::next_to_clean, jme_ring::next_to_fill, NULL, RX_DESC_SIZE, jme_adapter::rx_ring_size, and jme_adapter::rxring.

Referenced by jme_alloc_rx_resources(), jme_close(), and jme_open().

◆ jme_alloc_rx_resources()

static int jme_alloc_rx_resources ( struct jme_adapter jme)
static

Definition at line 455 of file jme.c.

456 {
457  unsigned int i;
458  struct jme_ring *rxring = &jme->rxring;
459  struct io_buffer **bufinf;
460 
461  rxring->desc = malloc_dma(jme->rx_ring_size * RX_DESC_SIZE,
463  if (!rxring->desc) {
464  DBG("Can not allocate receive ring descriptors.\n");
465  goto err_out;
466  }
467 
468  /*
469  * 16 Bytes align
470  */
471  rxring->dma = virt_to_bus(rxring->desc);
472  rxring->bufinf = malloc(sizeof(struct io_buffer *) *
473  jme->rx_ring_size);
474  if (!(rxring->bufinf)) {
475  DBG("Can not allocate receive buffer info.\n");
476  goto err_out;
477  }
478 
479  /*
480  * Initiallize Receive Buffer Pointers
481  */
482  bufinf = rxring->bufinf;
483  memset(bufinf, 0, sizeof(struct io_buffer *) * jme->rx_ring_size);
484  for (i = 0 ; i < jme->rx_ring_size ; ++i) {
485  if (jme_make_new_rx_buf(bufinf))
486  goto err_out;
487  ++bufinf;
488  }
489 
490  return 0;
491 
492 err_out:
494  return -ENOMEM;
495 }
#define RING_DESC_ALIGN
Definition: jme.h:50
unsigned long dma
Definition: jme.h:238
struct io_buffer ** bufinf
Definition: jme.h:241
void * desc
Definition: jme.h:237
static int jme_make_new_rx_buf(struct io_buffer **rxbip)
Definition: jme.c:403
#define ENOMEM
Not enough space.
Definition: errno.h:534
static __always_inline unsigned long virt_to_bus(volatile const void *addr)
Convert virtual address to a bus address.
Definition: io.h:183
static void jme_free_rx_resources(struct jme_adapter *jme)
Definition: jme.c:433
void * malloc(size_t size)
Allocate memory.
Definition: malloc.c:583
Definition: jme.h:236
static void *__malloc malloc_dma(size_t size, size_t phys_align)
Allocate memory for DMA.
Definition: malloc.h:66
#define RX_DESC_SIZE
Definition: jme.h:135
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
uint32_t rx_ring_size
Definition: jme.h:264
struct jme_ring rxring
Definition: jme.h:263
void * memset(void *dest, int character, size_t len) __nonnull
A persistent I/O buffer.
Definition: iobuf.h:32

References jme_ring::bufinf, DBG, jme_ring::desc, jme_ring::dma, ENOMEM, jme_free_rx_resources(), jme_make_new_rx_buf(), malloc(), malloc_dma(), memset(), RING_DESC_ALIGN, RX_DESC_SIZE, jme_adapter::rx_ring_size, jme_adapter::rxring, and virt_to_bus().

Referenced by jme_open().

◆ jme_init_rx_ring()

static void jme_init_rx_ring ( struct jme_adapter jme)
static

Definition at line 498 of file jme.c.

499 {
500  unsigned int i;
501  struct jme_ring *rxring = &jme->rxring;
502 
503  for (i = 0 ; i < jme->rx_ring_size ; ++i)
504  jme_set_clean_rxdesc(jme, i);
505 
506  rxring->next_to_fill = 0;
507  rxring->next_to_clean = 0;
508 }
static void jme_set_clean_rxdesc(struct jme_adapter *jme, int i)
Definition: jme.c:383
int next_to_clean
Definition: jme.h:243
Definition: jme.h:236
int next_to_fill
Definition: jme.h:244
uint32_t rx_ring_size
Definition: jme.h:264
struct jme_ring rxring
Definition: jme.h:263

References jme_set_clean_rxdesc(), jme_ring::next_to_clean, jme_ring::next_to_fill, jme_adapter::rx_ring_size, and jme_adapter::rxring.

Referenced by jme_link_change().

◆ jme_set_multi()

static void jme_set_multi ( struct jme_adapter jme)
static

Definition at line 511 of file jme.c.

512 {
513  /*
514  * Just receive all kind of packet for new.
515  */
517  jwrite32(jme, JME_RXMCS, jme->reg_rxmcs);
518 }
static void jwrite32(struct jme_adapter *jme, uint32_t reg, uint32_t val)
Definition: jme.h:901
uint32_t reg_rxmcs
Definition: jme.h:261
Definition: jme.h:307

References JME_RXMCS, jwrite32(), jme_adapter::reg_rxmcs, RXMCS_ALLFRAME, RXMCS_BRDFRAME, and RXMCS_UNIFRAME.

Referenced by jme_enable_rx_engine().

◆ jme_enable_rx_engine()

static void jme_enable_rx_engine ( struct jme_adapter jme)
static

Definition at line 521 of file jme.c.

522 {
523  /*
524  * Select Queue 0
525  */
526  jwrite32(jme, JME_RXCS, jme->reg_rxcs |
528  wmb();
529 
530  /*
531  * Setup RX DMA Bass Address
532  */
533  jwrite32(jme, JME_RXDBA_LO, (uint64_t)(jme->rxring.dma) & 0xFFFFFFFFUL);
534  jwrite32(jme, JME_RXDBA_HI, (uint64_t)(jme->rxring.dma) >> 32);
535  jwrite32(jme, JME_RXNDA, (uint64_t)(jme->rxring.dma) & 0xFFFFFFFFUL);
536 
537  /*
538  * Setup RX Descriptor Count
539  */
540  jwrite32(jme, JME_RXQDC, jme->rx_ring_size);
541 
542  /*
543  * Setup Unicast Filter
544  */
545  jme_set_multi(jme);
546 
547  /*
548  * Enable RX Engine
549  */
550  wmb();
551  jwrite32(jme, JME_RXCS, jme->reg_rxcs |
553  RXCS_ENABLE |
554  RXCS_QST);
555 }
wmb()
unsigned long dma
Definition: jme.h:238
static void jwrite32(struct jme_adapter *jme, uint32_t reg, uint32_t val)
Definition: jme.h:901
static void jme_set_multi(struct jme_adapter *jme)
Definition: jme.c:511
unsigned long long uint64_t
Definition: stdint.h:13
uint32_t reg_rxcs
Definition: jme.h:260
Definition: jme.h:463
Definition: jme.h:302
Definition: jme.h:306
Definition: jme.h:305
uint32_t rx_ring_size
Definition: jme.h:264
struct jme_ring rxring
Definition: jme.h:263

References jme_ring::dma, JME_RXCS, JME_RXDBA_HI, JME_RXDBA_LO, JME_RXNDA, JME_RXQDC, jme_set_multi(), jwrite32(), jme_adapter::reg_rxcs, jme_adapter::rx_ring_size, RXCS_ENABLE, RXCS_QST, RXCS_QUEUESEL_Q0, jme_adapter::rxring, and wmb().

Referenced by jme_link_change().

◆ jme_restart_rx_engine()

static void jme_restart_rx_engine ( struct jme_adapter jme)
static

Definition at line 558 of file jme.c.

559 {
560  /*
561  * Start RX Engine
562  */
563  jwrite32(jme, JME_RXCS, jme->reg_rxcs |
565  RXCS_ENABLE |
566  RXCS_QST);
567 }
static void jwrite32(struct jme_adapter *jme, uint32_t reg, uint32_t val)
Definition: jme.h:901
uint32_t reg_rxcs
Definition: jme.h:260
Definition: jme.h:463
Definition: jme.h:302

References JME_RXCS, jwrite32(), jme_adapter::reg_rxcs, RXCS_ENABLE, RXCS_QST, and RXCS_QUEUESEL_Q0.

Referenced by jme_poll().

◆ jme_disable_rx_engine()

static void jme_disable_rx_engine ( struct jme_adapter jme)
static

Definition at line 570 of file jme.c.

571 {
572  int i;
573  u32 val;
574 
575  /*
576  * Disable RX Engine
577  */
578  jwrite32(jme, JME_RXCS, jme->reg_rxcs);
579  wmb();
580 
581  val = jread32(jme, JME_RXCS);
582  for (i = JME_RX_DISABLE_TIMEOUT ; (val & RXCS_ENABLE) && i > 0 ; --i) {
583  mdelay(1);
584  val = jread32(jme, JME_RXCS);
585  rmb();
586  }
587 
588  if (!i)
589  DBG("Disable RX engine timeout.\n");
590 
591 }
wmb()
static void jwrite32(struct jme_adapter *jme, uint32_t reg, uint32_t val)
Definition: jme.h:901
static uint32_t jread32(struct jme_adapter *jme, uint32_t reg)
Definition: jme.h:896
uint32_t reg_rxcs
Definition: jme.h:260
Definition: jme.h:302
#define rmb()
Definition: io.h:484
#define JME_RX_DISABLE_TIMEOUT
Definition: jme.h:522
void __asmcall int val
Definition: setjmp.h:28
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:78
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
uint32_t u32
Definition: stdint.h:23

References DBG, JME_RX_DISABLE_TIMEOUT, JME_RXCS, jread32(), jwrite32(), mdelay(), jme_adapter::reg_rxcs, rmb, RXCS_ENABLE, val, and wmb().

Referenced by jme_link_change().

◆ jme_refill_rx_ring()

static void jme_refill_rx_ring ( struct jme_adapter jme,
int  curhole 
)
static

Definition at line 594 of file jme.c.

595 {
596  struct jme_ring *rxring = &jme->rxring;
597  int i = rxring->next_to_fill;
598  struct io_buffer **bufinf = rxring->bufinf;
599  int mask = jme->rx_ring_mask;
600  int limit = jme->rx_ring_size;
601 
602  while (limit--) {
603  if (!bufinf[i]) {
604  if (jme_make_new_rx_buf(bufinf + i))
605  break;
606  jme_set_clean_rxdesc(jme, i);
607  }
608  if (i == curhole)
609  limit = 0;
610  i = (i + 1) & mask;
611  }
612  rxring->next_to_fill = i;
613 }
static void jme_set_clean_rxdesc(struct jme_adapter *jme, int i)
Definition: jme.c:383
struct io_buffer ** bufinf
Definition: jme.h:241
static int jme_make_new_rx_buf(struct io_buffer **rxbip)
Definition: jme.c:403
uint32_t rx_ring_mask
Definition: jme.h:265
uint16_t limit
Limit.
Definition: librm.h:250
Definition: jme.h:236
int next_to_fill
Definition: jme.h:244
uint32_t rx_ring_size
Definition: jme.h:264
struct jme_ring rxring
Definition: jme.h:263
A persistent I/O buffer.
Definition: iobuf.h:32

References jme_ring::bufinf, jme_make_new_rx_buf(), jme_set_clean_rxdesc(), limit, jme_ring::next_to_fill, jme_adapter::rx_ring_mask, jme_adapter::rx_ring_size, and jme_adapter::rxring.

Referenced by jme_alloc_and_feed_iob().

◆ jme_alloc_and_feed_iob()

static void jme_alloc_and_feed_iob ( struct jme_adapter jme,
int  idx 
)
static

Definition at line 616 of file jme.c.

617 {
618  struct jme_ring *rxring = &jme->rxring;
619  struct rxdesc *rxdesc = rxring->desc;
620  struct io_buffer *rxbi = rxring->bufinf[idx];
621  struct net_device *netdev = jme->mii_if.dev;
622  int framesize;
623 
624  rxdesc += idx;
625 
626  framesize = le16_to_cpu(rxdesc->descwb.framesize);
627  iob_put(rxbi, framesize);
628  netdev_rx(netdev, rxbi);
629 
630  rxring->bufinf[idx] = NULL;
631  jme_refill_rx_ring(jme, idx);
632 }
struct net_device * dev
Definition: mii.h:152
#define iob_put(iobuf, len)
Definition: iobuf.h:116
struct mii_if_info mii_if
Definition: jme.h:254
struct io_buffer ** bufinf
Definition: jme.h:241
void * desc
Definition: jme.h:237
static void jme_refill_rx_ring(struct jme_adapter *jme, int curhole)
Definition: jme.c:594
static struct net_device * netdev
Definition: gdbudp.c:52
struct rxdesc::@71::@74 descwb
A network device.
Definition: netdevice.h:348
#define le16_to_cpu(value)
Definition: byteswap.h:112
void netdev_rx(struct net_device *netdev, struct io_buffer *iobuf)
Add packet to receive queue.
Definition: netdevice.c:470
Definition: jme.h:236
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
struct jme_ring rxring
Definition: jme.h:263
A persistent I/O buffer.
Definition: iobuf.h:32

References jme_ring::bufinf, jme_ring::desc, rxdesc::descwb, mii_if_info::dev, iob_put, jme_refill_rx_ring(), le16_to_cpu, jme_adapter::mii_if, netdev, netdev_rx(), NULL, and jme_adapter::rxring.

Referenced by jme_process_receive().

◆ jme_process_receive()

static void jme_process_receive ( struct jme_adapter jme)
static

Definition at line 635 of file jme.c.

636 {
637  struct jme_ring *rxring = &jme->rxring;
638  struct rxdesc *rxdesc = rxring->desc;
639  struct net_device *netdev = jme->mii_if.dev;
640  int i, j, ccnt, desccnt, mask = jme->rx_ring_mask;
641  unsigned int limit = jme->rx_ring_size;
642 
643  i = rxring->next_to_clean;
644  rxdesc += i;
645  while (rxring->bufinf[i] &&
646  !(rxdesc->descwb.flags & cpu_to_le16(RXWBFLAG_OWN)) &&
647  (rxdesc->descwb.desccnt & RXWBDCNT_WBCPL) &&
648  limit--) {
649 
650  rmb();
651  desccnt = rxdesc->descwb.desccnt & RXWBDCNT_DCNT;
652  DBG2("Cleaning rx desc=%d, cnt=%d\n", i, desccnt);
653 
654  if (desccnt > 1 || rxdesc->descwb.errstat & RXWBERR_ALLERR) {
655  for (j = i, ccnt = desccnt ; ccnt-- ; ) {
656  jme_set_clean_rxdesc(jme, j);
657  j = (j + 1) & (mask);
658  }
659  DBG("Dropped packet due to ");
660  if (desccnt > 1)
661  DBG("long packet.(%d descriptors)\n", desccnt);
662  else
663  DBG("Packet error.\n");
665  } else {
666  jme_alloc_and_feed_iob(jme, i);
667  }
668 
669  i = (i + desccnt) & (mask);
670  rxdesc = rxring->desc;
671  rxdesc += i;
672  }
673  rxring->next_to_clean = i;
674 
675  return;
676 }
#define EINVAL
Invalid argument.
Definition: errno.h:428
struct net_device * dev
Definition: mii.h:152
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition: netdevice.c:501
static void jme_set_clean_rxdesc(struct jme_adapter *jme, int i)
Definition: jme.c:383
struct mii_if_info mii_if
Definition: jme.h:254
struct io_buffer ** bufinf
Definition: jme.h:241
void * desc
Definition: jme.h:237
uint32_t rx_ring_mask
Definition: jme.h:265
#define rmb()
Definition: io.h:484
int next_to_clean
Definition: jme.h:243
static struct net_device * netdev
Definition: gdbudp.c:52
struct rxdesc::@71::@74 descwb
uint16_t limit
Limit.
Definition: librm.h:250
A network device.
Definition: netdevice.h:348
static void jme_alloc_and_feed_iob(struct jme_adapter *jme, int idx)
Definition: jme.c:616
Definition: jme.h:236
#define cpu_to_le16(value)
Definition: byteswap.h:106
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
uint32_t rx_ring_size
Definition: jme.h:264
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
struct jme_ring rxring
Definition: jme.h:263
#define DBG2(...)
Definition: compiler.h:515

References jme_ring::bufinf, cpu_to_le16, DBG, DBG2, jme_ring::desc, rxdesc::descwb, mii_if_info::dev, EINVAL, jme_alloc_and_feed_iob(), jme_set_clean_rxdesc(), limit, jme_adapter::mii_if, netdev, netdev_rx_err(), jme_ring::next_to_clean, NULL, rmb, jme_adapter::rx_ring_mask, jme_adapter::rx_ring_size, jme_adapter::rxring, RXWBDCNT_DCNT, RXWBDCNT_WBCPL, RXWBERR_ALLERR, and RXWBFLAG_OWN.

Referenced by jme_poll().

◆ jme_set_custom_macaddr()

static void jme_set_custom_macaddr ( struct net_device netdev)
static

Definition at line 679 of file jme.c.

680 {
681  struct jme_adapter *jme = netdev->priv;
683  u32 val;
684 
685  val = (addr[3] & 0xff) << 24 |
686  (addr[2] & 0xff) << 16 |
687  (addr[1] & 0xff) << 8 |
688  (addr[0] & 0xff);
689  jwrite32(jme, JME_RXUMA_LO, val);
690  val = (addr[5] & 0xff) << 8 |
691  (addr[4] & 0xff);
692  jwrite32(jme, JME_RXUMA_HI, val);
693 }
static void jwrite32(struct jme_adapter *jme, uint32_t reg, uint32_t val)
Definition: jme.h:901
void * priv
Driver private data.
Definition: netdevice.h:425
static struct net_device * netdev
Definition: gdbudp.c:52
u32 addr
Definition: sky2.h:8
unsigned char uint8_t
Definition: stdint.h:10
void __asmcall int val
Definition: setjmp.h:28
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:381
uint32_t u32
Definition: stdint.h:23

References addr, JME_RXUMA_HI, JME_RXUMA_LO, jwrite32(), net_device::ll_addr, netdev, net_device::priv, and val.

Referenced by jme_open().

◆ jme_open()

static int jme_open ( struct net_device netdev)
static

Open NIC.

Parameters
netdevNet device
Return values
rcReturn status code

Definition at line 702 of file jme.c.

703 {
704  struct jme_adapter *jme = netdev->priv;
705  int rc;
706 
707  /*
708  * Allocate receive resources
709  */
710  rc = jme_alloc_rx_resources(jme);
711  if (rc) {
712  DBG("Allocate receive resources error.\n");
713  goto nomem_out;
714  }
715 
716  /*
717  * Allocate transmit resources
718  */
719  rc = jme_alloc_tx_resources(jme);
720  if (rc) {
721  DBG("Allocate transmit resources error.\n");
722  goto free_rx_resources_out;
723  }
724 
727  jme_restart_an(jme);
728 
729  return 0;
730 
731 free_rx_resources_out:
733 nomem_out:
734  return rc;
735 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static void jme_set_custom_macaddr(struct net_device *netdev)
Definition: jme.c:679
static void jme_restart_an(struct jme_adapter *jme)
Definition: jme.c:148
static void jme_reset_phy_processor(struct jme_adapter *jme)
Definition: jme.c:94
static int jme_alloc_tx_resources(struct jme_adapter *jme)
Definition: jme.c:276
void * priv
Driver private data.
Definition: netdevice.h:425
static struct net_device * netdev
Definition: gdbudp.c:52
static int jme_alloc_rx_resources(struct jme_adapter *jme)
Definition: jme.c:455
static void jme_free_rx_resources(struct jme_adapter *jme)
Definition: jme.c:433
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498

References DBG, jme_alloc_rx_resources(), jme_alloc_tx_resources(), jme_free_rx_resources(), jme_reset_phy_processor(), jme_restart_an(), jme_set_custom_macaddr(), netdev, net_device::priv, and rc.

◆ jme_close()

static void jme_close ( struct net_device netdev)
static

Close NIC.

Parameters
netdevNet device

Definition at line 743 of file jme.c.

744 {
745  struct jme_adapter *jme = netdev->priv;
746 
750  jme->phylink = 0;
751  jme_phy_off(jme);
753 }
static void jme_phy_off(struct jme_adapter *jme)
Definition: jme.c:142
void netdev_link_down(struct net_device *netdev)
Mark network device as having link down.
Definition: netdevice.c:186
void * priv
Driver private data.
Definition: netdevice.h:425
static struct net_device * netdev
Definition: gdbudp.c:52
static void jme_free_rx_resources(struct jme_adapter *jme)
Definition: jme.c:433
static void jme_reset_mac_processor(struct jme_adapter *jme)
Definition: jme.c:210
uint32_t phylink
Definition: jme.h:262
static void jme_free_tx_resources(struct jme_adapter *jme)
Definition: jme.c:255

References jme_free_rx_resources(), jme_free_tx_resources(), jme_phy_off(), jme_reset_mac_processor(), netdev, netdev_link_down(), jme_adapter::phylink, and net_device::priv.

◆ jme_alloc_txdesc()

static int jme_alloc_txdesc ( struct jme_adapter jme)
static

Definition at line 756 of file jme.c.

757 {
758  struct jme_ring *txring = &jme->txring;
759  int idx;
760 
761  idx = txring->next_to_use;
762  if (txring->nr_free < 1)
763  return -1;
764  --(txring->nr_free);
765  txring->next_to_use = (txring->next_to_use + 1) & jme->tx_ring_mask;
766 
767  return idx;
768 }
int next_to_use
Definition: jme.h:245
uint32_t tx_ring_mask
Definition: jme.h:268
struct jme_ring txring
Definition: jme.h:266
int nr_free
Definition: jme.h:246
Definition: jme.h:236

References jme_ring::next_to_use, jme_ring::nr_free, jme_adapter::tx_ring_mask, and jme_adapter::txring.

Referenced by jme_transmit().

◆ jme_fill_tx_desc()

static void jme_fill_tx_desc ( struct jme_adapter jme,
struct io_buffer iob,
int  idx 
)
static

Definition at line 771 of file jme.c.

772 {
773  struct jme_ring *txring = &jme->txring;
774  struct txdesc *txdesc = txring->desc;
775  uint16_t len = iob_len(iob);
776  unsigned long int mapping;
777 
778  txdesc += idx;
779  mapping = virt_to_bus(iob->data);
780  DBG2("TX buffer address: %p(%08lx+%x)\n",
781  iob->data, mapping, len);
782  txdesc->dw[0] = 0;
783  txdesc->dw[1] = 0;
784  txdesc->dw[2] = 0;
785  txdesc->dw[3] = 0;
786  txdesc->desc1.datalen = cpu_to_le16(len);
787  txdesc->desc1.pktsize = cpu_to_le16(len);
788  txdesc->desc1.bufaddr = cpu_to_le32(mapping);
789  /*
790  * Set OWN bit at final.
791  * When kernel transmit faster than NIC.
792  * And NIC trying to send this descriptor before we tell
793  * it to start sending this TX queue.
794  * Other fields are already filled correctly.
795  */
796  wmb();
797  txdesc->desc1.flags = TXFLAG_OWN | TXFLAG_INT;
798  /*
799  * Set tx buffer info after telling NIC to send
800  * For better tx_clean timing
801  */
802  wmb();
803  txring->bufinf[idx] = iob;
804 }
unsigned short uint16_t
Definition: stdint.h:11
wmb()
uint32_t dw[4]
Definition: jme.h:56
struct io_buffer ** bufinf
Definition: jme.h:241
void * desc
Definition: jme.h:237
static __always_inline unsigned long virt_to_bus(volatile const void *addr)
Convert virtual address to a bus address.
Definition: io.h:183
#define cpu_to_le32(value)
Definition: byteswap.h:107
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:151
struct jme_ring txring
Definition: jme.h:266
Definition: jme.h:236
uint32_t len
Length.
Definition: ena.h:14
void * data
Start of data.
Definition: iobuf.h:44
#define cpu_to_le16(value)
Definition: byteswap.h:106
struct txdesc::@66::@68 desc1
#define DBG2(...)
Definition: compiler.h:515

References jme_ring::bufinf, cpu_to_le16, cpu_to_le32, io_buffer::data, DBG2, jme_ring::desc, txdesc::desc1, txdesc::dw, iob_len(), len, TXFLAG_INT, TXFLAG_OWN, jme_adapter::txring, virt_to_bus(), and wmb().

Referenced by jme_transmit().

◆ jme_transmit()

static int jme_transmit ( struct net_device netdev,
struct io_buffer iobuf 
)
static

Transmit packet.

Parameters
netdevNetwork device
iobufI/O buffer
Return values
rcReturn status code

Definition at line 814 of file jme.c.

815 {
816  struct jme_adapter *jme = netdev->priv;
817  int idx;
818 
819  idx = jme_alloc_txdesc(jme);
820  if (idx < 0) {
821  /*
822  * Pause transmit queue somehow if possible.
823  */
824  DBG("TX ring full!\n");
825  return -EOVERFLOW;
826  }
827 
828  jme_fill_tx_desc(jme, iobuf, idx);
829 
830  jwrite32(jme, JME_TXCS, jme->reg_txcs |
832  TXCS_QUEUE0S |
833  TXCS_ENABLE);
834  DBG2("xmit: idx=%d\n", idx);
835 
836  return 0;
837 }
static void jwrite32(struct jme_adapter *jme, uint32_t reg, uint32_t val)
Definition: jme.h:901
Definition: jme.h:293
void * priv
Driver private data.
Definition: netdevice.h:425
static struct net_device * netdev
Definition: gdbudp.c:52
#define EOVERFLOW
Value too large to be stored in data type.
Definition: errno.h:609
static int jme_alloc_txdesc(struct jme_adapter *jme)
Definition: jme.c:756
uint32_t reg_txcs
Definition: jme.h:259
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
static void jme_fill_tx_desc(struct jme_adapter *jme, struct io_buffer *iob, int idx)
Definition: jme.c:771
#define DBG2(...)
Definition: compiler.h:515

References DBG, DBG2, EOVERFLOW, jme_alloc_txdesc(), jme_fill_tx_desc(), JME_TXCS, jwrite32(), netdev, net_device::priv, jme_adapter::reg_txcs, TXCS_ENABLE, TXCS_QUEUE0S, and TXCS_SELECT_QUEUE0.

◆ jme_check_link()

static int jme_check_link ( struct net_device netdev,
int  testonly 
)
static

Definition at line 840 of file jme.c.

841 {
842  struct jme_adapter *jme = netdev->priv;
843  u32 phylink, ghc, cnt = JME_SPDRSV_TIMEOUT, gpreg1;
844  int rc = 0;
845 
846  phylink = jread32(jme, JME_PHY_LINK);
847 
848  if (phylink & PHY_LINK_UP) {
849  /*
850  * Keep polling for speed/duplex resolve complete
851  */
852  while (!(phylink & PHY_LINK_SPEEDDPU_RESOLVED) &&
853  --cnt) {
854 
855  udelay(1);
856  phylink = jread32(jme, JME_PHY_LINK);
857  }
858  if (!cnt)
859  DBG("Waiting speed resolve timeout.\n");
860 
861  if (jme->phylink == phylink) {
862  rc = 1;
863  goto out;
864  }
865  if (testonly)
866  goto out;
867 
868  jme->phylink = phylink;
869 
870  ghc = jme->reg_ghc & ~(GHC_SPEED | GHC_DPX |
873  switch (phylink & PHY_LINK_SPEED_MASK) {
874  case PHY_LINK_SPEED_10M:
875  ghc |= GHC_SPEED_10M |
877  break;
878  case PHY_LINK_SPEED_100M:
879  ghc |= GHC_SPEED_100M |
881  break;
883  ghc |= GHC_SPEED_1000M |
885  break;
886  default:
887  break;
888  }
889 
890  if (phylink & PHY_LINK_DUPLEX) {
892  ghc |= GHC_DPX;
893  } else {
895  TXMCS_BACKOFF |
899  ((0x2000 << TXTRHD_TXP_SHIFT) & TXTRHD_TXP) |
900  TXTRHD_TXREN |
901  ((8 << TXTRHD_TXRL_SHIFT) & TXTRHD_TXRL));
902  }
903 
904  gpreg1 = GPREG1_DEFAULT;
905  if (is_buggy250(jme->pdev->device, jme->chiprev)) {
906  if (!(phylink & PHY_LINK_DUPLEX))
907  gpreg1 |= GPREG1_HALFMODEPATCH;
908  switch (phylink & PHY_LINK_SPEED_MASK) {
909  case PHY_LINK_SPEED_10M:
910  jme_set_phyfifoa(jme);
911  gpreg1 |= GPREG1_RSSPATCH;
912  break;
913  case PHY_LINK_SPEED_100M:
914  jme_set_phyfifob(jme);
915  gpreg1 |= GPREG1_RSSPATCH;
916  break;
918  jme_set_phyfifoa(jme);
919  break;
920  default:
921  break;
922  }
923  }
924 
925  jwrite32(jme, JME_GPREG1, gpreg1);
926  jwrite32(jme, JME_GHC, ghc);
927  jme->reg_ghc = ghc;
928 
929  DBG("Link is up at %d Mbps, %s-Duplex, MDI%s.\n",
931  == PHY_LINK_SPEED_1000M) ? 1000 :
933  == PHY_LINK_SPEED_100M) ? 100 : 10,
934  (phylink & PHY_LINK_DUPLEX) ? "Full" : "Half",
935  (phylink & PHY_LINK_MDI_STAT) ? "-X" : "");
937  } else {
938  if (testonly)
939  goto out;
940 
941  DBG("Link is down.\n");
942  jme->phylink = 0;
944  }
945 
946 out:
947  return rc;
948 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static void jme_set_phyfifoa(struct jme_adapter *jme)
Definition: jme.c:130
static void jwrite32(struct jme_adapter *jme, uint32_t reg, uint32_t val)
Definition: jme.h:901
static uint32_t jread32(struct jme_adapter *jme, uint32_t reg)
Definition: jme.h:896
void netdev_link_down(struct net_device *netdev)
Mark network device as having link down.
Definition: netdevice.c:186
uint16_t device
Device ID.
Definition: pci.h:204
void * priv
Driver private data.
Definition: netdevice.h:425
#define JME_SPDRSV_TIMEOUT
Definition: jme.h:672
static void netdev_link_up(struct net_device *netdev)
Mark network device as having link up.
Definition: netdevice.h:768
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
Definition: jme.h:316
__be32 out[4]
Definition: CIB_PRM.h:36
uint32_t reg_ghc
Definition: jme.h:258
struct pci_device * pdev
Definition: jme.h:255
Definition: jme.h:601
Definition: jme.h:298
Definition: jme.h:602
uint32_t phylink
Definition: jme.h:262
static void jme_set_phyfifob(struct jme_adapter *jme)
Definition: jme.c:136
unsigned int chiprev
Definition: jme.h:257
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
uint32_t u32
Definition: stdint.h:23
static int is_buggy250(unsigned short device, unsigned int chiprev)
Definition: jme.h:888

References jme_adapter::chiprev, DBG, pci_device::device, GHC_DPX, GHC_SPEED, GHC_SPEED_1000M, GHC_SPEED_100M, GHC_SPEED_10M, GHC_TO_CLK_GPHY, GHC_TO_CLK_PCIE, GHC_TXMAC_CLK_GPHY, GHC_TXMAC_CLK_PCIE, GPREG1_DEFAULT, GPREG1_HALFMODEPATCH, GPREG1_RSSPATCH, is_buggy250(), JME_GHC, JME_GPREG1, JME_PHY_LINK, jme_set_phyfifoa(), jme_set_phyfifob(), JME_SPDRSV_TIMEOUT, JME_TXMCS, JME_TXTRHD, jread32(), jwrite32(), netdev, netdev_link_down(), netdev_link_up(), out, jme_adapter::pdev, PHY_LINK_DUPLEX, PHY_LINK_MDI_STAT, PHY_LINK_SPEED_1000M, PHY_LINK_SPEED_100M, PHY_LINK_SPEED_10M, PHY_LINK_SPEED_MASK, PHY_LINK_SPEEDDPU_RESOLVED, PHY_LINK_UP, jme_adapter::phylink, net_device::priv, rc, jme_adapter::reg_ghc, TXMCS_BACKOFF, TXMCS_CARRIERSENSE, TXMCS_COLLISION, TXMCS_DEFAULT, TXTRHD_TXP, TXTRHD_TXP_SHIFT, TXTRHD_TXPEN, TXTRHD_TXREN, TXTRHD_TXRL, TXTRHD_TXRL_SHIFT, and udelay().

Referenced by jme_link_change().

◆ jme_link_change()

static void jme_link_change ( struct net_device netdev)
static

Definition at line 951 of file jme.c.

952 {
953  struct jme_adapter *jme = netdev->priv;
954 
955  /*
956  * Do nothing if the link status did not change.
957  */
958  if (jme_check_link(netdev, 1))
959  return;
960 
961  if (netdev_link_ok(netdev)) {
965  jme_reset_ghc_speed(jme);
967  }
968 
970  if (netdev_link_ok(netdev)) {
971  jme_init_rx_ring(jme);
973  jme_init_tx_ring(jme);
975  }
976 
977  return;
978 }
static void jme_enable_tx_engine(struct jme_adapter *jme)
Definition: jme.c:328
static void jme_reset_ghc_speed(struct jme_adapter *jme)
Definition: jme.c:158
static void jme_disable_tx_engine(struct jme_adapter *jme)
Definition: jme.c:359
static void jme_disable_rx_engine(struct jme_adapter *jme)
Definition: jme.c:570
void netdev_link_down(struct net_device *netdev)
Mark network device as having link down.
Definition: netdevice.c:186
static void jme_init_rx_ring(struct jme_adapter *jme)
Definition: jme.c:498
void * priv
Driver private data.
Definition: netdevice.h:425
static int netdev_link_ok(struct net_device *netdev)
Check link state of network device.
Definition: netdevice.h:630
static struct net_device * netdev
Definition: gdbudp.c:52
static int jme_check_link(struct net_device *netdev, int testonly)
Definition: jme.c:840
static void jme_reset_mac_processor(struct jme_adapter *jme)
Definition: jme.c:210
static void jme_enable_rx_engine(struct jme_adapter *jme)
Definition: jme.c:521
static void jme_init_tx_ring(struct jme_adapter *jme)
Definition: jme.c:312

References jme_check_link(), jme_disable_rx_engine(), jme_disable_tx_engine(), jme_enable_rx_engine(), jme_enable_tx_engine(), jme_init_rx_ring(), jme_init_tx_ring(), jme_reset_ghc_speed(), jme_reset_mac_processor(), netdev, netdev_link_down(), netdev_link_ok(), and net_device::priv.

Referenced by jme_poll().

◆ jme_tx_clean()

static void jme_tx_clean ( struct jme_adapter jme)
static

Definition at line 981 of file jme.c.

982 {
983  struct jme_ring *txring = &jme->txring;
984  struct txdesc *txdesc = txring->desc;
985  struct io_buffer *txbi;
986  struct net_device *netdev = jme->mii_if.dev;
987  int i, cnt = 0, max, err, mask;
988 
989  max = jme->tx_ring_size - txring->nr_free;
990  mask = jme->tx_ring_mask;
991 
992  for (i = txring->next_to_clean ; cnt < max ; ++cnt) {
993 
994  txbi = txring->bufinf[i];
995 
996  if (txbi && !(txdesc[i].descwb.flags & TXWBFLAG_OWN)) {
997  DBG2("TX clean address: %08lx(%08lx+%zx)\n",
998  (unsigned long)txbi->data,
999  virt_to_bus(txbi->data),
1000  iob_len(txbi));
1001  err = txdesc[i].descwb.flags & TXWBFLAG_ALLERR;
1002  if (err)
1004  else
1005  netdev_tx_complete(netdev, txbi);
1006  txring->bufinf[i] = NULL;
1007  } else {
1008  break;
1009  }
1010 
1011  i = (i + 1) & mask;
1012  }
1013 
1014  DBG2("txclean: next %d\n", i);
1015  txring->next_to_clean = i;
1016  txring->nr_free += cnt;
1017 }
struct net_device * dev
Definition: mii.h:152
static void netdev_tx_complete(struct net_device *netdev, struct io_buffer *iobuf)
Complete network transmission.
Definition: netdevice.h:746
#define max(x, y)
Definition: ath.h:39
struct mii_if_info mii_if
Definition: jme.h:254
uint32_t tx_ring_size
Definition: jme.h:267
struct io_buffer ** bufinf
Definition: jme.h:241
void * desc
Definition: jme.h:237
static __always_inline unsigned long virt_to_bus(volatile const void *addr)
Convert virtual address to a bus address.
Definition: io.h:183
int next_to_clean
Definition: jme.h:243
uint32_t tx_ring_mask
Definition: jme.h:268
uint8_t flags
Definition: jme.h:61
static struct net_device * netdev
Definition: gdbudp.c:52
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:151
A network device.
Definition: netdevice.h:348
struct jme_ring txring
Definition: jme.h:266
int nr_free
Definition: jme.h:246
void netdev_tx_complete_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Complete network transmission.
Definition: netdevice.c:395
Definition: jme.h:236
void * data
Start of data.
Definition: iobuf.h:44
#define EIO
Input/output error.
Definition: errno.h:433
struct txdesc::@66::@70 descwb
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
#define DBG2(...)
Definition: compiler.h:515
A persistent I/O buffer.
Definition: iobuf.h:32

References jme_ring::bufinf, io_buffer::data, DBG2, jme_ring::desc, txdesc::descwb, mii_if_info::dev, EIO, txdesc::flags, iob_len(), max, jme_adapter::mii_if, netdev, netdev_tx_complete(), netdev_tx_complete_err(), jme_ring::next_to_clean, jme_ring::nr_free, NULL, jme_adapter::tx_ring_mask, jme_adapter::tx_ring_size, jme_adapter::txring, TXWBFLAG_ALLERR, TXWBFLAG_OWN, and virt_to_bus().

Referenced by jme_poll().

◆ jme_poll()

static void jme_poll ( struct net_device netdev)
static

Poll for received packets.

Parameters
netdevNetwork device

Definition at line 1024 of file jme.c.

1025 {
1026  struct jme_adapter *jme = netdev->priv;
1027  u32 intrstat;
1028 
1029  intrstat = jread32(jme, JME_IEVE);
1030 
1031  /*
1032  * Check if any actions needs to perform.
1033  */
1034  if ((intrstat & INTR_ENABLE) == 0)
1035  return;
1036 
1037  /*
1038  * Check if the device still exist
1039  */
1040  if (intrstat == ~((typeof(intrstat))0))
1041  return;
1042 
1043  DBG2("intrstat 0x%08x\n", intrstat);
1044  if (intrstat & (INTR_LINKCH | INTR_SWINTR)) {
1045  DBG2("Link changed\n");
1047 
1048  /*
1049  * Clear all interrupt status
1050  */
1051  jwrite32(jme, JME_IEVE, intrstat);
1052 
1053  /*
1054  * Link change event is critical
1055  * all other events are ignored
1056  */
1057  return;
1058  }
1059 
1060  /*
1061  * Process transmission complete first to free more memory.
1062  */
1063  if (intrstat & INTR_TX0) {
1064  DBG2("Packet transmit complete\n");
1065  jme_tx_clean(jme);
1066  jwrite32(jme, JME_IEVE, intrstat & INTR_TX0);
1067  }
1068 
1069  if (intrstat & (INTR_RX0 | INTR_RX0EMP)) {
1070  DBG2("Packet received\n");
1071  jme_process_receive(jme);
1072  jwrite32(jme, JME_IEVE,
1073  intrstat & (INTR_RX0 | INTR_RX0EMP));
1074  if (intrstat & INTR_RX0EMP)
1075  jme_restart_rx_engine(jme);
1076  }
1077 
1078  /*
1079  * Clean all other interrupt status
1080  */
1081  jwrite32(jme, JME_IEVE,
1082  intrstat & ~(INTR_RX0 | INTR_RX0EMP | INTR_TX0));
1083 }
static void jwrite32(struct jme_adapter *jme, uint32_t reg, uint32_t val)
Definition: jme.h:901
static void jme_tx_clean(struct jme_adapter *jme)
Definition: jme.c:981
Definition: jme.h:828
static uint32_t jread32(struct jme_adapter *jme, uint32_t reg)
Definition: jme.h:896
void * priv
Driver private data.
Definition: netdevice.h:425
static void jme_process_receive(struct jme_adapter *jme)
Definition: jme.c:635
static struct net_device * netdev
Definition: gdbudp.c:52
static void jme_link_change(struct net_device *netdev)
Definition: jme.c:951
static const uint32_t INTR_ENABLE
Definition: jme.h:831
Definition: jme.h:820
Definition: jme.h:329
static void jme_restart_rx_engine(struct jme_adapter *jme)
Definition: jme.c:558
uint32_t u32
Definition: stdint.h:23
#define DBG2(...)
Definition: compiler.h:515

References DBG2, INTR_ENABLE, INTR_LINKCH, INTR_RX0, INTR_RX0EMP, INTR_SWINTR, INTR_TX0, JME_IEVE, jme_link_change(), jme_process_receive(), jme_restart_rx_engine(), jme_tx_clean(), jread32(), jwrite32(), netdev, and net_device::priv.

◆ jme_irq()

static void jme_irq ( struct net_device netdev,
int  enable 
)
static

Enable/disable interrupts.

Parameters
netdevNetwork device
enableInterrupts should be enabled

Definition at line 1092 of file jme.c.

1093 {
1094  struct jme_adapter *jme = netdev->priv;
1095 
1096  DBG("jme interrupts %s\n", (enable ? "enabled" : "disabled"));
1097  if (enable)
1098  jme_start_irq(jme);
1099  else
1100  jme_stop_irq(jme);
1101 }
void * priv
Driver private data.
Definition: netdevice.h:425
static struct net_device * netdev
Definition: gdbudp.c:52
static void jme_stop_irq(struct jme_adapter *jme)
Definition: jme.c:174
static void jme_start_irq(struct jme_adapter *jme)
Definition: jme.c:165
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498

References DBG, jme_start_irq(), jme_stop_irq(), netdev, and net_device::priv.

◆ jme_check_hw_ver()

static void jme_check_hw_ver ( struct jme_adapter jme)
static

Definition at line 1113 of file jme.c.

1114 {
1115  u32 chipmode;
1116 
1117  chipmode = jread32(jme, JME_CHIPMODE);
1118 
1119  jme->fpgaver = (chipmode & CM_FPGAVER_MASK) >> CM_FPGAVER_SHIFT;
1120  jme->chiprev = (chipmode & CM_CHIPREV_MASK) >> CM_CHIPREV_SHIFT;
1121 }
static uint32_t jread32(struct jme_adapter *jme, uint32_t reg)
Definition: jme.h:896
unsigned int fpgaver
Definition: jme.h:256
unsigned int chiprev
Definition: jme.h:257
uint32_t u32
Definition: stdint.h:23

References jme_adapter::chiprev, CM_CHIPREV_MASK, CM_CHIPREV_SHIFT, CM_FPGAVER_MASK, CM_FPGAVER_SHIFT, jme_adapter::fpgaver, JME_CHIPMODE, and jread32().

Referenced by jme_probe().

◆ jme_reload_eeprom()

static int jme_reload_eeprom ( struct jme_adapter jme)
static

Definition at line 1124 of file jme.c.

1125 {
1126  u32 val;
1127  int i;
1128 
1129  val = jread32(jme, JME_SMBCSR);
1130 
1131  if (val & SMBCSR_EEPROMD) {
1132  val |= SMBCSR_CNACK;
1133  jwrite32(jme, JME_SMBCSR, val);
1134  val |= SMBCSR_RELOAD;
1135  jwrite32(jme, JME_SMBCSR, val);
1136  mdelay(12);
1137 
1138  for (i = JME_EEPROM_RELOAD_TIMEOUT; i > 0; --i) {
1139  mdelay(1);
1140  if ((jread32(jme, JME_SMBCSR) & SMBCSR_RELOAD) == 0)
1141  break;
1142  }
1143 
1144  if (i == 0) {
1145  DBG("eeprom reload timeout\n");
1146  return -EIO;
1147  }
1148  }
1149 
1150  return 0;
1151 }
static void jwrite32(struct jme_adapter *jme, uint32_t reg, uint32_t val)
Definition: jme.h:901
static uint32_t jread32(struct jme_adapter *jme, uint32_t reg)
Definition: jme.h:896
void __asmcall int val
Definition: setjmp.h:28
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:78
#define EIO
Input/output error.
Definition: errno.h:433
#define JME_EEPROM_RELOAD_TIMEOUT
Definition: jme.h:708
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
uint32_t u32
Definition: stdint.h:23

References DBG, EIO, JME_EEPROM_RELOAD_TIMEOUT, JME_SMBCSR, jread32(), jwrite32(), mdelay(), SMBCSR_CNACK, SMBCSR_EEPROMD, SMBCSR_RELOAD, and val.

Referenced by jme_probe().

◆ jme_load_macaddr()

static void jme_load_macaddr ( struct net_device netdev)
static

Definition at line 1154 of file jme.c.

1155 {
1156  struct jme_adapter *jme = netdev_priv(netdev);
1157  unsigned char macaddr[6];
1158  u32 val;
1159 
1160  val = jread32(jme, JME_RXUMA_LO);
1161  macaddr[0] = (val >> 0) & 0xFF;
1162  macaddr[1] = (val >> 8) & 0xFF;
1163  macaddr[2] = (val >> 16) & 0xFF;
1164  macaddr[3] = (val >> 24) & 0xFF;
1165  val = jread32(jme, JME_RXUMA_HI);
1166  macaddr[4] = (val >> 0) & 0xFF;
1167  macaddr[5] = (val >> 8) & 0xFF;
1168  memcpy(netdev->hw_addr, macaddr, 6);
1169 }
static void * netdev_priv(struct net_device *netdev)
Get driver private area for this network device.
Definition: netdevice.h:566
static uint32_t jread32(struct jme_adapter *jme, uint32_t reg)
Definition: jme.h:896
void * memcpy(void *dest, const void *src, size_t len) __nonnull
static struct net_device * netdev
Definition: gdbudp.c:52
void __asmcall int val
Definition: setjmp.h:28
uint8_t hw_addr[MAX_HW_ADDR_LEN]
Hardware address.
Definition: netdevice.h:375
uint32_t u32
Definition: stdint.h:23

References net_device::hw_addr, JME_RXUMA_HI, JME_RXUMA_LO, jread32(), memcpy(), netdev, netdev_priv(), and val.

Referenced by jme_probe().

◆ jme_probe()

static int jme_probe ( struct pci_device pci)
static

Probe PCI device.

Parameters
pciPCI device
idPCI ID
Return values
rcReturn status code

Definition at line 1179 of file jme.c.

1180 {
1181  struct net_device *netdev;
1182  struct jme_adapter *jme;
1183  int rc;
1184  uint8_t mrrs;
1185 
1186  /* Allocate net device */
1187  netdev = alloc_etherdev(sizeof(*jme));
1188  if (!netdev)
1189  return -ENOMEM;
1191  jme = netdev->priv;
1192  pci_set_drvdata(pci, netdev);
1193  netdev->dev = &pci->dev;
1194  jme->regs = ioremap(pci->membase, JME_REGS_SIZE);
1195  if (!(jme->regs)) {
1196  DBG("Mapping PCI resource region error.\n");
1197  rc = -ENOMEM;
1198  goto err_out;
1199  }
1200  jme->reg_ghc = 0;
1201  jme->reg_rxcs = RXCS_DEFAULT;
1202  jme->reg_rxmcs = RXMCS_DEFAULT;
1203  jme->phylink = 0;
1204  jme->pdev = pci;
1205  jme->mii_if.dev = netdev;
1206  jme->mii_if.phy_id = 1;
1209  jme->rx_ring_size = 1 << 4;
1210  jme->rx_ring_mask = jme->rx_ring_size - 1;
1211  jme->tx_ring_size = 1 << 4;
1212  jme->tx_ring_mask = jme->tx_ring_size - 1;
1213 
1214  /* Fix up PCI device */
1215  adjust_pci_device(pci);
1216 
1217  /*
1218  * Get Max Read Req Size from PCI Config Space
1219  */
1220  pci_read_config_byte(pci, PCI_DCSR_MRRS, &mrrs);
1221  mrrs &= PCI_DCSR_MRRS_MASK;
1222  switch (mrrs) {
1223  case MRRS_128B:
1225  break;
1226  case MRRS_256B:
1228  break;
1229  default:
1231  break;
1232  };
1233 
1234  /*
1235  * Get basic hardware info.
1236  */
1237  jme_check_hw_ver(jme);
1239  jme->mii_if.supports_gmii = 1;
1240  else
1241  jme->mii_if.supports_gmii = 0;
1242 
1243  /*
1244  * Initialize PHY
1245  */
1246  jme_set_phyfifoa(jme);
1247  jme_phy_init(jme);
1248 
1249  /*
1250  * Bring down phy before interface is opened.
1251  */
1252  jme_phy_off(jme);
1253 
1254  /*
1255  * Reset MAC processor and reload EEPROM for MAC Address
1256  */
1258  rc = jme_reload_eeprom(jme);
1259  if (rc) {
1260  DBG("Reload eeprom for reading MAC Address error.\n");
1261  goto err_unmap;
1262  }
1264 
1265  /* Register network device */
1266  if ((rc = register_netdev(netdev)) != 0) {
1267  DBG("Register net_device error.\n");
1268  goto err_unmap;
1269  }
1270 
1271  return 0;
1272 
1273 err_unmap:
1274  iounmap(jme->regs);
1275 err_out:
1277  netdev_put(netdev);
1278  return rc;
1279 }
int phy_id
Definition: mii.h:143
unsigned long membase
Memory base.
Definition: pci.h:194
struct net_device * dev
Definition: mii.h:152
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static void jme_set_phyfifoa(struct jme_adapter *jme)
Definition: jme.c:130
uint32_t reg_rxmcs
Definition: jme.h:261
int(* mdio_read)(struct net_device *dev, int phy_id, int location)
Definition: mii.h:153
static void jme_phy_off(struct jme_adapter *jme)
Definition: jme.c:142
#define PCI_DEVICE_ID_JMICRON_JMC250
Definition: jme.h:27
Definition: jme.h:38
uint32_t reg_rxcs
Definition: jme.h:260
struct mii_if_info mii_if
Definition: jme.h:254
uint32_t tx_ring_size
Definition: jme.h:267
void adjust_pci_device(struct pci_device *pci)
Enable PCI device.
Definition: pci.c:149
#define PCI_DCSR_MRRS_MASK
Definition: jme.h:34
struct device dev
Generic device.
Definition: pci.h:189
static void jme_mdio_write(struct net_device *netdev, int phy, int reg, int val)
Definition: jme.c:70
static void jme_load_macaddr(struct net_device *netdev)
Definition: jme.c:1154
static void netdev_init(struct net_device *netdev, struct net_device_operations *op)
Initialise a network device.
Definition: netdevice.h:498
uint32_t rx_ring_mask
Definition: jme.h:265
static void jme_check_hw_ver(struct jme_adapter *jme)
Definition: jme.c:1113
static void pci_set_drvdata(struct pci_device *pci, void *priv)
Set PCI driver-private data.
Definition: pci.h:338
#define ENOMEM
Not enough space.
Definition: errno.h:534
static int jme_mdio_read(struct net_device *netdev, int phy, int reg)
Definition: jme.c:41
uint16_t device
Device ID.
Definition: pci.h:204
void * regs
Definition: jme.h:253
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:555
unsigned int supports_gmii
Definition: mii.h:150
void * priv
Driver private data.
Definition: netdevice.h:425
uint32_t tx_ring_mask
Definition: jme.h:268
static struct net_device * netdev
Definition: gdbudp.c:52
uint32_t reg_ghc
Definition: jme.h:258
struct pci_device * pdev
Definition: jme.h:255
int register_netdev(struct net_device *netdev)
Register network device.
Definition: netdevice.c:667
A network device.
Definition: netdevice.h:348
void(* mdio_write)(struct net_device *dev, int phy_id, int location, int val)
Definition: mii.h:154
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:511
unsigned char uint8_t
Definition: stdint.h:10
static void jme_reset_mac_processor(struct jme_adapter *jme)
Definition: jme.c:210
uint32_t phylink
Definition: jme.h:262
struct device * dev
Underlying hardware device.
Definition: netdevice.h:360
static int jme_reload_eeprom(struct jme_adapter *jme)
Definition: jme.c:1124
struct net_device * alloc_etherdev(size_t priv_size)
Allocate Ethernet device.
Definition: ethernet.c:264
uint32_t reg_txcs
Definition: jme.h:259
void iounmap(volatile const void *io_addr)
Unmap I/O address.
#define PCI_DCSR_MRRS
Definition: jme.h:33
Definition: jme.h:37
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
void * ioremap(unsigned long bus_addr, size_t len)
Map bus address as an I/O address.
uint32_t rx_ring_size
Definition: jme.h:264
static void jme_phy_init(struct jme_adapter *jme)
Definition: jme.c:121
static struct net_device_operations jme_operations
JME net device operations.
Definition: jme.c:1104
int pci_read_config_byte(struct pci_device *pci, unsigned int where, uint8_t *value)
Read byte from PCI configuration space.

References adjust_pci_device(), alloc_etherdev(), DBG, mii_if_info::dev, pci_device::dev, net_device::dev, pci_device::device, ENOMEM, ioremap(), iounmap(), jme_check_hw_ver(), jme_load_macaddr(), jme_mdio_read(), jme_mdio_write(), jme_operations, jme_phy_init(), jme_phy_off(), JME_REGS_SIZE, jme_reload_eeprom(), jme_reset_mac_processor(), jme_set_phyfifoa(), mii_if_info::mdio_read, mii_if_info::mdio_write, pci_device::membase, jme_adapter::mii_if, MRRS_128B, MRRS_256B, netdev, netdev_init(), netdev_nullify(), netdev_put(), PCI_DCSR_MRRS, PCI_DCSR_MRRS_MASK, PCI_DEVICE_ID_JMICRON_JMC250, pci_read_config_byte(), pci_set_drvdata(), jme_adapter::pdev, mii_if_info::phy_id, jme_adapter::phylink, net_device::priv, rc, jme_adapter::reg_ghc, jme_adapter::reg_rxcs, jme_adapter::reg_rxmcs, jme_adapter::reg_txcs, register_netdev(), jme_adapter::regs, jme_adapter::rx_ring_mask, jme_adapter::rx_ring_size, RXCS_DEFAULT, RXMCS_DEFAULT, mii_if_info::supports_gmii, jme_adapter::tx_ring_mask, jme_adapter::tx_ring_size, TXCS_DEFAULT, TXCS_DMASIZE_128B, TXCS_DMASIZE_256B, and TXCS_DMASIZE_512B.

◆ jme_remove()

static void jme_remove ( struct pci_device pci)
static

Remove PCI device.

Parameters
pciPCI device

Definition at line 1287 of file jme.c.

1288 {
1289  struct net_device *netdev = pci_get_drvdata(pci);
1290  struct jme_adapter *jme = netdev->priv;
1291 
1292  iounmap(jme->regs);
1295  netdev_put(netdev);
1296 }
void * regs
Definition: jme.h:253
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:555
void * priv
Driver private data.
Definition: netdevice.h:425
static struct net_device * netdev
Definition: gdbudp.c:52
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:844
A network device.
Definition: netdevice.h:348
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:511
static void * pci_get_drvdata(struct pci_device *pci)
Get PCI driver-private data.
Definition: pci.h:348
void iounmap(volatile const void *io_addr)
Unmap I/O address.

References iounmap(), netdev, netdev_nullify(), netdev_put(), pci_get_drvdata(), net_device::priv, jme_adapter::regs, and unregister_netdev().

Variable Documentation

◆ jme_operations

struct net_device_operations jme_operations
static
Initial value:
= {
.open = jme_open,
.close = jme_close,
.transmit = jme_transmit,
.poll = jme_poll,
.irq = jme_irq,
}
static void jme_irq(struct net_device *netdev, int enable)
Enable/disable interrupts.
Definition: jme.c:1092
static void jme_poll(struct net_device *netdev)
Poll for received packets.
Definition: jme.c:1024
static void jme_close(struct net_device *netdev)
Close NIC.
Definition: jme.c:743
static int jme_transmit(struct net_device *netdev, struct io_buffer *iobuf)
Transmit packet.
Definition: jme.c:814
static int jme_open(struct net_device *netdev)
Open NIC.
Definition: jme.c:702

JME net device operations.

Definition at line 1104 of file jme.c.

Referenced by jme_probe().

◆ jm_nics

struct pci_device_id jm_nics[]
static
Initial value:
= {
PCI_ROM(0x197b, 0x0250, "jme", "JMicron Gigabit Ethernet", 0),
PCI_ROM(0x197b, 0x0260, "jmfe", "JMicron Fast Ethernet", 0),
}
#define PCI_ROM(_vendor, _device, _name, _description, _data)
Definition: pci.h:283

Definition at line 1298 of file jme.c.

◆ __pci_driver

struct pci_driver jme_driver __pci_driver
Initial value:
= {
.ids = jm_nics,
.id_count = ( sizeof ( jm_nics ) / sizeof ( jm_nics[0] ) ),
.probe = jme_probe,
}
static struct pci_device_id jm_nics[]
Definition: jme.c:1298
static int jme_probe(struct pci_device *pci)
Probe PCI device.
Definition: jme.c:1179
static struct xen_remove_from_physmap * remove
Definition: xenmem.h:39
static void jme_remove(struct pci_device *pci)
Remove PCI device.
Definition: jme.c:1287

Definition at line 1303 of file jme.c.