Commit abf79225 authored by Alessandro Rubini's avatar Alessandro Rubini

wr_minic.c: whitespace and indentation cleanup

parent 4dfe582f
...@@ -57,8 +57,10 @@ ...@@ -57,8 +57,10 @@
#define RX_OOB_SIZE 6 #define RX_OOB_SIZE 6
#define REFCLK_FREQ 125000000 #define REFCLK_FREQ 125000000
// extracts the values of TS rising and falling edge counters from the descriptor header /*
* Extracts the values of TS rising and falling edge counters
* from the descriptor header
*/
#define EXPLODE_WR_TIMESTAMP(raw, rc, fc) \ #define EXPLODE_WR_TIMESTAMP(raw, rc, fc) \
rc = (raw) & 0xfffffff; \ rc = (raw) & 0xfffffff; \
fc = (raw >> 28) & 0xf; fc = (raw >> 28) & 0xf;
...@@ -74,12 +76,11 @@ struct tx_timestamp { ...@@ -74,12 +76,11 @@ struct tx_timestamp {
}; };
struct wr_minic { struct wr_minic {
void __iomem *base; // address of the Minic+RAM+Endpoint combo
void __iomem *base; // base address of the Minic+Packet RAM+Endpoint combo void __iomem *minic_regs; // address of the miNIC registers
void __iomem *minic_regs; // base address of the miNIC registers void __iomem *ep_regs; // address of the Endpoint registers
void __iomem *ep_regs; // base address of the Endpoint registers void __iomem *pbuf; // address of the Packet RAM
void __iomem *pbuf; // base address of the Packet RAM void __iomem *ppsg; // address of the PPS generator
void __iomem *ppsg; // base address of the PPS generator
spinlock_t lock; spinlock_t lock;
...@@ -140,16 +141,22 @@ static int phy_read(struct net_device *dev, int phy_id, int location) ...@@ -140,16 +141,22 @@ static int phy_read(struct net_device *dev, int phy_id, int location)
struct wr_minic *nic = netdev_priv(dev); struct wr_minic *nic = netdev_priv(dev);
endpoint_writel(nic, EP_REG_MDIO_CR, EP_MDIO_CR_ADDR_W(location)); endpoint_writel(nic, EP_REG_MDIO_CR, EP_MDIO_CR_ADDR_W(location));
while( (endpoint_readl(nic, EP_REG_MDIO_SR) & EP_MDIO_SR_READY) == 0); while( (endpoint_readl(nic, EP_REG_MDIO_SR) & EP_MDIO_SR_READY) == 0)
;
return EP_MDIO_SR_RDATA_R(endpoint_readl(nic, EP_REG_MDIO_SR)); return EP_MDIO_SR_RDATA_R(endpoint_readl(nic, EP_REG_MDIO_SR));
} }
static void phy_write(struct net_device *dev, int phy_id, int location, int value) static void phy_write(struct net_device *dev, int phy_id, int location,
int value)
{ {
struct wr_minic *nic = netdev_priv(dev); struct wr_minic *nic = netdev_priv(dev);
endpoint_writel(nic, EP_REG_MDIO_CR, EP_MDIO_CR_ADDR_W(location) | EP_MDIO_CR_DATA_W(value)| EP_MDIO_CR_RW); endpoint_writel(nic, EP_REG_MDIO_CR,
while( (endpoint_readl(nic, EP_REG_MDIO_SR) & EP_MDIO_SR_READY) == 0); EP_MDIO_CR_ADDR_W(location)
| EP_MDIO_CR_DATA_W(value)
| EP_MDIO_CR_RW);
while( (endpoint_readl(nic, EP_REG_MDIO_SR) & EP_MDIO_SR_READY) == 0)
;
} }
...@@ -162,7 +169,8 @@ static int minic_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) ...@@ -162,7 +169,8 @@ static int minic_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
ret = mii_ethtool_gset(&lp->mii, cmd); ret = mii_ethtool_gset(&lp->mii, cmd);
spin_unlock_irq(&lp->lock); spin_unlock_irq(&lp->lock);
cmd->supported= SUPPORTED_FIBRE | SUPPORTED_Autoneg| SUPPORTED_1000baseKX_Full; cmd->supported= SUPPORTED_FIBRE | SUPPORTED_Autoneg
| SUPPORTED_1000baseKX_Full;
cmd->advertising = ADVERTISED_1000baseKX_Full | ADVERTISED_Autoneg; cmd->advertising = ADVERTISED_1000baseKX_Full | ADVERTISED_Autoneg;
cmd->port = PORT_FIBRE; cmd->port = PORT_FIBRE;
cmd->speed = SPEED_1000; cmd->speed = SPEED_1000;
...@@ -197,11 +205,13 @@ static int minic_nwayreset(struct net_device *dev) ...@@ -197,11 +205,13 @@ static int minic_nwayreset(struct net_device *dev)
return ret; return ret;
} }
static void minic_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) static void minic_get_drvinfo(struct net_device *dev,
struct ethtool_drvinfo *info)
{ {
strlcpy(info->driver, DRV_NAME, sizeof(info->driver)); strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
strlcpy(info->version, DRV_VERSION, sizeof(info->version)); strlcpy(info->version, DRV_VERSION, sizeof(info->version));
strlcpy(info->bus_info, dev_name(dev->dev.parent), sizeof(info->bus_info)); strlcpy(info->bus_info, dev_name(dev->dev.parent),
sizeof(info->bus_info));
} }
static const struct ethtool_ops minic_ethtool_ops = { static const struct ethtool_ops minic_ethtool_ops = {
...@@ -219,17 +229,18 @@ static void minic_ppsg_read_time(struct wr_minic *nic, u32 *cntr, u64 *utc) ...@@ -219,17 +229,18 @@ static void minic_ppsg_read_time(struct wr_minic *nic, u32 *cntr, u64 *utc)
uint32_t cyc_before, cyc_after; uint32_t cyc_before, cyc_after;
uint32_t utc_lo, utc_hi; uint32_t utc_lo, utc_hi;
for(;;) for(;;) {
{
cyc_before =ppsg_readl(nic, PPSG_REG_CNTR_NSEC) & 0xfffffff; cyc_before =ppsg_readl(nic, PPSG_REG_CNTR_NSEC) & 0xfffffff;
utc_lo = ppsg_readl(nic, PPSG_REG_CNTR_UTCLO) ; utc_lo = ppsg_readl(nic, PPSG_REG_CNTR_UTCLO) ;
utc_hi = ppsg_readl(nic, PPSG_REG_CNTR_UTCHI) & 0xff; utc_hi = ppsg_readl(nic, PPSG_REG_CNTR_UTCHI) & 0xff;
cyc_after = ppsg_readl(nic, PPSG_REG_CNTR_NSEC) & 0xfffffff; cyc_after = ppsg_readl(nic, PPSG_REG_CNTR_NSEC) & 0xfffffff;
// there was an UTC transition. (nanosecond counter overflow). read the value again. // there was an UTC transition. (nanosecond counter overflow),
if(cyc_after < REFCLK_FREQ/4 && cyc_before > (REFCLK_FREQ - REFCLK_FREQ/4)) // read the value again.
if(cyc_after < REFCLK_FREQ/4
&& cyc_before > (REFCLK_FREQ - REFCLK_FREQ/4)) {
continue; continue;
else { } else {
if(utc) *utc = (u64)utc_lo | (u64)utc_hi << 32; if(utc) *utc = (u64)utc_lo | (u64)utc_hi << 32;
if(cntr) *cntr = cyc_after; if(cntr) *cntr = cyc_after;
return; return;
...@@ -285,7 +296,6 @@ static void minic_new_tx_buffer(struct wr_minic *nic) ...@@ -285,7 +296,6 @@ static void minic_new_tx_buffer(struct wr_minic *nic)
{ {
nic->tx_head = nic->tx_base; nic->tx_head = nic->tx_base;
nic->tx_avail = (nic->tx_size - MINIC_MTU) >> 2; nic->tx_avail = (nic->tx_size - MINIC_MTU) >> 2;
minic_writel(nic, MINIC_REG_TX_ADDR, nic->tx_base); minic_writel(nic, MINIC_REG_TX_ADDR, nic->tx_base);
} }
...@@ -309,36 +319,38 @@ static int minic_rx_frame(struct wr_minic *nic) ...@@ -309,36 +319,38 @@ static int minic_rx_frame(struct wr_minic *nic)
return 1; return 1;
rx_head = nic->pbuf + nic->rx_head; rx_head = nic->pbuf + nic->rx_head;
desc_hdr = __raw_readl(rx_head++); /* read the 32-bit descriptor header */ desc_hdr = __raw_readl(rx_head++); /* read 32-bit descriptor header */
if(!RX_DESC_VALID(desc_hdr)) /* invalid descriptor? Weird, the RX_ADDR seems to be saying something different. Ignore the packet and purge the RX buffer. */ if(!RX_DESC_VALID(desc_hdr)) {
{ /*
dev_info(nic->dev, "%s: weird, invalid RX descriptor (%x, head %x)", __func__, desc_hdr, (unsigned int) rx_head-1); * invalid descriptor? Weird, the RX_ADDR seems
* to be saying something different. Ignore the packet
* and purge the RX buffer.
*/
dev_info(nic->dev, "%s: weird, invalid RX descriptor "
"(%x, head %x)", __func__, desc_hdr,
(unsigned int) rx_head-1);
minic_new_rx_buffer(nic); minic_new_rx_buffer(nic);
return 0; return 0;
} }
// if(RX_DESC_HAS_OOB(desc_hdr)) // if(RX_DESC_HAS_OOB(desc_hdr))
payload_size = RX_DESC_SIZE(desc_hdr); payload_size = RX_DESC_SIZE(desc_hdr);
num_words = (payload_size + 3) >> 2; num_words = (payload_size + 3) >> 2;
/* valid packet */ /* valid packet */
if(!RX_DESC_ERROR(desc_hdr)) if(!RX_DESC_ERROR(desc_hdr)) {
{
skb = netdev_alloc_skb(netdev, payload_size + 9); skb = netdev_alloc_skb(netdev, payload_size + 9);
if (unlikely(skb == NULL)) { if (unlikely(skb == NULL)) {
if (net_ratelimit()) if (net_ratelimit())
dev_warn(nic->dev, "-ENOMEM - packet dropped\n"); dev_warn(nic->dev, "-ENOMEM - pckt dropped\n");
return 0; return 0;
} }
/* Make the IP header word-aligned (the ethernet header is 14 bytes) */ /* Make the IP header aligned (the eth header is 14 bytes) */
skb_reserve(skb, 2); skb_reserve(skb, 2);
for(i=num_words, tmp_ptr = tmp_buf;i >=0 ; i--) for(i=num_words, tmp_ptr = tmp_buf;i >=0 ; i--)
...@@ -361,20 +373,24 @@ static int minic_rx_frame(struct wr_minic *nic) ...@@ -361,20 +373,24 @@ static int minic_rx_frame(struct wr_minic *nic)
minic_ppsg_read_time(nic, &counter_ppsg, &utc); minic_ppsg_read_time(nic, &counter_ppsg, &utc);
if(counter_r > (3*REFCLK_FREQ/4) && counter_ppsg < REFCLK_FREQ/4) if(counter_r > (3*REFCLK_FREQ/4)
&& counter_ppsg < REFCLK_FREQ/4)
utc--; utc--;
// fixme: we need to pass the phase value somehow for RX timestamps. For the time being, we pass the R-F counter difference on the MSB of UTC (instead of sign value), so the PTP can detect the valid counter /* fixme: we need to pass the phase value somehow
* for RX timestamps. For the time being, we pass
* the R-F counter difference on the MSB of UTC
hwts->hwtstamp.tv.sec = (s32)utc & 0x7fffffff ; * (instead of sign value), so the PTP can detect
* the valid counter
*/
hwts->hwtstamp.tv.sec = (s32)utc & 0x7fffffff;
cntr_diff = (counter_r & F_COUNTER_MASK) - counter_f; cntr_diff = (counter_r & F_COUNTER_MASK) - counter_f;
/* the bit says the rising edge cnter is 1tick ahead */
if(cntr_diff == 1 || cntr_diff == (-F_COUNTER_MASK)) if(cntr_diff == 1 || cntr_diff == (-F_COUNTER_MASK))
hwts->hwtstamp.tv.sec |= 0x80000000; // indicated that the rising edge counter is one tick ahead hwts->hwtstamp.tv.sec |= 0x80000000;
hwts->hwtstamp.tv.nsec = counter_r * 8; hwts->hwtstamp.tv.nsec = counter_r * 8;
} }
...@@ -398,16 +414,12 @@ static int minic_rx_frame(struct wr_minic *nic) ...@@ -398,16 +414,12 @@ static int minic_rx_frame(struct wr_minic *nic)
nic->stats.rx_errors ++; nic->stats.rx_errors ++;
nic->rx_head += ( num_words + 1 ) << 2; nic->rx_head += ( num_words + 1 ) << 2;
} }
wmb(); wmb();
return 0; return 0;
} }
static int minic_poll_txts_fifo(struct wr_minic *nic, u16 oob_fid,
struct skb_shared_hwtstamps *hwts)
static int minic_poll_txts_fifo(struct wr_minic *nic, u16 oob_fid, struct skb_shared_hwtstamps *hwts)
{ {
int i; int i;
...@@ -431,8 +443,8 @@ static int minic_poll_txts_fifo(struct wr_minic *nic, u16 oob_fid, struct skb_s ...@@ -431,8 +443,8 @@ static int minic_poll_txts_fifo(struct wr_minic *nic, u16 oob_fid, struct skb_s
if(dmtd_phase < 0) dmtd_phase += DMTD_MAX_PHASE; if(dmtd_phase < 0) dmtd_phase += DMTD_MAX_PHASE;
while(!(minic_readl(nic, MINIC_REG_TSFIFO_CSR) & MINIC_TSFIFO_CSR_EMPTY)) while(!(minic_readl(nic, MINIC_REG_TSFIFO_CSR)
{ & MINIC_TSFIFO_CSR_EMPTY)) {
u32 tsval_raw = minic_readl(nic, MINIC_REG_TSFIFO_R0); u32 tsval_raw = minic_readl(nic, MINIC_REG_TSFIFO_R0);
u32 fid = (minic_readl(nic, MINIC_REG_TSFIFO_R1) >> 5) & 0xffff; u32 fid = (minic_readl(nic, MINIC_REG_TSFIFO_R1) >> 5) & 0xffff;
...@@ -445,48 +457,44 @@ static int minic_poll_txts_fifo(struct wr_minic *nic, u16 oob_fid, struct skb_s ...@@ -445,48 +457,44 @@ static int minic_poll_txts_fifo(struct wr_minic *nic, u16 oob_fid, struct skb_s
// printk("About to read time\n"); // printk("About to read time\n");
minic_ppsg_read_time(nic, &counter_ppsg, &utc); minic_ppsg_read_time(nic, &counter_ppsg, &utc);
// printk("After read time\n"); // printk("After read time\n");
// the timestamp was taken at the end of previous second // the timestamp was taken at the end of previous second
// of UTC time, and now we are at the beginning of the next second // of UTC time, and now we are at the beg. of the next second
if(counter_r > (3*REFCLK_FREQ/4) && counter_ppsg < REFCLK_FREQ/4) if(counter_r > (3*REFCLK_FREQ/4)
&& counter_ppsg < REFCLK_FREQ/4)
utc--; utc--;
// fixme // fixme
tsval.hwtstamp.tv.sec = ((s32)utc & 0x7fffffff); tsval.hwtstamp.tv.sec = ((s32)utc & 0x7fffffff);
tsval.hwtstamp.tv.nsec = counter_r * 8; tsval.hwtstamp.tv.nsec = counter_r * 8;
for(i = 0; i<MINIC_TX_MAX_TS;i++) for(i = 0; i<MINIC_TX_MAX_TS;i++)
if(!nic->tx_tstable[i].valid) if(!nic->tx_tstable[i].valid) {
{ // printk("Addts: fid %d tsval %x\n",
// printk("Addts: fid %d tsval %x\n", fid, tsval); // fid, tsval);
nic->tx_tstable[i].valid = 1; nic->tx_tstable[i].valid = 1;
nic->tx_tstable[i].ts_val = tsval; nic->tx_tstable[i].ts_val = tsval;
nic->tx_tstable[i].fid = fid; nic->tx_tstable[i].fid = fid;
break; break;
};
} }
}
// printk("queryts: fid %d\n", oob_fid); // printk("queryts: fid %d\n", oob_fid);
for(i = 0; i<MINIC_TX_MAX_TS;i++) for(i = 0; i<MINIC_TX_MAX_TS;i++) {
if(nic->tx_tstable[i].valid && oob_fid == nic->tx_tstable[i].fid) if(nic->tx_tstable[i].valid && oob_fid
{ == nic->tx_tstable[i].fid) {
// printk("GotTS: fid %d\n", oob_fid); // printk("GotTS: fid %d\n", oob_fid);
if(hwts) if(hwts)
memcpy(hwts, &nic->tx_tstable[i].ts_val, sizeof(struct skb_shared_hwtstamps)); memcpy(hwts, &nic->tx_tstable[i].ts_val,
sizeof(struct skb_shared_hwtstamps));
nic->tx_tstable[i].valid = 0; nic->tx_tstable[i].valid = 0;
return 0; return 0;
}; }
}
// printk("Missed timestamp..."); // printk("Missed timestamp...");
return -1; return -1;
} }
...@@ -502,19 +510,18 @@ static inline void minic_tx_handle_irq(struct wr_minic *nic) ...@@ -502,19 +510,18 @@ static inline void minic_tx_handle_irq(struct wr_minic *nic)
unsigned long flags; unsigned long flags;
u16 oob_tag; u16 oob_tag;
spin_lock_irqsave(&nic->lock, flags); spin_lock_irqsave(&nic->lock, flags);
// this will only work for the NIC directly connected to the endpoint. In case of a switch, /*
// the packet will reach the output port after being completely transmitted by the NIC (i.e. after the TX interrupt) * this will only work for the NIC directly connected to the endpoint.
* In case of a switch, the packet will reach the output port after
* being completely transmitted by the NIC (i.e. after TX interrupt)
*/
if(shtx->in_progress) if(shtx->in_progress) {
{
oob_tag = *(u16 *) hwoob; oob_tag = *(u16 *) hwoob;
if(!minic_poll_txts_fifo(nic, oob_tag, &hwts)) if(!minic_poll_txts_fifo(nic, oob_tag, &hwts))
skb_tstamp_tx(nic->current_skb, &hwts); skb_tstamp_tx(nic->current_skb, &hwts);
} }
dev_kfree_skb_irq(nic->current_skb); dev_kfree_skb_irq(nic->current_skb);
...@@ -527,8 +534,6 @@ static inline void minic_tx_handle_irq(struct wr_minic *nic) ...@@ -527,8 +534,6 @@ static inline void minic_tx_handle_irq(struct wr_minic *nic)
minic_clear_irq(nic, MINIC_EIC_ISR_TX); // clear the TX interrupt minic_clear_irq(nic, MINIC_EIC_ISR_TX); // clear the TX interrupt
} }
static inline void minic_rx_handle_irq(struct wr_minic *nic) static inline void minic_rx_handle_irq(struct wr_minic *nic)
{ {
int buf_full; int buf_full;
...@@ -558,9 +563,8 @@ static void minic_interrupt(void *dev_id) // called by MCH VIC driver ...@@ -558,9 +563,8 @@ static void minic_interrupt(void *dev_id) // called by MCH VIC driver
minic_rx_handle_irq(nic); minic_rx_handle_irq(nic);
} }
static int minic_hw_tx(struct wr_minic *nic, char *data, unsigned size,
u16 tx_oob_val)
static int minic_hw_tx(struct wr_minic *nic, char *data, unsigned size, u16 tx_oob_val)
{ {
u32 __iomem *dst, *dptr; u32 __iomem *dst, *dptr;
u32 nwords; u32 nwords;
...@@ -573,23 +577,24 @@ static int minic_hw_tx(struct wr_minic *nic, char *data, unsigned size, u16 tx_o ...@@ -573,23 +577,24 @@ static int minic_hw_tx(struct wr_minic *nic, char *data, unsigned size, u16 tx_o
memset(pkt_buf, 0x0, size + 16); memset(pkt_buf, 0x0, size + 16);
memcpy(pkt_buf + 1, data, size); memcpy(pkt_buf + 1, data, size);
if(nwords < 30) nwords = 30; // min packet length = 60 bytes (CRC excluded) if(nwords < 30) nwords = 30; // min length = 60 bytes (CRC excluded)
if(tx_oob_val) // do the TX timestamping? if(tx_oob_val) { // do the TX timestamping?
{
tx_oob_val = swab16(tx_oob_val); tx_oob_val = swab16(tx_oob_val);
memcpy((void*)pkt_buf + 4 + size, &tx_oob_val, sizeof(u16)); memcpy((void*)pkt_buf + 4 + size, &tx_oob_val, sizeof(u16));
nwords++; nwords++;
pkt_buf[0] = TX_DESC_WITH_OOB; pkt_buf[0] = TX_DESC_WITH_OOB;
// printk("add oob\n"); // printk("add oob\n");
} else } else {
pkt_buf[0] = 0; pkt_buf[0] = 0;
}
pkt_buf[0] |= TX_DESC_VALID | TX_DESC_HAS_OWN_MAC | nwords; pkt_buf[0] |= TX_DESC_VALID | TX_DESC_HAS_OWN_MAC | nwords;
for(i=((nwords+1)>>1)+3, dptr = (u32*) pkt_buf, dst = nic->pbuf + nic->tx_head; i ; i--) dptr = (u32*) pkt_buf;
*dst ++ = *dptr++; dst = nic->pbuf + nic->tx_head;
for(i = ((nwords + 1) >> 1) + 3; i; i--)
*dst++ = *dptr++;
minic_enable_irq(nic, MINIC_EIC_IER_TX); minic_enable_irq(nic, MINIC_EIC_IER_TX);
...@@ -619,22 +624,19 @@ static int minic_start_xmit(struct sk_buff *skb, struct net_device *netdev) ...@@ -619,22 +624,19 @@ static int minic_start_xmit(struct sk_buff *skb, struct net_device *netdev)
spin_lock_irq(&nic->lock); spin_lock_irq(&nic->lock);
nic->current_skb = skb; nic->current_skb = skb;
netif_stop_queue(netdev); // queue stays stopped until the packet is transmitted. netif_stop_queue(netdev); // queue is stopped until packet is tx'ed
if(nic -> tx_hwtstamp_enable && shtx->hardware) if(nic -> tx_hwtstamp_enable && shtx->hardware) {
{
struct skb_shared_hwtstamps *hwts = skb_hwtstamps(skb); struct skb_shared_hwtstamps *hwts = skb_hwtstamps(skb);
shtx->in_progress = 1; shtx->in_progress = 1;
// printk("DoHWTX\n");
*(u16 *) hwts = tx_oob = nic->tx_hwtstamp_oob; *(u16 *) hwts = tx_oob = nic->tx_hwtstamp_oob;
nic->tx_hwtstamp_oob ++; nic->tx_hwtstamp_oob ++;
if(nic->tx_hwtstamp_oob == 60000) if(nic->tx_hwtstamp_oob == 60000)
nic->tx_hwtstamp_oob = 1; nic->tx_hwtstamp_oob = 1;
} else } else {
tx_oob = 0; tx_oob = 0;
}
minic_new_tx_buffer(nic); minic_new_tx_buffer(nic);
minic_hw_tx(nic, data, len, tx_oob); minic_hw_tx(nic, data, len, tx_oob);
...@@ -651,27 +653,26 @@ static int minic_start_xmit(struct sk_buff *skb, struct net_device *netdev) ...@@ -651,27 +653,26 @@ static int minic_start_xmit(struct sk_buff *skb, struct net_device *netdev)
static void minic_update_ts_config(struct wr_minic *nic) static void minic_update_ts_config(struct wr_minic *nic)
{ {
endpoint_writel(nic, EP_REG_TSCR, (nic->tx_hwtstamp_enable ? EP_TSCR_EN_TXTS : 0) endpoint_writel(nic, EP_REG_TSCR,
(nic->tx_hwtstamp_enable ? EP_TSCR_EN_TXTS : 0)
| (nic->rx_hwtstamp_enable ? EP_TSCR_EN_RXTS : 0) | (nic->rx_hwtstamp_enable ? EP_TSCR_EN_RXTS : 0)
); );
// printk("update_ts_config: TSCR %x\n", endpoint_readl(nic, EP_REG_TSCR)); // printk("update_ts_config: TSCR %x\n",
// endpoint_readl(nic, EP_REG_TSCR));
} }
static int minic_tstamp_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd) static int minic_tstamp_ioctl(struct net_device *netdev, struct ifreq *rq,
int cmd)
{ {
struct wr_minic *nic = netdev_priv(netdev); struct wr_minic *nic = netdev_priv(netdev);
struct hwtstamp_config config; struct hwtstamp_config config;
if (copy_from_user(&config, rq->ifr_data, sizeof(config))) if (copy_from_user(&config, rq->ifr_data, sizeof(config)))
return -EFAULT; return -EFAULT;
// printk("hwtstamp_ioctl()\n" ); // printk("hwtstamp_ioctl()\n" );
switch (config.tx_type) { switch (config.tx_type) {
case HWTSTAMP_TX_ON: case HWTSTAMP_TX_ON:
// printk("%s: hw tx timestamping ON\n", __func__); // printk("%s: hw tx timestamping ON\n", __func__);
...@@ -686,8 +687,6 @@ static int minic_tstamp_ioctl(struct net_device *netdev, struct ifreq *rq, int c ...@@ -686,8 +687,6 @@ static int minic_tstamp_ioctl(struct net_device *netdev, struct ifreq *rq, int c
nic->tx_hwtstamp_enable = 0; nic->tx_hwtstamp_enable = 0;
break; break;
default: default:
return -ERANGE; return -ERANGE;
} }
...@@ -703,8 +702,9 @@ static int minic_tstamp_ioctl(struct net_device *netdev, struct ifreq *rq, int c ...@@ -703,8 +702,9 @@ static int minic_tstamp_ioctl(struct net_device *netdev, struct ifreq *rq, int c
break; break;
case HWTSTAMP_FILTER_PTP_V2_L2_EVENT: case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
// printk( "%s - hw rx timestamping ON for PTP L2 events\n", __func__); // printk( "%s - hw rx timestamping ON for PTP L2 events\n",
nic->rx_hwtstamp_enable = 1; // Only PTPv2 is supported for the time being... // __func__);
nic->rx_hwtstamp_enable = 1; // Only PTPv2 supported by now
config.rx_filter = HWTSTAMP_FILTER_ALL; config.rx_filter = HWTSTAMP_FILTER_ALL;
break; break;
default: default:
...@@ -715,7 +715,6 @@ static int minic_tstamp_ioctl(struct net_device *netdev, struct ifreq *rq, int c ...@@ -715,7 +715,6 @@ static int minic_tstamp_ioctl(struct net_device *netdev, struct ifreq *rq, int c
return copy_to_user(rq->ifr_data, &config, sizeof(config)) ? return copy_to_user(rq->ifr_data, &config, sizeof(config)) ?
-EFAULT : 0; -EFAULT : 0;
} }
#define PRIV_IOCGCALIBRATE (SIOCDEVPRIVATE+1) #define PRIV_IOCGCALIBRATE (SIOCDEVPRIVATE+1)
...@@ -746,11 +745,10 @@ static int phase_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd) ...@@ -746,11 +745,10 @@ static int phase_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
u32 dmsr = endpoint_readl(nic, EP_REG_DMSR); u32 dmsr = endpoint_readl(nic, EP_REG_DMSR);
if(dmsr & EP_DMSR_PS_RDY) if(dmsr & EP_DMSR_PS_RDY) {
{
s32 dmtd_phase = EP_DMSR_PS_VAL_R(dmsr); s32 dmtd_phase = EP_DMSR_PS_VAL_R(dmsr);
// sign-extend, fix the average if its out of range due to jitter // sign-extend, fix the average if out of range due to jitter
if(dmtd_phase & 0x800000) dmtd_phase |= 0xff000000; if(dmtd_phase & 0x800000) dmtd_phase |= 0xff000000;
// calculate the average // calculate the average
...@@ -768,10 +766,10 @@ static int phase_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd) ...@@ -768,10 +766,10 @@ static int phase_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
return copy_to_user(rq->ifr_data, &phase_req, sizeof(phase_req)) ? return copy_to_user(rq->ifr_data, &phase_req, sizeof(phase_req)) ?
-EFAULT : 0; -EFAULT : 0;
}
}; static int calibration_ioctl(struct net_device *netdev, struct ifreq *rq,
int cmd)
static int calibration_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
{ {
struct wrmch_calibration_req cal_req; struct wrmch_calibration_req cal_req;
struct wr_minic *nic = netdev_priv(netdev); struct wr_minic *nic = netdev_priv(netdev);
...@@ -780,62 +778,65 @@ static int calibration_ioctl(struct net_device *netdev, struct ifreq *rq, int cm ...@@ -780,62 +778,65 @@ static int calibration_ioctl(struct net_device *netdev, struct ifreq *rq, int cm
if (copy_from_user(&cal_req, rq->ifr_data, sizeof(cal_req))) if (copy_from_user(&cal_req, rq->ifr_data, sizeof(cal_req)))
return -EFAULT; return -EFAULT;
switch(cal_req.cmd) {
switch(cal_req.cmd)
{
case CAL_CMD_TX_ON: case CAL_CMD_TX_ON:
if(nic->iface_up) if(nic->iface_up) {
{
tmp = phy_read(netdev, 0, MDIO_REG_WR_SPEC); tmp = phy_read(netdev, 0, MDIO_REG_WR_SPEC);
phy_write(netdev, 0, MDIO_REG_WR_SPEC, tmp | MDIO_WR_SPEC_TX_CAL); phy_write(netdev, 0, MDIO_REG_WR_SPEC,
} else return -EFAULT; tmp | MDIO_WR_SPEC_TX_CAL);
} else {
return -EFAULT;
}
break; break;
case CAL_CMD_TX_OFF: case CAL_CMD_TX_OFF:
if(nic->iface_up) if(nic->iface_up) {
{
tmp = phy_read(netdev, 0, MDIO_REG_WR_SPEC); tmp = phy_read(netdev, 0, MDIO_REG_WR_SPEC);
phy_write(netdev, 0, MDIO_REG_WR_SPEC, tmp & (~MDIO_WR_SPEC_TX_CAL)); phy_write(netdev, 0, MDIO_REG_WR_SPEC,
} else return -EFAULT; tmp & (~MDIO_WR_SPEC_TX_CAL));
} else {
return -EFAULT;
}
break; break;
case CAL_CMD_RX_ON: case CAL_CMD_RX_ON:
if(nic->iface_up) if(nic->iface_up) {
{
tmp = phy_read(netdev, 0, MDIO_REG_WR_SPEC); tmp = phy_read(netdev, 0, MDIO_REG_WR_SPEC);
phy_write(netdev, 0, MDIO_REG_WR_SPEC, tmp | MDIO_WR_SPEC_CAL_CRST); phy_write(netdev, 0, MDIO_REG_WR_SPEC,
} else return -EFAULT; tmp | MDIO_WR_SPEC_CAL_CRST);
} else {
return -EFAULT;
}
break; break;
case CAL_CMD_RX_OFF: case CAL_CMD_RX_OFF:
if(nic->iface_up) if(nic->iface_up) {
{
// do nothing..... // do nothing.....
} else return -EFAULT; } else {
return -EFAULT;
}
break; break;
case CAL_CMD_RX_CHECK: case CAL_CMD_RX_CHECK:
if(nic->iface_up) if(nic->iface_up) {
{
tmp = phy_read(netdev, 0, MDIO_REG_WR_SPEC); tmp = phy_read(netdev, 0, MDIO_REG_WR_SPEC);
cal_req.cal_present = tmp & MDIO_WR_SPEC_RX_CAL_STAT ? 1 : 0; cal_req.cal_present = tmp & MDIO_WR_SPEC_RX_CAL_STAT
? 1 : 0;
return copy_to_user(rq->ifr_data, &cal_req, sizeof(cal_req)) ? if (copy_to_user(rq->ifr_data,&cal_req,
-EFAULT : 0; sizeof(cal_req)))
return -EFAULT;
} else return -EFAULT; return 0;
} else {
return -EFAULT;
}
break; break;
} }
return 0; return 0;
} }
static int minic_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd) static int minic_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
{ {
struct wr_minic *nic = netdev_priv(netdev); struct wr_minic *nic = netdev_priv(netdev);
...@@ -843,16 +844,11 @@ static int minic_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd) ...@@ -843,16 +844,11 @@ static int minic_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
switch (cmd) { switch (cmd) {
case SIOCSHWTSTAMP: case SIOCSHWTSTAMP:
return minic_tstamp_ioctl(netdev, rq, cmd); return minic_tstamp_ioctl(netdev, rq, cmd);
case PRIV_IOCGCALIBRATE: case PRIV_IOCGCALIBRATE:
return calibration_ioctl(netdev, rq, cmd); return calibration_ioctl(netdev, rq, cmd);
case PRIV_IOCGGETPHASE: case PRIV_IOCGGETPHASE:
return phase_ioctl(netdev, rq, cmd); return phase_ioctl(netdev, rq, cmd);
default: default:
spin_lock_irq(&nic->lock); spin_lock_irq(&nic->lock);
res = generic_mii_ioctl(&nic->mii, if_mii(rq), cmd, NULL); res = generic_mii_ioctl(&nic->mii, if_mii(rq), cmd, NULL);
spin_unlock_irq(&nic->lock); spin_unlock_irq(&nic->lock);
...@@ -864,14 +860,17 @@ static void ep_enable(struct net_device *netdev) ...@@ -864,14 +860,17 @@ static void ep_enable(struct net_device *netdev)
{ {
struct wr_minic *nic = netdev_priv(netdev); struct wr_minic *nic = netdev_priv(netdev);
endpoint_writel(nic, EP_REG_DMCR, EP_DMCR_EN | EP_DMCR_N_AVG_W(DMTD_AVG_SAMPLES)); endpoint_writel(nic, EP_REG_DMCR,
endpoint_writel(nic, EP_REG_ECR, EP_ECR_TX_EN_FRA | EP_ECR_RX_EN_FRA | EP_ECR_RST_CNT); EP_DMCR_EN | EP_DMCR_N_AVG_W(DMTD_AVG_SAMPLES));
endpoint_writel(nic, EP_REG_RFCR, 3 << EP_RFCR_QMODE_SHIFT); // QMODE = UNQUALIFIED endpoint_writel(nic, EP_REG_ECR,
EP_ECR_TX_EN_FRA | EP_ECR_RX_EN_FRA | EP_ECR_RST_CNT);
endpoint_writel(nic, EP_REG_RFCR,
3 << EP_RFCR_QMODE_SHIFT); // QMODE = UNQUALIFIED
endpoint_writel(nic, EP_REG_TSCR, 0); // disable the timestamping endpoint_writel(nic, EP_REG_TSCR, 0); // disable the timestamping
endpoint_writel(nic, EP_REG_FCR, 0); // no flow control for the time being endpoint_writel(nic, EP_REG_FCR, 0); // no flow control by now
phy_write(netdev, 0, MII_ADVERTISE, 0x01a0); // adv. TX+RX flow, full
phy_write(netdev, 0, MII_ADVERTISE, 0x01a0); // advertise TX+RX flow control, full duplex phy_write(netdev, 0, MII_BMCR, 0);
phy_write(netdev, 0, MII_BMCR, 0); //phy_read(netdev, 0, MII_BMCR) | BMCR_ANENABLE | BMCR_ANRESTART); //phy_read(netdev, 0, MII_BMCR) | BMCR_ANENABLE | BMCR_ANRESTART);
} }
static void ep_disable(struct net_device *netdev) static void ep_disable(struct net_device *netdev)
...@@ -882,22 +881,20 @@ static void ep_disable(struct net_device *netdev) ...@@ -882,22 +881,20 @@ static void ep_disable(struct net_device *netdev)
endpoint_writel(nic, EP_REG_TSCR, 0); endpoint_writel(nic, EP_REG_TSCR, 0);
} }
static void update_link_status(unsigned long dev_id) static void update_link_status(unsigned long dev_id)
{ {
struct net_device *netdev = (struct net_device *) dev_id; struct net_device *netdev = (struct net_device *) dev_id;
struct wr_minic *nic = netdev_priv(netdev); struct wr_minic *nic = netdev_priv(netdev);
u32 ecr, bmsr, bmsr2, bmsr3, bmcr, lpa; u32 ecr, bmsr, bmcr, lpa;
bmsr = phy_read(netdev, 0, MII_BMSR); bmsr = phy_read(netdev, 0, MII_BMSR);
bmcr = phy_read(netdev, 0, MII_BMCR); bmcr = phy_read(netdev, 0, MII_BMCR);
// printk(KERN_INFO "iface %s naddr %x bmsr %x\n", netdev->name, nic->mii.dev, bmsr); // printk(KERN_INFO "iface %s naddr %x bmsr %x\n",
// netdev->name, nic->mii.dev, bmsr);
if (!mii_link_ok(&nic->mii)) { /* no link */ if (!mii_link_ok(&nic->mii)) { /* no link */
if(netif_carrier_ok(netdev)) if(netif_carrier_ok(netdev)) {
{
netif_carrier_off(netdev); netif_carrier_off(netdev);
nic->iface_up = 0; nic->iface_up = 0;
printk(KERN_INFO "%s: Link down.\n", netdev->name); printk(KERN_INFO "%s: Link down.\n", netdev->name);
...@@ -909,29 +906,34 @@ static void update_link_status(unsigned long dev_id) ...@@ -909,29 +906,34 @@ static void update_link_status(unsigned long dev_id)
return; return;
if (bmcr & BMCR_ANENABLE) { /* AutoNegotiation is enabled */ if (bmcr & BMCR_ANENABLE) { /* AutoNegotiation is enabled */
if (!(bmsr & BMSR_ANEGCOMPLETE)) if (!(bmsr & BMSR_ANEGCOMPLETE)) {
return; /* Do nothing - another interrupt generated when negotiation complete */ /*
* Do nothing - another interrupt is generated
* when negotiation complete
*/
return;
}
lpa = phy_read(netdev,0, MII_LPA); lpa = phy_read(netdev,0, MII_LPA);
netif_carrier_on(netdev); netif_carrier_on(netdev);
nic->iface_up = 1; nic->iface_up = 1;
// endpoint_writel(nic, EP_REG_FCR, EP_FCR_TXPAUSE |EP_FCR_RXPAUSE | EP_FCR_TX_THR_W(128) | EP_FCR_TX_QUANTA_W(200)); // endpoint_writel(nic, EP_REG_FCR,
// EP_FCR_TXPAUSE |EP_FCR_RXPAUSE | EP_FCR_TX_THR_W(128)
// | EP_FCR_TX_QUANTA_W(200));
printk(KERN_INFO "%s: Link up, lpa 0x%04x.\n",
printk(KERN_INFO "%s: Link up, lpa 0x%04x.\n", netdev->name, lpa); netdev->name, lpa);
} else { } else {
netif_carrier_on(netdev); netif_carrier_on(netdev);
printk(KERN_INFO "%s: Link up.\n", netdev->name); printk(KERN_INFO "%s: Link up.\n", netdev->name);
nic->iface_up = 1; nic->iface_up = 1;
} }
ecr = endpoint_readl(nic, EP_REG_ECR); ecr = endpoint_readl(nic, EP_REG_ECR);
endpoint_writel(nic, EP_REG_ECR, ecr | EP_ECR_RST_CNT); // reset RMON counters /* reset RMON counters */
endpoint_writel(nic, EP_REG_ECR, ecr | EP_ECR_RST_CNT);
endpoint_writel(nic, EP_REG_ECR, ecr ); endpoint_writel(nic, EP_REG_ECR, ecr );
} }
static void minic_check_link(unsigned long dev_id) static void minic_check_link(unsigned long dev_id)
...@@ -966,7 +968,6 @@ static int minic_open(struct net_device *netdev) ...@@ -966,7 +968,6 @@ static int minic_open(struct net_device *netdev)
nic->synced = false; nic->synced = false;
nic->syncing_counters = false; nic->syncing_counters = false;
nic->rx_base = MINIC_PBUF_SIZE >> 1; nic->rx_base = MINIC_PBUF_SIZE >> 1;
nic->rx_size = MINIC_PBUF_SIZE >> 1; nic->rx_size = MINIC_PBUF_SIZE >> 1;
...@@ -1018,8 +1019,14 @@ static void minic_update_mac(struct net_device *netdev) ...@@ -1018,8 +1019,14 @@ static void minic_update_mac(struct net_device *netdev)
{ {
struct wr_minic *nic = netdev_priv(netdev); struct wr_minic *nic = netdev_priv(netdev);
endpoint_writel(nic, EP_REG_MACL, (netdev->dev_addr[3] << 24) | (netdev->dev_addr[2] << 16) | (netdev->dev_addr[1] << 8) | (netdev->dev_addr[0])); endpoint_writel(nic, EP_REG_MACL,
endpoint_writel(nic, EP_REG_MACH, (netdev->dev_addr[5] << 8) | (netdev->dev_addr[4])); (netdev->dev_addr[3] << 24)
| (netdev->dev_addr[2] << 16)
| (netdev->dev_addr[1] << 8)
| (netdev->dev_addr[0]));
endpoint_writel(nic, EP_REG_MACH,
(netdev->dev_addr[5] << 8)
| (netdev->dev_addr[4]));
} }
...@@ -1032,7 +1039,8 @@ static int minic_set_mac_address(struct net_device *netdev, void* addr) ...@@ -1032,7 +1039,8 @@ static int minic_set_mac_address(struct net_device *netdev, void* addr)
memcpy(netdev->dev_addr, address->sa_data, netdev->addr_len); memcpy(netdev->dev_addr, address->sa_data, netdev->addr_len);
minic_update_mac(netdev); minic_update_mac(netdev);
// printk("%s: Setting MAC address to %pM\n", netdev->name, netdev->dev_addr); // printk("%s: Setting MAC address to %pM\n",
//netdev->name, netdev->dev_addr);
return 0; return 0;
} }
...@@ -1083,7 +1091,7 @@ static int __devinit minic_probe(struct platform_device *pdev) ...@@ -1083,7 +1091,7 @@ static int __devinit minic_probe(struct platform_device *pdev)
goto err_out; goto err_out;
} }
// printk("base-addr 0x%x-0x%x\n", base->start, base->end); // printk("base-addr 0x%x-0x%x\n", base->start, base->end);
SET_NETDEV_DEV(netdev, &pdev->dev); SET_NETDEV_DEV(netdev, &pdev->dev);
...@@ -1097,11 +1105,13 @@ static int __devinit minic_probe(struct platform_device *pdev) ...@@ -1097,11 +1105,13 @@ static int __devinit minic_probe(struct platform_device *pdev)
spin_lock_init(&nic->lock); spin_lock_init(&nic->lock);
nic->base = ioremap(base_minic->start, base_minic->end - base_minic->start + 1); nic->base = ioremap(base_minic->start,
nic->ppsg = ioremap(base_ppsg->start, base_ppsg->end - base_ppsg->start + 1); base_minic->end - base_minic->start + 1);
nic->ppsg = ioremap(base_ppsg->start,
base_ppsg->end - base_ppsg->start + 1);
// dev_info(&pdev->dev, "io at 0x%x, pbuf at 0x%x\n", nic->minic_regs, nic->pbuf); // dev_info(&pdev->dev, "io at 0x%x, pbuf at 0x%x\n",
// nic->minic_regs, nic->pbuf);
if (!nic->base || !nic->ppsg) { if (!nic->base || !nic->ppsg) {
// if (netif_msg_probe(nic)) // if (netif_msg_probe(nic))
...@@ -1117,18 +1127,16 @@ static int __devinit minic_probe(struct platform_device *pdev) ...@@ -1117,18 +1127,16 @@ static int __devinit minic_probe(struct platform_device *pdev)
netdev->base_addr = (u32) nic->base; netdev->base_addr = (u32) nic->base;
strcpy(netdev->name, (char *)pdev->dev.platform_data); strcpy(netdev->name, (char *)pdev->dev.platform_data);
if(endpoint_readl(nic, EP_REG_IDCODE) != 0xcafebabe) if(endpoint_readl(nic, EP_REG_IDCODE) != 0xcafebabe) {
{ printk(KERN_INFO "Looks like the port %s "
printk(KERN_INFO "Looks like the port %s hasn't been synthesized...\n", netdev->name); "hasn't been synthesized...\n", netdev->name);
free_netdev(netdev); free_netdev(netdev);
iounmap(nic->base); iounmap(nic->base);
iounmap(nic->ppsg); iounmap(nic->ppsg);
return 0 ; return 0 ;
} }
memset(netdev->dev_addr, 0, 6); memset(netdev->dev_addr, 0, 6);
// minic_get_mac_addr(nic); // minic_get_mac_addr(nic);
netdev->irq = platform_get_irq(pdev, 0); netdev->irq = platform_get_irq(pdev, 0);
...@@ -1137,7 +1145,6 @@ static int __devinit minic_probe(struct platform_device *pdev) ...@@ -1137,7 +1145,6 @@ static int __devinit minic_probe(struct platform_device *pdev)
goto err_out_iounmap; goto err_out_iounmap;
} }
err = wrmch_vic_request_irq(netdev->irq, minic_interrupt, netdev); err = wrmch_vic_request_irq(netdev->irq, minic_interrupt, netdev);
if (err) { if (err) {
...@@ -1167,7 +1174,6 @@ static int __devinit minic_probe(struct platform_device *pdev) ...@@ -1167,7 +1174,6 @@ static int __devinit minic_probe(struct platform_device *pdev)
nic->mii.advertising = ADVERTISE_1000XFULL; nic->mii.advertising = ADVERTISE_1000XFULL;
nic->mii.full_duplex = 1; nic->mii.full_duplex = 1;
err = register_netdev(netdev); err = register_netdev(netdev);
if (err) { if (err) {
// if (netif_msg_probe(nic)) // if (netif_msg_probe(nic))
...@@ -1185,13 +1191,13 @@ static int __devinit minic_probe(struct platform_device *pdev) ...@@ -1185,13 +1191,13 @@ static int __devinit minic_probe(struct platform_device *pdev)
return 0; return 0;
err_out_freeirq: err_out_freeirq:
free_irq(netdev->irq, &pdev->dev); free_irq(netdev->irq, &pdev->dev);
err_out_iounmap: err_out_iounmap:
iounmap(nic->base); iounmap(nic->base);
err_out_free_netdev: err_out_free_netdev:
free_netdev(netdev); free_netdev(netdev);
err_out: err_out:
platform_set_drvdata(pdev, NULL); platform_set_drvdata(pdev, NULL);
return err; return err;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment