/* select which firmware to use */ #define USE_HP_WORKAROUND #define HP_WORKAROUND_DEFAULT /* select which firmware to use as default */ #define CAS_HP_ALT_FIRMWARE cas_prog_null /* alternate firmware */
#include"cassini.h"
#define USE_TX_COMPWB /* use completion writeback registers */ #define USE_CSMA_CD_PROTO /* standard CSMA/CD */ #define USE_RX_BLANK /* hw interrupt mitigation */ #undef USE_ENTROPY_DEV /* don't test for entropy device */
/* NOTE: these aren't useable unless PCI interrupts can be assigned. *also,weneedtomakecp->lockfiner-grained.
*/ #undef USE_PCI_INTB #undef USE_PCI_INTC #undef USE_PCI_INTD #undef USE_QOS
#undef USE_VPD_DEBUG /* debug vpd information if defined */
/* rx processing options */ #define USE_PAGE_ORDER /* specify to allocate large rx pages */ #define RX_DONT_BATCH 0/* if 1, don't batch flows */ #define RX_COPY_ALWAYS 0/* if 0, use frags */ #define RX_COPY_MIN 64/* copy a little to make upper layers happy */ #undef RX_COUNT_BUFFERS /* define to calculate RX buffer stats */
/* length of time before we decide the hardware is borked, *anddev->tx_timeout()shouldbecalledtofixtheproblem
*/ #define CAS_TX_TIMEOUT (HZ) #define CAS_LINK_TIMEOUT (22*HZ/10) #define CAS_LINK_FAST_TIMEOUT (1)
/* timeout values for state changing. these specify the number *of10usdelaystobeusedbeforegivingup.
*/ #define STOP_TRIES_PHY 1000 #define STOP_TRIES 5000
/* specify a minimum frame size to deal with some fifo issues *maxmtu==2*pagesize-ethernetheader-64-swivel= *2*page_size-0x50
*/ #define CAS_MIN_FRAME 97 #define CAS_1000MB_MIN_FRAME 255 #define CAS_MIN_MTU 60 #define CAS_MAX_MTU min(((cp->page_size << 1) - 0x50), 9000)
staticinlinevoid cas_lock_tx(struct cas *cp)
{ int i;
for (i = 0; i < N_TX_RINGS; i++)
spin_lock_nested(&cp->tx_lock[i], i);
}
/* WTZ: QA was finding deadlock problems with the previous *versionsafterlongtestrunswithmultiplecardspermachine. *Seeifreplacingcas_lock_allwithsaferversionshelps.The *symptomsQAisreportingmatchthosewe'dexpectifinterrupts *aren'tbeingproperlyrestored,andwefixedapreviousdeadlock *withsimilarsymptomsbyusingsave/restoreversionsinother *places.
*/ #define cas_lock_all_save(cp, flags) \ do { \ struct cas *xxxcp = (cp); \
spin_lock_irqsave(&xxxcp->lock, flags); \
cas_lock_tx(xxxcp); \
} while (0)
staticinlinevoid cas_unlock_tx(struct cas *cp)
{ int i;
for (i = N_TX_RINGS; i > 0; i--)
spin_unlock(&cp->tx_lock[i - 1]);
}
#define cas_unlock_all_restore(cp, flags) \ do { \ struct cas *xxxcp = (cp); \
cas_unlock_tx(xxxcp); \
spin_unlock_irqrestore(&xxxcp->lock, flags); \
} while (0)
staticvoid cas_disable_irq(struct cas *cp, constint ring)
{ /* Make sure we won't get any more interrupts */ if (ring == 0) {
writel(0xFFFFFFFF, cp->regs + REG_INTR_MASK); return;
}
/* if we read back 0x0, we don't have an entropy device */ if (readb(cp->regs + REG_ENTROPY_RAND_REG) == 0)
cp->cas_flags &= ~CAS_FLAG_ENTROPY_DEV; #endif
}
/* access to the phy. the following assumes that we've initialized the MIF to *beinframeratherthanbit-bangmode
*/ static u16 cas_phy_read(struct cas *cp, int reg)
{
u32 cmd; int limit = STOP_TRIES_PHY;
/* initialize spare pool of rx buffers, but allocate during the open */ staticvoid cas_spare_init(struct cas *cp)
{
spin_lock(&cp->rx_inuse_lock);
INIT_LIST_HEAD(&cp->rx_inuse_list);
spin_unlock(&cp->rx_inuse_lock);
/* replenish spares if needed */ staticvoid cas_spare_recover(struct cas *cp, const gfp_t flags)
{ struct list_head list, *elem, *tmp; int needed, i;
/* check inuse list. if we don't need any more free buffers, *justfreeit
*/
/* make a local copy of the list */
INIT_LIST_HEAD(&list);
spin_lock(&cp->rx_inuse_lock);
list_splice_init(&cp->rx_inuse_list, &list);
spin_unlock(&cp->rx_inuse_lock);
/* put any inuse buffers back on the list */ if (!list_empty(&list)) {
spin_lock(&cp->rx_inuse_lock);
list_splice(&list, &cp->rx_inuse_list);
spin_unlock(&cp->rx_inuse_lock);
}
spin_lock(&cp->rx_spare_lock);
needed = cp->rx_spares_needed;
spin_unlock(&cp->rx_spare_lock); if (!needed) return;
/* we still need spares, so try to allocate some */
INIT_LIST_HEAD(&list);
i = 0; while (i < needed) {
cas_page_t *spare = cas_page_alloc(cp, flags); if (!spare) break;
list_add(&spare->list, &list);
i++;
}
if (cp->cas_flags & CAS_FLAG_1000MB_CAP) { /* make sure that we don't advertise half *duplextoavoidachipissue
*/
val = cas_phy_read(cp, CAS_MII_1000_CTRL);
val &= ~CAS_ADVERTISE_1000HALF;
val |= CAS_ADVERTISE_1000FULL;
cas_phy_write(cp, CAS_MII_1000_CTRL, val);
}
} else { /* reset pcs for serdes */
u32 val; int limit;
staticint cas_pcs_link_check(struct cas *cp)
{
u32 stat, state_machine; int retval = 0;
/* The link status bit latches on zero, so you must *readittwiceinsuchacasetoseeatransition *tothelinkbeingup.
*/
stat = readl(cp->regs + REG_PCS_MII_STATUS); if ((stat & PCS_MII_STATUS_LINK_STATUS) == 0)
stat = readl(cp->regs + REG_PCS_MII_STATUS);
/* The remote-fault indication is only valid *whenautoneghascompleted.
*/ if ((stat & (PCS_MII_STATUS_AUTONEG_COMP |
PCS_MII_STATUS_REMOTE_FAULT)) ==
(PCS_MII_STATUS_AUTONEG_COMP | PCS_MII_STATUS_REMOTE_FAULT))
netif_info(cp, link, cp->dev, "PCS RemoteFault\n");
/* work around link detection issue by querying the PCS state *machinedirectly.
*/
state_machine = readl(cp->regs + REG_PCS_STATE_MACHINE); if ((state_machine & PCS_SM_LINK_STATE_MASK) != SM_LINK_STATE_UP) {
stat &= ~PCS_MII_STATUS_LINK_STATUS;
} elseif (state_machine & PCS_SM_WORD_SYNC_STATE_MASK) {
stat |= PCS_MII_STATUS_LINK_STATUS;
}
if (stat & PCS_MII_STATUS_LINK_STATUS) { if (cp->lstate != link_up) { if (cp->opened) {
cp->lstate = link_up;
cp->link_transition = LINK_TRANSITION_LINK_UP;
/* Cassini only: if you force a mode, there can be *syncproblemsonlinkdown.tofixthat,thefollowing *thingsneedtobechecked: *1)readserialinkstateregister *2)readpcsstatusregistertoverifylinkdown. *3)iflinkdownandseriallink==0x03,thenyouneed *toglobalresetthechip.
*/ if ((cp->cas_flags & CAS_FLAG_REG_PLUS) == 0) { /* should check to see if we're in a forced mode */
stat = readl(cp->regs + REG_PCS_SERDES_STATE); if (stat == 0x03) return1;
}
} elseif (cp->lstate == link_down) { if (link_transition_timeout != 0 &&
cp->link_transition != LINK_TRANSITION_REQUESTED_RESET &&
!cp->link_transition_jiffies_valid) { /* force a reset, as a workaround for the *link-failureproblem.Maywanttomove *thistoapointabitearlierinthe *sequence.
*/
retval = 1;
cp->link_transition = LINK_TRANSITION_REQUESTED_RESET;
cp->link_transition_jiffies = jiffies;
cp->link_transition_jiffies_valid = 1;
} else {
cp->link_transition = LINK_TRANSITION_STILL_FAILED;
}
}
return retval;
}
staticint cas_pcs_interrupt(struct net_device *dev, struct cas *cp, u32 status)
{
u32 stat = readl(cp->regs + REG_PCS_INTR_STATUS);
if ((stat & PCS_INTR_STATUS_LINK_CHANGE) == 0) return0; return cas_pcs_link_check(cp);
}
/* We do not keep track of MAC_TX_COLL_FIRST and *MAC_TX_PEAK_ATTEMPTSevents.
*/ return0;
}
staticvoid cas_load_firmware(struct cas *cp, cas_hp_inst_t *firmware)
{
cas_hp_inst_t *inst;
u32 val; int i;
i = 0; while ((inst = firmware) && inst->note) {
writel(i, cp->regs + REG_HP_INSTR_RAM_ADDR);
val = CAS_BASE(HP_INSTR_RAM_HI_VAL, inst->val);
val |= CAS_BASE(HP_INSTR_RAM_HI_MASK, inst->mask);
writel(val, cp->regs + REG_HP_INSTR_RAM_DATA_HI);
val = CAS_BASE(HP_INSTR_RAM_MID_OUTARG, inst->outarg >> 10);
val |= CAS_BASE(HP_INSTR_RAM_MID_OUTOP, inst->outop);
val |= CAS_BASE(HP_INSTR_RAM_MID_FNEXT, inst->fnext);
val |= CAS_BASE(HP_INSTR_RAM_MID_FOFF, inst->foff);
val |= CAS_BASE(HP_INSTR_RAM_MID_SNEXT, inst->snext);
val |= CAS_BASE(HP_INSTR_RAM_MID_SOFF, inst->soff);
val |= CAS_BASE(HP_INSTR_RAM_MID_OP, inst->op);
writel(val, cp->regs + REG_HP_INSTR_RAM_DATA_MID);
val = CAS_BASE(HP_INSTR_RAM_LOW_OUTMASK, inst->outmask);
val |= CAS_BASE(HP_INSTR_RAM_LOW_OUTSHIFT, inst->outshift);
val |= CAS_BASE(HP_INSTR_RAM_LOW_OUTEN, inst->outenab);
val |= CAS_BASE(HP_INSTR_RAM_LOW_OUTARG, inst->outarg);
writel(val, cp->regs + REG_HP_INSTR_RAM_DATA_LOW);
++firmware;
++i;
}
}
staticvoid cas_init_rx_dma(struct cas *cp)
{
u64 desc_dma = cp->block_dvma;
u32 val; int i, size;
/* rx free descriptors */
val = CAS_BASE(RX_CFG_SWIVEL, RX_SWIVEL_OFF_VAL);
val |= CAS_BASE(RX_CFG_DESC_RING, RX_DESC_RINGN_INDEX(0));
val |= CAS_BASE(RX_CFG_COMP_RING, RX_COMP_RINGN_INDEX(0)); if ((N_RX_DESC_RINGS > 1) &&
(cp->cas_flags & CAS_FLAG_REG_PLUS)) /* do desc 2 */
val |= CAS_BASE(RX_CFG_DESC_RING1, RX_DESC_RINGN_INDEX(1));
writel(val, cp->regs + REG_RX_CFG);
/* set up pause thresholds */
val = CAS_BASE(RX_PAUSE_THRESH_OFF,
cp->rx_pause_off / RX_PAUSE_THRESH_QUANTUM);
val |= CAS_BASE(RX_PAUSE_THRESH_ON,
cp->rx_pause_on / RX_PAUSE_THRESH_QUANTUM);
writel(val, cp->regs + REG_RX_PAUSE_THRESH);
/* zero out dma reassembly buffers */ for (i = 0; i < 64; i++) {
writel(i, cp->regs + REG_RX_TABLE_ADDR);
writel(0x0, cp->regs + REG_RX_TABLE_DATA_LOW);
writel(0x0, cp->regs + REG_RX_TABLE_DATA_MID);
writel(0x0, cp->regs + REG_RX_TABLE_DATA_HI);
}
/* make sure address register is 0 for normal operation */
writel(0x0, cp->regs + REG_RX_CTRL_FIFO_ADDR);
writel(0x0, cp->regs + REG_RX_IPP_FIFO_ADDR);
/* interrupt generation as a function of low water marks for *freedescandcompletionentries.theseareusedtotrigger *housekeepingforrxdescs.wedon'tusethefreeinterrupt *asit'snotveryuseful
*/ /* val = CAS_BASE(RX_AE_THRESH_FREE, RX_AE_FREEN_VAL(0)); */
val = CAS_BASE(RX_AE_THRESH_COMP, RX_AE_COMP_VAL);
writel(val, cp->regs + REG_RX_AE_THRESH); if (cp->cas_flags & CAS_FLAG_REG_PLUS) {
val = CAS_BASE(RX_AE1_THRESH_FREE, RX_AE_FREEN_VAL(1));
writel(val, cp->regs + REG_PLUS_RX_AE1_THRESH);
}
/* Random early detect registers. useful for congestion avoidance. *thisshouldbetunable.
*/
writel(0x0, cp->regs + REG_RX_RED);
/* receive page sizes. default == 2K (0x800) */
val = 0; if (cp->page_size == 0x1000)
val = 0x1; elseif (cp->page_size == 0x2000)
val = 0x2; elseif (cp->page_size == 0x4000)
val = 0x3;
/* round mtu + offset. constrain to page size. */
size = cp->dev->mtu + 64; if (size > cp->page_size)
size = cp->page_size;
if (size <= 0x400)
i = 0x0; elseif (size <= 0x800)
i = 0x1; elseif (size <= 0x1000)
i = 0x2; else
i = 0x3;
cp->mtu_stride = 1 << (i + 10);
val = CAS_BASE(RX_PAGE_SIZE, val);
val |= CAS_BASE(RX_PAGE_SIZE_MTU_STRIDE, i);
val |= CAS_BASE(RX_PAGE_SIZE_MTU_COUNT, cp->page_size >> (i + 10));
val |= CAS_BASE(RX_PAGE_SIZE_MTU_OFF, 0x1);
writel(val, cp->regs + REG_RX_PAGE_SIZE);
/* enable the header parser if desired */ if (&CAS_HP_FIRMWARE[0] == &cas_prog_null[0]) return;
val = CAS_BASE(HP_CFG_NUM_CPU, CAS_NCPUS > 63 ? 0 : CAS_NCPUS);
val |= HP_CFG_PARSE_EN | HP_CFG_SYN_INC_MASK;
val |= CAS_BASE(HP_CFG_TCP_THRESH, HP_TCP_THRESH_VAL);
writel(val, cp->regs + REG_HP_CFG);
}
/* NOTE: we use the ENC RX DESC ring for spares. the rx_page[0,1] *flippingisprotectedbythefactthatthechipwillnot *handbackthesamepageindexwhileit'sbeingprocessed.
*/ staticinline cas_page_t *cas_page_spare(struct cas *cp, constint index)
{
cas_page_t *page = cp->rx_pages[1][index];
cas_page_t *new;
if (page_count(page->buffer) == 1) return page;
new = cas_page_dequeue(cp); if (new) {
spin_lock(&cp->rx_inuse_lock);
list_add(&page->list, &cp->rx_inuse_list);
spin_unlock(&cp->rx_inuse_lock);
} returnnew;
}
/* this needs to be changed if we actually use the ENC RX DESC ring */ static cas_page_t *cas_page_swap(struct cas *cp, constint ring, constint index)
{
cas_page_t **page0 = cp->rx_pages[0];
cas_page_t **page1 = cp->rx_pages[1];
/* swap if buffer is in use */ if (page_count(page0[index]->buffer) > 1) {
cas_page_t *new = cas_page_spare(cp, index); if (new) {
page1[index] = page0[index];
page0[index] = new;
}
}
RX_USED_SET(page0[index], 0); return page0[index];
}
staticvoid cas_clean_rxds(struct cas *cp)
{ /* only clean ring 0 as ring 1 is used for spare buffers */ struct cas_rx_desc *rxd = cp->init_rxds[0]; int i, size;
/* release all rx flows */ for (i = 0; i < N_RX_FLOWS; i++) { struct sk_buff *skb; while ((skb = __skb_dequeue(&cp->rx_flows[i]))) {
cas_skb_release(skb);
}
}
staticvoid cas_clean_rxcs(struct cas *cp)
{ int i, j;
/* take ownership of rx comp descriptors */
memset(cp->rx_cur, 0, sizeof(*cp->rx_cur)*N_RX_COMP_RINGS);
memset(cp->rx_new, 0, sizeof(*cp->rx_new)*N_RX_COMP_RINGS); for (i = 0; i < N_RX_COMP_RINGS; i++) { struct cas_rx_comp *rxc = cp->init_rxcs[i]; for (j = 0; j < RX_COMP_RINGN_SIZE(i); j++) {
cas_rxc_init(rxc + j);
}
}
}
#if0 /* When we get a RX fifo overflow, the RX unit is probably hung *sowedothefollowing. * *Ifanypartoftheresetgoeswrong,wereturn1andthatcausesthe *wholechiptobereset.
*/ staticint cas_rxmac_reset(struct cas *cp)
{ struct net_device *dev = cp->dev; int limit;
u32 val;
/* First, reset MAC RX. */
writel(cp->mac_rx_cfg & ~MAC_RX_CFG_EN, cp->regs + REG_MAC_RX_CFG); for (limit = 0; limit < STOP_TRIES; limit++) { if (!(readl(cp->regs + REG_MAC_RX_CFG) & MAC_RX_CFG_EN)) break;
udelay(10);
} if (limit == STOP_TRIES) {
netdev_err(dev, "RX MAC will not disable, resetting whole chip\n"); return1;
}
/* Second, disable RX DMA. */
writel(0, cp->regs + REG_RX_CFG); for (limit = 0; limit < STOP_TRIES; limit++) { if (!(readl(cp->regs + REG_RX_CFG) & RX_CFG_DMA_EN)) break;
udelay(10);
} if (limit == STOP_TRIES) {
netdev_err(dev, "RX DMA will not disable, resetting whole chip\n"); return1;
}
mdelay(5);
/* Execute RX reset command. */
writel(SW_RESET_RX, cp->regs + REG_SW_RESET); for (limit = 0; limit < STOP_TRIES; limit++) { if (!(readl(cp->regs + REG_SW_RESET) & SW_RESET_RX)) break;
udelay(10);
} if (limit == STOP_TRIES) {
netdev_err(dev, "RX reset command will not execute, resetting whole chip\n"); return1;
}
/* reset driver rx state */
cas_clean_rxds(cp);
cas_clean_rxcs(cp);
/* Now, reprogram the rest of RX unit. */
cas_init_rx_dma(cp);
/* This interrupt is just for pause frame and pause *tracking.Itisusefulfordiagnosticsanddebug *butprobablybydefaultwewillmasktheseevents.
*/ if (stat & MAC_CTRL_PAUSE_STATE)
cp->pause_entered++;
if (stat & MAC_CTRL_PAUSE_RECEIVED)
cp->pause_last_time_recvd = (stat >> 16);
return0;
}
/* Must be invoked under cp->lock. */ staticinlineint cas_mdio_link_not_up(struct cas *cp)
{
u16 val;
/* Try forced modes. we try things in the following order: *1000full->100full/half->10half
*/
val &= ~(BMCR_ANRESTART | BMCR_ANENABLE);
val |= BMCR_FULLDPLX;
val |= (cp->cas_flags & CAS_FLAG_1000MB_CAP) ?
CAS_BMCR_SPEED1000 : BMCR_SPEED100;
cas_phy_write(cp, MII_BMCR, val);
cp->timer_ticks = 5;
cp->lstate = link_force_try;
cp->link_transition = LINK_TRANSITION_LINK_CONFIG; break;
case link_force_try: /* Downgrade from 1000 to 100 to 10 Mbps if necessary. */
val = cas_phy_read(cp, MII_BMCR);
cp->timer_ticks = 5; if (val & CAS_BMCR_SPEED1000) { /* gigabit */
val &= ~CAS_BMCR_SPEED1000;
val |= (BMCR_SPEED100 | BMCR_FULLDPLX);
cas_phy_write(cp, MII_BMCR, val); break;
}
if (val & BMCR_SPEED100) { if (val & BMCR_FULLDPLX) /* fd failed */
val &= ~BMCR_FULLDPLX; else { /* 100Mbps failed */
val &= ~BMCR_SPEED100;
}
cas_phy_write(cp, MII_BMCR, val); break;
} break; default: break;
} return0;
}
/* must be invoked with cp->lock held */ staticint cas_mii_link_check(struct cas *cp, const u16 bmsr)
{ int restart;
if (bmsr & BMSR_LSTATUS) { /* Ok, here we got a link. If we had it due to a forced *fallback,andwewereconfiguredforautoneg,we *retryashortautonegpass.Ifyouknowyourhubis *broken,useethtool;)
*/ if ((cp->lstate == link_force_try) &&
(cp->link_cntl & BMCR_ANENABLE)) {
cp->lstate = link_force_ret;
cp->link_transition = LINK_TRANSITION_LINK_CONFIG;
cas_mif_poll(cp, 0);
cp->link_fcntl = cas_phy_read(cp, MII_BMCR);
cp->timer_ticks = 5; if (cp->opened)
netif_info(cp, link, cp->dev, "Got link after fallback, retrying autoneg once...\n");
cas_phy_write(cp, MII_BMCR,
cp->link_fcntl | BMCR_ANENABLE |
BMCR_ANRESTART);
cas_mif_poll(cp, 1);
if (cp->opened) {
cas_set_link_modes(cp);
netif_carrier_on(cp->dev);
}
} return0;
}
/* link not up. if the link was previously up, we restart the *wholeprocess
*/
restart = 0; if (cp->lstate == link_up) {
cp->lstate = link_down;
cp->link_transition = LINK_TRANSITION_LINK_DOWN;
if (status & INTR_PCS_STATUS) { if (cas_pcs_interrupt(dev, cp, status)) goto do_reset;
}
if (status & INTR_TX_MAC_STATUS) { if (cas_txmac_interrupt(dev, cp, status)) goto do_reset;
}
if (status & INTR_RX_MAC_STATUS) { if (cas_rxmac_interrupt(dev, cp, status)) goto do_reset;
}
if (status & INTR_MAC_CTRL_STATUS) { if (cas_mac_interrupt(dev, cp, status)) goto do_reset;
}
if (status & INTR_MIF_STATUS) { if (cas_mif_interrupt(dev, cp, status)) goto do_reset;
}
if (status & INTR_PCI_ERROR_STATUS) { if (cas_pci_interrupt(dev, cp, status)) goto do_reset;
} return0;
do_reset: #if1
atomic_inc(&cp->reset_task_pending);
atomic_inc(&cp->reset_task_pending_all);
netdev_err(dev, "reset called in cas_abnormal_irq [0x%x]\n", status);
schedule_work(&cp->reset_task); #else
atomic_set(&cp->reset_task_pending, CAS_RESET_ALL);
netdev_err(dev, "reset called in cas_abnormal_irq\n");
schedule_work(&cp->reset_task); #endif return1;
}
/* NOTE: CAS_TABORT returns 1 or 2 so that it can be used when *determiningwhethertodoanetif_stop/wakeup
*/ #define CAS_TABORT(x) (((x)->cas_flags & CAS_FLAG_TARGET_ABORT) ? 2 : 1) #define CAS_ROUND_PAGE(x) (((x) + PAGE_SIZE - 1) & PAGE_MASK) staticinlineint cas_calc_tabort(struct cas *cp, constunsignedlong addr, constint len)
{ unsignedlong off = addr + len;
if (CAS_TABORT(cp) == 1) return0; if ((CAS_ROUND_PAGE(off) - off) > TX_TARGET_ABORT_LEN) return0; return TX_TARGET_ABORT_LEN;
}
staticinlinevoid cas_tx_ringN(struct cas *cp, int ring, int limit)
{ struct cas_tx_desc *txds; struct sk_buff **skbs; struct net_device *dev = cp->dev; int entry, count;
if (!skb) { /* this should never occur */
entry = TX_DESC_NEXT(ring, entry); continue;
}
/* however, we might get only a partial skb release. */
count -= skb_shinfo(skb)->nr_frags +
+ cp->tx_tiny_use[ring][entry].nbufs + 1; if (count < 0) break;
/* this is wrong for multiple tx rings. the net device needs *multiplequeuesforthistodotherightthing.wewait *for2*packetstobeavailablewhenusingtinybuffers
*/ if (netif_queue_stopped(dev) &&
(TX_BUFFS_AVAIL(cp, ring) > CAS_TABORT(cp)*(MAX_SKB_FRAGS + 1)))
netif_wake_queue(dev);
spin_unlock(&cp->tx_lock[ring]);
}
staticvoid cas_tx(struct net_device *dev, struct cas *cp,
u32 status)
{ int limit, ring; #ifdef USE_TX_COMPWB
u64 compwb = le64_to_cpu(cp->init_block->tx_compwb); #endif
netif_printk(cp, intr, KERN_DEBUG, cp->dev, "tx interrupt, status: 0x%x, %llx\n",
status, (unsignedlonglong)compwb); /* process all the rings */ for (ring = 0; ring < N_TX_RINGS; ring++) { #ifdef USE_TX_COMPWB /* use the completion writeback registers */
limit = (CAS_VAL(TX_COMPWB_MSB, compwb) << 8) |
CAS_VAL(TX_COMPWB_LSB, compwb);
compwb = TX_COMPWB_NEXT(compwb); #else
limit = readl(cp->regs + REG_TX_COMPN(ring)); #endif if (cp->tx_old[ring] != limit)
cas_tx_ringN(cp, ring, limit);
}
}
staticint cas_rx_process_pkt(struct cas *cp, struct cas_rx_comp *rxc, int entry, const u64 *words, struct sk_buff **skbref)
{ int dlen, hlen, len, i, alloclen; int off, swivel = RX_SWIVEL_OFF_VAL; struct cas_page *page; struct sk_buff *skb; void *crcaddr;
__sum16 csum; char *p;
/* normal or jumbo packets. we use frags */
i = CAS_VAL(RX_COMP1_DATA_INDEX, words[0]);
page = cp->rx_pages[CAS_VAL(RX_INDEX_RING, i)][CAS_VAL(RX_INDEX_NUM, i)];
off = CAS_VAL(RX_COMP1_DATA_OFF, words[0]) + swivel;
hlen = min(cp->page_size - off, dlen); if (hlen < 0) {
netif_printk(cp, rx_err, KERN_DEBUG, cp->dev, "rx page overflow: %d\n", hlen);
dev_kfree_skb_irq(skb); return -1;
}
i = hlen; if (i == dlen) /* attach FCS */
i += cp->crc_size;
dma_sync_single_for_cpu(&cp->pdev->dev, page->dma_addr + off,
i, DMA_FROM_DEVICE);
/* make sure we always copy a header */
swivel = 0; if (p == (char *) skb->data) { /* not split */
memcpy(p, page_address(page->buffer) + off,
RX_COPY_MIN);
dma_sync_single_for_device(&cp->pdev->dev,
page->dma_addr + off, i,
DMA_FROM_DEVICE);
off += RX_COPY_MIN;
swivel = RX_COPY_MIN;
RX_USED_ADD(page, cp->mtu_stride);
} else {
RX_USED_ADD(page, hlen);
}
skb_put(skb, alloclen);
/* we can handle up to 64 rx flows at a time. we do the same thing *asnonreassmexceptthatwebatchupthebuffers. *NOTE:wecurrentlyjusttreateachflowasabunchofpacketsthat *wepassup.abetterwaywouldbetocoalescethepackets *intoajumbopacket.todothat,weneedtodothefollowing: *1)thefirstpacketwillhaveacleansplitbetweenheaderand *data.saveboth. *2)eachtimethenextflowpacketcomesin,extendthe *datalengthandmergethechecksums. *3)onflowrelease,fixuptheheader. *4)makesurethehigherlayerdoesn'tcare. *becausepacketsgetcoalesced,weshouldn'trunintofragmentcount *issues.
*/ staticinlinevoid cas_rx_flow_pkt(struct cas *cp, const u64 *words, struct sk_buff *skb)
{ int flowid = CAS_VAL(RX_COMP3_FLOWID, words[2]) & (N_RX_FLOWS - 1); struct sk_buff_head *flow = &cp->rx_flows[flowid];
/* this is protected at a higher layer, so no need to *doanyadditionallockinghere.stickthebuffer *attheend.
*/
__skb_queue_tail(flow, skb); if (words[0] & RX_COMP1_RELEASE_FLOW) { while ((skb = __skb_dequeue(flow))) {
cas_skb_release(skb);
}
}
}
/* put rx descriptor back on ring. if a buffer is in use by a higher *layer,thiswillneedtoputinareplacement.
*/ staticvoid cas_post_page(struct cas *cp, constint ring, constint index)
{
cas_page_t *new; int entry;
/* only when things are bad */ staticint cas_post_rxds_ringN(struct cas *cp, int ring, int num)
{ unsignedint entry, last, count, released; int cluster;
cas_page_t **page = cp->rx_pages[ring];
cluster = -1;
count = entry & 0x3;
last = RX_DESC_ENTRY(ring, num ? entry + num - 4: entry - 4);
released = 0; while (entry != last) { /* make a new buffer if it's still in use */ if (page_count(page[entry]->buffer) > 1) {
cas_page_t *new = cas_page_dequeue(cp); if (!new) { /* let the timer know that we need to *dothisagain
*/
cp->cas_flags |= CAS_FLAG_RXD_POST(ring); if (!timer_pending(&cp->link_timer))
mod_timer(&cp->link_timer, jiffies +
CAS_LINK_FAST_TIMEOUT);
cp->rx_old[ring] = entry;
cp->rx_last[ring] = num ? num - released : 0; return -ENOMEM;
}
spin_lock(&cp->rx_inuse_lock);
list_add(&page[entry]->list, &cp->rx_inuse_list);
spin_unlock(&cp->rx_inuse_lock);
cp->init_rxds[ring][entry].buffer =
cpu_to_le64(new->dma_addr);
page[entry] = new;
/* process a completion ring. packets are set up in three basic ways: *smallpackets:shouldbecopiedheader+datainsinglebuffer. *largepackets:headeranddatainasinglebuffer. *splitpackets:headerinaseparatebufferfromdata. *datamaybeinmultiplepages.datamaybe>256 *bytesbutinasinglepage. * *NOTE:RXpagepostingisdoneinthisroutineaswell.whilethere's *thecapabilityofusingmultipleRXcompletionrings,itisn't *reallyworthwhileduetothefactthatthepagepostingwill *forceserializationonthesingledescriptorring.
*/ staticint cas_rx_ringN(struct cas *cp, int ring, int budget)
{ struct cas_rx_comp *rxcs = cp->init_rxcs[ring]; int entry, drops; int npackets = 0;
/* don't touch if still owned by hw */
type = CAS_VAL(RX_COMP1_TYPE, words[0]); if (type == 0) break;
/* hw hasn't cleared the zero bit yet */ if (words[3] & RX_COMP4_ZERO) { break;
}
/* get info on the packet */ if (words[3] & (RX_COMP4_LEN_MISMATCH | RX_COMP4_BAD)) {
spin_lock(&cp->stat_lock[ring]);
cp->net_stats[ring].rx_errors++; if (words[3] & RX_COMP4_LEN_MISMATCH)
cp->net_stats[ring].rx_length_errors++; if (words[3] & RX_COMP4_BAD)
cp->net_stats[ring].rx_crc_errors++;
spin_unlock(&cp->stat_lock[ring]);
/* We'll just return it to Cassini. */
drop_it:
spin_lock(&cp->stat_lock[ring]);
++cp->net_stats[ring].rx_dropped;
spin_unlock(&cp->stat_lock[ring]); goto next;
}
len = cas_rx_process_pkt(cp, rxc, entry, words, &skb); if (len < 0) {
++drops; goto drop_it;
}
/* see if it's a flow re-assembly or not. the driver *itselfhandlesreleasebackup.
*/ if (RX_DONT_BATCH || (type == 0x2)) { /* non-reassm: these always get released */
cas_skb_release(skb);
} else {
cas_rx_flow_pkt(cp, words, skb);
}
/* should it be released? */ if (words[0] & RX_COMP1_RELEASE_HDR) {
i = CAS_VAL(RX_COMP2_HDR_INDEX, words[1]);
dring = CAS_VAL(RX_INDEX_RING, i);
i = CAS_VAL(RX_INDEX_NUM, i);
cas_post_page(cp, dring, i);
}
if (words[0] & RX_COMP1_RELEASE_DATA) {
i = CAS_VAL(RX_COMP1_DATA_INDEX, words[0]);
dring = CAS_VAL(RX_INDEX_RING, i);
i = CAS_VAL(RX_INDEX_NUM, i);
cas_post_page(cp, dring, i);
}
if (words[0] & RX_COMP1_RELEASE_NEXT) {
i = CAS_VAL(RX_COMP2_NEXT_INDEX, words[1]);
dring = CAS_VAL(RX_INDEX_RING, i);
i = CAS_VAL(RX_INDEX_NUM, i);
cas_post_page(cp, dring, i);
}
/* skip to the next entry */
entry = RX_COMP_ENTRY(ring, entry + 1 +
CAS_VAL(RX_COMP1_SKIP, words[0])); #ifdef USE_NAPI if (budget && (npackets >= budget)) break; #endif
}
cp->rx_new[ring] = entry;
if (drops)
netdev_info(cp->dev, "Memory squeeze, deferring packet\n"); return npackets;
}
/* put completion entries back on the ring */ staticvoid cas_post_rxcs_ringN(struct net_device *dev, struct cas *cp, int ring)
{ struct cas_rx_comp *rxc = cp->init_rxcs[ring]; int last, entry;
/* cassini can use all four PCI interrupts for the completion ring. *rings3and4areidentical
*/ #ifdefined(USE_PCI_INTC) || defined(USE_PCI_INTD) staticinlinevoid cas_handle_irqN(struct net_device *dev, struct cas *cp, const u32 status, constint ring)
{ if (status & (INTR_RX_COMP_FULL_ALT | INTR_RX_COMP_AF_ALT))
cas_post_rxcs_ringN(dev, cp, ring);
}
static irqreturn_t cas_interruptN(int irq, void *dev_id)
{ struct net_device *dev = dev_id; struct cas *cp = netdev_priv(dev); unsignedlong flags; int ring = (irq == cp->pci_irq_INTC) ? 2 : 3;
u32 status = readl(cp->regs + REG_PLUS_INTRN_STATUS(ring));
/* check for shared irq */ if (status == 0) return IRQ_NONE;
#ifdef USE_PCI_INTB /* everything but rx packets */ staticinlinevoid cas_handle_irq1(struct cas *cp, const u32 status)
{ if (status & INTR_RX_BUF_UNAVAIL_1) { /* Frame arrived, no free RX buffers available.
* NOTE: we can get this on a link transition. */
cas_post_rxds_ringN(cp, 1, 0);
spin_lock(&cp->stat_lock[1]);
cp->net_stats[1].rx_dropped++;
spin_unlock(&cp->stat_lock[1]);
}
if (status & INTR_RX_BUF_AE_1)
cas_post_rxds_ringN(cp, 1, RX_DESC_RINGN_SIZE(1) -
RX_AE_FREEN_VAL(1));
if (status & (INTR_RX_COMP_AF | INTR_RX_COMP_FULL))
cas_post_rxcs_ringN(cp, 1);
}
/* ring 2 handles a few more events than 3 and 4 */ static irqreturn_t cas_interrupt1(int irq, void *dev_id)
{ struct net_device *dev = dev_id; struct cas *cp = netdev_priv(dev); unsignedlong flags;
u32 status = readl(cp->regs + REG_PLUS_INTRN_STATUS(1));
/* check for shared interrupt */ if (status == 0) return IRQ_NONE;
/* NAPI rx packets. we spread the credits across all of the *rxcrings * *tomakesurewe'refairwiththeworkweloopthrougheach *ringN_RX_COMP_RINGtimeswitharequestof *budget/N_RX_COMP_RINGS
*/
enable_intr = 1;
credits = 0; for (i = 0; i < N_RX_COMP_RINGS; i++) { int j; for (j = 0; j < N_RX_COMP_RINGS; j++) {
credits += cas_rx_ringN(cp, j, budget / N_RX_COMP_RINGS); if (credits >= budget) {
enable_intr = 0; goto rx_comp;
}
}
}
rx_comp: /* final rx completion */
spin_lock_irqsave(&cp->lock, flags); if (status)
cas_handle_irq(dev, cp, status);
#ifdef USE_PCI_INTB if (N_RX_COMP_RINGS > 1) {
status = readl(cp->regs + REG_PLUS_INTRN_STATUS(1)); if (status)
cas_handle_irq1(dev, cp, status);
} #endif
#ifdef USE_PCI_INTC if (N_RX_COMP_RINGS > 2) {
status = readl(cp->regs + REG_PLUS_INTRN_STATUS(2)); if (status)
cas_handle_irqN(dev, cp, status, 2);
} #endif
#ifdef USE_PCI_INTD if (N_RX_COMP_RINGS > 3) {
status = readl(cp->regs + REG_PLUS_INTRN_STATUS(3)); if (status)
cas_handle_irqN(dev, cp, status, 3);
} #endif
spin_unlock_irqrestore(&cp->lock, flags); if (enable_intr) {
napi_complete(napi);
cas_unmask_intr(cp);
} return credits;
} #endif
staticinlineint cas_intme(int ring, int entry)
{ /* Algorithm: IRQ every 1/2 of descriptors. */ if (!(entry & ((TX_DESC_RINGN_SIZE(ring) >> 1) - 1))) return1; return0;
}
staticvoid cas_write_txd(struct cas *cp, int ring, int entry,
dma_addr_t mapping, int len, u64 ctrl, int last)
{ struct cas_tx_desc *txd = cp->init_txds[ring] + entry;
staticinlineint cas_xmit_tx_ringN(struct cas *cp, int ring, struct sk_buff *skb)
{ struct net_device *dev = cp->dev; int entry, nr_frags, frag, tabort, tentry;
dma_addr_t mapping; unsignedlong flags;
u64 ctrl;
u32 len;
spin_lock_irqsave(&cp->tx_lock[ring], flags);
/* This is a hard error, log it. */ if (TX_BUFFS_AVAIL(cp, ring) <=
CAS_TABORT(cp)*(skb_shinfo(skb)->nr_frags + 1)) {
netif_stop_queue(dev);
spin_unlock_irqrestore(&cp->tx_lock[ring], flags);
netdev_err(dev, "BUG! Tx Ring full when queue awake!\n"); return1;
}
/* this is only used as a load-balancing hint, so it doesn't *needtobeSMPsafe
*/ staticint ring;
if (skb_padto(skb, cp->min_frame_size)) return NETDEV_TX_OK;
/* XXX: we need some higher-level QoS hooks to steer packets to *individualqueues.
*/ if (cas_xmit_tx_ringN(cp, ring++ & N_TX_RINGS_MASK, skb)) return NETDEV_TX_BUSY; return NETDEV_TX_OK;
}
staticvoid cas_init_tx_dma(struct cas *cp)
{
u64 desc_dma = cp->block_dvma; unsignedlong off;
u32 val; int i;
/* set up tx completion writeback registers. must be 8-byte aligned */ #ifdef USE_TX_COMPWB
off = offsetof(struct cas_init_block, tx_compwb);
writel((desc_dma + off) >> 32, cp->regs + REG_TX_COMPWB_DB_HI);
writel((desc_dma + off) & 0xffffffff, cp->regs + REG_TX_COMPWB_DB_LOW); #endif
/* write out tx ring info and tx desc bases */ for (i = 0; i < MAX_TX_RINGS; i++) {
off = (unsignedlong) cp->init_txds[i] -
(unsignedlong) cp->init_block;
val |= CAS_TX_RINGN_BASE(i);
writel((desc_dma + off) >> 32, cp->regs + REG_TX_DBN_HI(i));
writel((desc_dma + off) & 0xffffffff, cp->regs +
REG_TX_DBN_LOW(i)); /* don't zero out the kick register here as the system *willwedge
*/
}
writel(val, cp->regs + REG_TX_CFG);
/* program max burst sizes. these numbers should be different *ifdoingQoS.
*/ #ifdef USE_QOS
writel(0x800, cp->regs + REG_TX_MAXBURST_0);
writel(0x1600, cp->regs + REG_TX_MAXBURST_1);
writel(0x2400, cp->regs + REG_TX_MAXBURST_2);
writel(0x4800, cp->regs + REG_TX_MAXBURST_3); #else
writel(0x800, cp->regs + REG_TX_MAXBURST_0);
writel(0x800, cp->regs + REG_TX_MAXBURST_1);
writel(0x800, cp->regs + REG_TX_MAXBURST_2);
writel(0x800, cp->regs + REG_TX_MAXBURST_3); #endif
}
/* Must be invoked under cp->lock. */ staticinlinevoid cas_init_dma(struct cas *cp)
{
cas_init_tx_dma(cp);
cas_init_rx_dma(cp);
}
staticvoid cas_process_mc_list(struct cas *cp)
{
u16 hash_table[16];
u32 crc; struct netdev_hw_addr *ha; int i = 1;
memset(hash_table, 0, sizeof(hash_table));
netdev_for_each_mc_addr(ha, cp->dev) { if (i <= CAS_MC_EXACT_MATCH_SIZE) { /* use the alternate mac address registers for the *first15multicastaddresses
*/
writel((ha->addr[4] << 8) | ha->addr[5],
cp->regs + REG_MAC_ADDRN(i*3 + 0));
writel((ha->addr[2] << 8) | ha->addr[3],
cp->regs + REG_MAC_ADDRN(i*3 + 1));
writel((ha->addr[0] << 8) | ha->addr[1],
cp->regs + REG_MAC_ADDRN(i*3 + 2));
i++;
} else { /* use hw hash table for the next series of *multicastaddresses
*/
crc = ether_crc_le(ETH_ALEN, ha->addr);
crc >>= 24;
hash_table[crc >> 4] |= 1 << (15 - (crc & 0xf));
}
} for (i = 0; i < 16; i++)
writel(hash_table[i], cp->regs + REG_MAC_HASH_TABLEN(i));
}
/* Must be invoked under cp->lock. */ static u32 cas_setup_multicast(struct cas *cp)
{
u32 rxcfg = 0; int i;
if (cp->dev->flags & IFF_PROMISC) {
rxcfg |= MAC_RX_CFG_PROMISC_EN;
} elseif (cp->dev->flags & IFF_ALLMULTI) { for (i=0; i < 16; i++)
writel(0xFFFF, cp->regs + REG_MAC_HASH_TABLEN(i));
rxcfg |= MAC_RX_CFG_HASH_FILTER_EN;
/* Must be invoked under cp->lock. */ staticvoid cas_init_mac(struct cas *cp)
{ constunsignedchar *e = &cp->dev->dev_addr[0]; int i;
cas_mac_reset(cp);
#if !defined(CONFIG_SPARC64) && !defined(CONFIG_ALPHA) /* set the infinite burst register for chips that don't have *pciissues.
*/ if ((cp->cas_flags & CAS_FLAG_TARGET_ABORT) == 0)
writel(INF_BURST_EN, cp->regs + REG_INF_BURST); #endif
/* Setup MAC interrupts. We want to get all of the interesting *counterexpirationevents,butwedonotwanttohearabout *normalrx/txastheDMAenginetellsusthat.
*/
writel(MAC_TX_FRAME_XMIT, cp->regs + REG_MAC_TX_MASK);
writel(MAC_RX_FRAME_RECV, cp->regs + REG_MAC_RX_MASK);
/* Don't enable even the PAUSE interrupts for now, we *makenouseofthoseeventsotherthantorecordthem.
*/
writel(0xffffffff, cp->regs + REG_MAC_CTRL_MASK);
}
/* Must be invoked under cp->lock. */ staticvoid cas_init_pause_thresholds(struct cas *cp)
{ /* Calculate pause thresholds. Setting the OFF threshold to the *fullRXfifosizeeffectivelydisablesPAUSEgeneration
*/ if (cp->rx_fifo_size <= (2 * 1024)) {
cp->rx_pause_off = cp->rx_pause_on = cp->rx_fifo_size;
} else { int max_frame = (cp->dev->mtu + ETH_HLEN + 4 + 4 + 64) & ~63; if (max_frame * 3 > cp->rx_fifo_size) {
cp->rx_pause_off = 7104;
cp->rx_pause_on = 960;
} else { int off = (cp->rx_fifo_size - (max_frame * 2)); int on = off - max_frame;
cp->rx_pause_off = off;
cp->rx_pause_on = on;
}
}
}
staticint cas_vpd_match(constvoid __iomem *p, constchar *str)
{ int len = strlen(str) + 1; int i;
for (i = 0; i < len; i++) { if (readb(p + i) != str[i]) return0;
} return1;
}
/* get the mac address by reading the vpd information in the rom. *alsogetthephytypeanddetermineifthere'sanentropygenerator. *NOTE:thisisabitconvolutedforthefollowingreasons: *1)vpdinfohasorder-dependentmacaddressesformultiniccards *2)theonlywaytodeterminethenicorderistousetheslot *number. *3)fibercardsdon'thavebridges,sotheirslotnumbersdon't *meananything. *4)wedon'tactuallyknowwehaveafibercarduntilafter *themacaddressesareparsed.
*/ staticint cas_get_vpd_info(struct cas *cp, unsignedchar *dev_addr, constint offset)
{ void __iomem *p = cp->regs + REG_EXPANSION_ROM_RUN_START; void __iomem *base, *kstart; int i, len; int found = 0; #define VPD_FOUND_MAC 0x01 #define VPD_FOUND_PHY 0x02
int phy_type = CAS_PHY_MII_MDIO0; /* default phy type */ int mac_off = 0;
/* give us access to the PROM */
writel(BIM_LOCAL_DEV_PROM | BIM_LOCAL_DEV_PAD,
cp->regs + REG_BIM_LOCAL_DEV_EN);
/* check for an expansion rom */ if (readb(p) != 0x55 || readb(p + 1) != 0xaa) goto use_random_mac_addr;
/* search for beginning of vpd */
base = NULL; for (i = 2; i < EXPANSION_ROM_SIZE; i++) { /* check for PCIR */ if ((readb(p + i + 0) == 0x50) &&
(readb(p + i + 1) == 0x43) &&
(readb(p + i + 2) == 0x49) &&
(readb(p + i + 3) == 0x52)) {
base = p + (readb(p + i + 8) |
(readb(p + i + 9) << 8)); break;
}
}
if (!base || (readb(base) != 0x82)) goto use_random_mac_addr;
i = (readb(base + 1) | (readb(base + 2) << 8)) + 3; while (i < EXPANSION_ROM_SIZE) { if (readb(base + i) != 0x90) /* no vpd found */ goto use_random_mac_addr;
/* found a vpd field */
len = readb(base + i + 1) | (readb(base + i + 2) << 8);
/* extract keywords */
kstart = base + i + 3;
p = kstart; while ((p - kstart) < len) { int klen = readb(p + 2); int j; char type;
/* Sun MAC prefix then 3 random bytes. */
pr_info("MAC address not found in ROM VPD\n");
dev_addr[0] = 0x08;
dev_addr[1] = 0x00;
dev_addr[2] = 0x20;
get_random_bytes(dev_addr + 3, 3);
cp->cas_flags = 0; if ((pdev->vendor == PCI_VENDOR_ID_SUN) &&
(pdev->device == PCI_DEVICE_ID_SUN_CASSINI)) { if (pdev->revision >= CAS_ID_REVPLUS)
cp->cas_flags |= CAS_FLAG_REG_PLUS; if (pdev->revision < CAS_ID_REVPLUS02u)
cp->cas_flags |= CAS_FLAG_TARGET_ABORT;
/* Original Cassini supports HW CSUM, but it's not *enabledbydefaultasitcantriggerTXhangs.
*/ if (pdev->revision < CAS_ID_REV2)
cp->cas_flags |= CAS_FLAG_NO_HW_CSUM;
} else { /* Only sun has original cassini chips. */
cp->cas_flags |= CAS_FLAG_REG_PLUS;
/* We use a flag because the same phy might be externally *connected.
*/ if ((pdev->vendor == PCI_VENDOR_ID_NS) &&
(pdev->device == PCI_DEVICE_ID_NS_SATURN))
cp->cas_flags |= CAS_FLAG_SATURN;
}
}
staticint cas_check_invariants(struct cas *cp)
{ struct pci_dev *pdev = cp->pdev;
u8 addr[ETH_ALEN];
u32 cfg; int i;
/* get page size for rx buffers. */
cp->page_order = 0; #ifdef USE_PAGE_ORDER if (PAGE_SHIFT < CAS_JUMBO_PAGE_SHIFT) { /* see if we can allocate larger pages */ struct page *page = alloc_pages(GFP_ATOMIC,
CAS_JUMBO_PAGE_SHIFT -
PAGE_SHIFT); if (page) {
__free_pages(page, CAS_JUMBO_PAGE_SHIFT - PAGE_SHIFT);
cp->page_order = CAS_JUMBO_PAGE_SHIFT - PAGE_SHIFT;
} else {
printk("MTU limited to %d bytes\n", CAS_MAX_MTU);
}
} #endif
cp->page_size = (PAGE_SIZE << cp->page_order);
done: /* see if we can do gigabit */
cfg = cas_phy_read(cp, MII_BMSR); if ((cfg & CAS_BMSR_1000_EXTEND) &&
cas_phy_read(cp, CAS_MII_1000_EXTEND))
cp->cas_flags |= CAS_FLAG_1000MB_CAP; return0;
}
/* Must be invoked under cp->lock. */ staticinlinevoid cas_start_dma(struct cas *cp)
{ int i;
u32 val; int txfailed = 0;
if (cp->cas_flags & CAS_FLAG_REG_PLUS) { if (N_RX_DESC_RINGS > 1)
writel(RX_DESC_RINGN_SIZE(1) - 4,
cp->regs + REG_PLUS_RX_KICK1);
}
}
/* Must be invoked under cp->lock. */ staticvoid cas_read_pcs_link_mode(struct cas *cp, int *fd, int *spd, int *pause)
{
u32 val = readl(cp->regs + REG_PCS_MII_LPA);
*fd = (val & PCS_MII_LPA_FD) ? 1 : 0;
*pause = (val & PCS_MII_LPA_SYM_PAUSE) ? 0x01 : 0x00; if (val & PCS_MII_LPA_ASYM_PAUSE)
*pause |= 0x10;
*spd = 1000;
}
/* Must be invoked under cp->lock. */ staticvoid cas_read_mii_link_mode(struct cas *cp, int *fd, int *spd, int *pause)
{
u32 val;
*fd = 0;
*spd = 10;
*pause = 0;
/* use GMII registers */
val = cas_phy_read(cp, MII_LPA); if (val & CAS_LPA_PAUSE)
*pause = 0x01;
if (val & CAS_LPA_ASYM_PAUSE)
*pause |= 0x10;
if (val & LPA_DUPLEX)
*fd = 1; if (val & LPA_100)
*spd = 100;
if (cp->cas_flags & CAS_FLAG_1000MB_CAP) {
val = cas_phy_read(cp, CAS_MII_1000_STATUS); if (val & (CAS_LPA_1000FULL | CAS_LPA_1000HALF))
*spd = 1000; if (val & CAS_LPA_1000FULL)
*fd = 1;
}
}
/* A link-up condition has occurred, initialize and enable the *restofthechip. * *Mustbeinvokedundercp->lock.
*/ staticvoid cas_set_link_modes(struct cas *cp)
{
u32 val; int full_duplex, speed, pause;
full_duplex = 0;
speed = 10;
pause = 0;
if (CAS_PHY_MII(cp->phy_type)) {
cas_mif_poll(cp, 0);
val = cas_phy_read(cp, MII_BMCR); if (val & BMCR_ANENABLE) {
cas_read_mii_link_mode(cp, &full_duplex, &speed,
&pause);
} else { if (val & BMCR_FULLDPLX)
full_duplex = 1;
} else {
val = readl(cp->regs + REG_PCS_MII_CTRL);
cas_read_pcs_link_mode(cp, &full_duplex, &speed, &pause); if ((val & PCS_MII_AUTONEG_EN) == 0) { if (val & PCS_MII_CTRL_DUPLEX)
full_duplex = 1;
}
}
netif_info(cp, link, cp->dev, "Link up at %d Mbps, %s-duplex\n",
speed, full_duplex ? "full" : "half");
val = MAC_XIF_TX_MII_OUTPUT_EN | MAC_XIF_LINK_LED; if (CAS_PHY_MII(cp->phy_type)) {
val |= MAC_XIF_MII_BUFFER_OUTPUT_EN; if (!full_duplex)
val |= MAC_XIF_DISABLE_ECHO;
} if (full_duplex)
val |= MAC_XIF_FDPLX_LED; if (speed == 1000)
val |= MAC_XIF_GMII_MODE;
writel(val, cp->regs + REG_MAC_XIF_CFG);
/* deal with carrier and collision detect. */
val = MAC_TX_CFG_IPG_EN; if (full_duplex) {
val |= MAC_TX_CFG_IGNORE_CARRIER;
val |= MAC_TX_CFG_IGNORE_COLL;
} else { #ifndef USE_CSMA_CD_PROTO
val |= MAC_TX_CFG_NEVER_GIVE_UP_EN;
val |= MAC_TX_CFG_NEVER_GIVE_UP_LIM; #endif
} /* val now set up for REG_MAC_TX_CFG */
/* If gigabit and half-duplex, enable carrier extension *mode.increaseslottimeto512bytesaswell. *else,disableitandmakesureslottimeis64bytes. *alsoactivatechecksumbugworkaround
*/ if ((speed == 1000) && !full_duplex) {
writel(val | MAC_TX_CFG_CARRIER_EXTEND,
cp->regs + REG_MAC_TX_CFG);
val = readl(cp->regs + REG_MAC_RX_CFG);
val &= ~MAC_RX_CFG_STRIP_FCS; /* checksum workaround */
writel(val | MAC_RX_CFG_CARRIER_EXTEND,
cp->regs + REG_MAC_RX_CFG);
/* Must be invoked under cp->lock. on earlier cassini boards, *SOFT_0istiedtoPCIreset.weusethistoforceapcireset, *letitsettleout,andthenrestorepcistate.
*/ staticvoid cas_hard_reset(struct cas *cp)
{
writel(BIM_LOCAL_DEV_SOFT_0, cp->regs + REG_BIM_LOCAL_DEV_EN);
udelay(20);
pci_restore_state(cp->pdev);
}
staticvoid cas_global_reset(struct cas *cp, int blkflag)
{ int limit;
/* issue a global reset. don't use RSTOUT. */ if (blkflag && !CAS_PHY_MII(cp->phy_type)) { /* For PCS, when the blkflag is set, we should set the *SW_REST_BLOCK_PCS_SLINKbittopreventtheresultsof *thelastautonegotiationfrombeingcleared.We'll *needsomespecialhandlingifthechipissetintoa *loopbackmode.
*/
writel((SW_RESET_TX | SW_RESET_RX | SW_RESET_BLOCK_PCS_SLINK),
cp->regs + REG_SW_RESET);
} else {
writel(SW_RESET_TX | SW_RESET_RX, cp->regs + REG_SW_RESET);
}
/* need to wait at least 3ms before polling register */
mdelay(3);
limit = STOP_TRIES; while (limit-- > 0) {
u32 val = readl(cp->regs + REG_SW_RESET); if ((val & (SW_RESET_TX | SW_RESET_RX)) == 0) goto done;
udelay(10);
}
netdev_err(cp->dev, "sw reset failed\n");
/* clear out error registers */
spin_lock(&cp->stat_lock[N_TX_RINGS]);
cas_clear_mac_err(cp);
spin_unlock(&cp->stat_lock[N_TX_RINGS]);
}
/* Shut down the chip, must be called with pm_mutex held. */ staticvoid cas_shutdown(struct cas *cp)
{ unsignedlong flags;
/* Make us not-running to avoid timers respawning */
cp->hw_running = 0;
timer_delete_sync(&cp->link_timer);
/* Stop the reset task */ #if0 while (atomic_read(&cp->reset_task_pending_mtu) ||
atomic_read(&cp->reset_task_pending_spare) ||
atomic_read(&cp->reset_task_pending_all))
schedule();
#else while (atomic_read(&cp->reset_task_pending))
schedule(); #endif /* Actually stop the chip */
cas_lock_all_save(cp, flags);
cas_reset(cp, 0); if (cp->cas_flags & CAS_FLAG_SATURN)
cas_phy_powerdown(cp);
cas_unlock_all_restore(cp, flags);
}
staticint cas_change_mtu(struct net_device *dev, int new_mtu)
{ struct cas *cp = netdev_priv(dev);
WRITE_ONCE(dev->mtu, new_mtu); if (!netif_running(dev) || !netif_device_present(dev)) return0;
/* let the reset task handle it */ #if1
atomic_inc(&cp->reset_task_pending); if ((cp->phy_type & CAS_PHY_SERDES)) {
atomic_inc(&cp->reset_task_pending_all);
} else {
atomic_inc(&cp->reset_task_pending_mtu);
}
schedule_work(&cp->reset_task); #else
atomic_set(&cp->reset_task_pending, (cp->phy_type & CAS_PHY_SERDES) ?
CAS_RESET_ALL : CAS_RESET_MTU);
pr_err("reset called in cas_change_mtu\n");
schedule_work(&cp->reset_task); #endif
flush_work(&cp->reset_task); return0;
}
staticvoid cas_clean_txd(struct cas *cp, int ring)
{ struct cas_tx_desc *txd = cp->init_txds[ring]; struct sk_buff *skb, **skbs = cp->tx_skbs[ring];
u64 daddr, dlen; int i, size;
size = TX_DESC_RINGN_SIZE(ring); for (i = 0; i < size; i++) { int frag;
if (skbs[i] == NULL) continue;
skb = skbs[i];
skbs[i] = NULL;
for (frag = 0; frag <= skb_shinfo(skb)->nr_frags; frag++) { int ent = i & (size - 1);
/* first buffer is never a tiny buffer and so *needstobeunmapped.
*/
daddr = le64_to_cpu(txd[ent].buffer);
dlen = CAS_VAL(TX_DESC_BUFLEN,
le64_to_cpu(txd[ent].control));
dma_unmap_page(&cp->pdev->dev, daddr, dlen,
DMA_TO_DEVICE);
if (frag != skb_shinfo(skb)->nr_frags) {
i++;
/* next buffer might by a tiny buffer. *skippastit.
*/
ent = i & (size - 1); if (cp->tx_tiny_use[ring][ent].used)
i++;
}
}
dev_kfree_skb_any(skb);
}
/* zero out tiny buf usage */
memset(cp->tx_tiny_use[ring], 0, size*sizeof(*cp->tx_tiny_use[ring]));
}
/* freed on close */ staticinlinevoid cas_free_rx_desc(struct cas *cp, int ring)
{
cas_page_t **page = cp->rx_pages[ring]; int i, size;
size = RX_DESC_RINGN_SIZE(ring); for (i = 0; i < size; i++) { if (page[i]) {
cas_page_free(cp, page[i]);
page[i] = NULL;
}
}
}
staticvoid cas_free_rxds(struct cas *cp)
{ int i;
for (i = 0; i < N_RX_DESC_RINGS; i++)
cas_free_rx_desc(cp, i);
}
/* Must be invoked under cp->lock. */ staticvoid cas_clean_rings(struct cas *cp)
{ int i;
/* need to clean all tx rings */
memset(cp->tx_old, 0, sizeof(*cp->tx_old)*N_TX_RINGS);
memset(cp->tx_new, 0, sizeof(*cp->tx_new)*N_TX_RINGS); for (i = 0; i < N_TX_RINGS; i++)
cas_clean_txd(cp, i);
/* zero out init block */
memset(cp->init_block, 0, sizeof(struct cas_init_block));
cas_clean_rxds(cp);
cas_clean_rxcs(cp);
}
/* allocated on open */ staticinlineint cas_alloc_rx_desc(struct cas *cp, int ring)
{
cas_page_t **page = cp->rx_pages[ring]; int size, i = 0;
size = RX_DESC_RINGN_SIZE(ring); for (i = 0; i < size; i++) { if ((page[i] = cas_page_alloc(cp, GFP_KERNEL)) == NULL) return -1;
} return0;
}
staticint cas_alloc_rxds(struct cas *cp)
{ int i;
for (i = 0; i < N_RX_DESC_RINGS; i++) { if (cas_alloc_rx_desc(cp, i) < 0) {
cas_free_rxds(cp); return -1;
}
} return0;
}
staticvoid cas_reset_task(struct work_struct *work)
{ struct cas *cp = container_of(work, struct cas, reset_task); #if0 int pending = atomic_read(&cp->reset_task_pending); #else int pending_all = atomic_read(&cp->reset_task_pending_all); int pending_spare = atomic_read(&cp->reset_task_pending_spare); int pending_mtu = atomic_read(&cp->reset_task_pending_mtu);
if (pending_all == 0 && pending_spare == 0 && pending_mtu == 0) { /* We can have more tasks scheduled than actually *needed.
*/
atomic_dec(&cp->reset_task_pending); return;
} #endif /* The link went down, we reset the ring, but keep *DMAstopped.Usethisfunctionforreset *onerroraswell.
*/ if (cp->hw_running) { unsignedlong flags;
/* Make sure we don't get interrupts or tx packets */
netif_device_detach(cp->dev);
cas_lock_all_save(cp, flags);
if (cp->opened) { /* We call cas_spare_recover when we call cas_open. *butwedonotinitializethelistscas_spare_recover *usesuntilcas_openiscalled.
*/
cas_spare_recover(cp, GFP_ATOMIC);
} #if1 /* test => only pending_spare set */ if (!pending_all && !pending_mtu) goto done; #else if (pending == CAS_RESET_SPARE) goto done; #endif /* when pending == CAS_RESET_ALL, the following *calltocas_init_hwwillrestartautonegotiation. *Settingthesecondargumentofcas_resetto *!(pending==CAS_RESET_ALL)willsetthisargument *to1(avoidingreinitializingthePHYforthenormal *PCScase)whenautonegotiationisnotrestarted.
*/ #if1
cas_reset(cp, !(pending_all > 0)); if (cp->opened)
cas_clean_rings(cp);
cas_init_hw(cp, (pending_all > 0)); #else
cas_reset(cp, !(pending == CAS_RESET_ALL)); if (cp->opened)
cas_clean_rings(cp);
cas_init_hw(cp, pending == CAS_RESET_ALL); #endif
/* If the link task is still pending, we just *reschedulethelinktimer
*/ #if1 if (atomic_read(&cp->reset_task_pending_all) ||
atomic_read(&cp->reset_task_pending_spare) ||
atomic_read(&cp->reset_task_pending_mtu)) goto done; #else if (atomic_read(&cp->reset_task_pending)) goto done; #endif
/* check for rx cleaning */ if ((mask = (cp->cas_flags & CAS_FLAG_RXD_POST_MASK))) { int i, rmask;
for (i = 0; i < MAX_RX_DESC_RINGS; i++) {
rmask = CAS_FLAG_RXD_POST(i); if ((mask & rmask) == 0) continue;
/* post_rxds will do a mod_timer */ if (cas_post_rxds_ringN(cp, i, cp->rx_last[i]) < 0) {
pending = 1; continue;
}
cp->cas_flags &= ~rmask;
}
}
if (CAS_PHY_MII(cp->phy_type)) {
u16 bmsr;
cas_mif_poll(cp, 0);
bmsr = cas_phy_read(cp, MII_BMSR); /* WTZ: Solaris driver reads this twice, but that *maybeduetothePCScaseandtheuseofa *commonimplementation.Readittwiceheretobe *safe.
*/
bmsr = cas_phy_read(cp, MII_BMSR);
cas_mif_poll(cp, 1);
readl(cp->regs + REG_MIF_STATUS); /* avoid dups */
reset = cas_mii_link_check(cp, bmsr);
} else {
reset = cas_pcs_link_check(cp);
}
if (reset) goto done;
/* check for tx state machine confusion */ if ((readl(cp->regs + REG_MAC_TX_STATUS) & MAC_TX_FRAME_XMIT) == 0) {
u32 val = readl(cp->regs + REG_MAC_STATE_MACHINE);
u32 wptr, rptr; int tlm = CAS_VAL(MAC_SM_TLM, val);
done: if (reset) { #if1
atomic_inc(&cp->reset_task_pending);
atomic_inc(&cp->reset_task_pending_all);
schedule_work(&cp->reset_task); #else
atomic_set(&cp->reset_task_pending, CAS_RESET_ALL);
pr_err("reset called in cas_link_timer\n");
schedule_work(&cp->reset_task); #endif
}
if (!pending)
mod_timer(&cp->link_timer, jiffies + CAS_LINK_TIMEOUT);
cas_unlock_tx(cp);
spin_unlock_irqrestore(&cp->lock, flags);
}
/* tiny buffers are used to avoid target abort issues with *oldercassini's
*/ staticvoid cas_tx_tiny_free(struct cas *cp)
{ struct pci_dev *pdev = cp->pdev; int i;
for (i = 0; i < N_TX_RINGS; i++) { if (!cp->tx_tiny_bufs[i]) continue;
staticint cas_tx_tiny_alloc(struct cas *cp)
{ struct pci_dev *pdev = cp->pdev; int i;
for (i = 0; i < N_TX_RINGS; i++) {
cp->tx_tiny_bufs[i] =
dma_alloc_coherent(&pdev->dev, TX_TINY_BUF_BLOCK,
&cp->tx_tiny_dvma[i], GFP_KERNEL); if (!cp->tx_tiny_bufs[i]) {
cas_tx_tiny_free(cp); return -1;
}
} return0;
}
staticint cas_open(struct net_device *dev)
{ struct cas *cp = netdev_priv(dev); int hw_was_up, err; unsignedlong flags;
mutex_lock(&cp->pm_mutex);
hw_was_up = cp->hw_running;
/* The power-management mutex protects the hw_running *etc.statesoitissafetodothisbitwithoutcp->lock
*/ if (!cp->hw_running) { /* Reset the chip */
cas_lock_all_save(cp, flags); /* We set the second arg to cas_reset to zero *becausecas_init_hwbelowwillhaveitssecond *argumentsettonon-zero,whichwillforce *autonegotiationtostart.
*/
cas_reset(cp, 0);
cp->hw_running = 1;
cas_unlock_all_restore(cp, flags);
}
err = -ENOMEM; if (cas_tx_tiny_alloc(cp) < 0) goto err_unlock;
/* We can now request the interrupt as we know it's masked *onthecontroller.cassini+hasupto4interrupts *thatcanbeused,butyouneedtodoexplicitpciinterrupt *mappingtoexposethem
*/ if (request_irq(cp->pdev->irq, cas_interrupt,
IRQF_SHARED, dev->name, (void *) dev)) {
netdev_err(cp->dev, "failed to request irq !\n");
err = -EAGAIN; goto err_spare;
}
if (cp->hw_running) { /* pcs uses the same bits as mii */
bmcr = readl(cp->regs + REG_PCS_MII_CTRL);
cas_read_pcs_link_mode(cp, &full_duplex,
&speed, &pause);
}
}
spin_unlock_irqrestore(&cp->lock, flags);
if (bmcr & BMCR_ANENABLE) {
advertising |= ADVERTISED_Autoneg;
cmd->base.autoneg = AUTONEG_ENABLE;
cmd->base.speed = ((speed == 10) ?
SPEED_10 :
((speed == 1000) ?
SPEED_1000 : SPEED_100));
cmd->base.duplex = full_duplex ? DUPLEX_FULL : DUPLEX_HALF;
} else {
cmd->base.autoneg = AUTONEG_DISABLE;
cmd->base.speed = ((bmcr & CAS_BMCR_SPEED1000) ?
SPEED_1000 :
((bmcr & BMCR_SPEED100) ?
SPEED_100 : SPEED_10));
cmd->base.duplex = (bmcr & BMCR_FULLDPLX) ?
DUPLEX_FULL : DUPLEX_HALF;
} if (linkstate != link_up) { /* Force these to "unknown" if the link is not up and *autonogotiationinenabled.Wecansetthelink *speedto0,butnotcmd->duplex, *becauseitslegalvaluesare0and1.Ethtoolwill *printthevaluereportedinparenthesesafterthe *word"Unknown"forunrecognizedvalues. * *Ifinforcedmode,wereportthespeedandduplex *settingsthatweconfigured.
*/ if (cp->link_cntl & BMCR_ANENABLE) {
cmd->base.speed = 0;
cmd->base.duplex = 0xff;
} else {
cmd->base.speed = SPEED_10; if (cp->link_cntl & BMCR_SPEED100) {
cmd->base.speed = SPEED_100;
} elseif (cp->link_cntl & CAS_BMCR_SPEED1000) {
cmd->base.speed = SPEED_1000;
}
cmd->base.duplex = (cp->link_cntl & BMCR_FULLDPLX) ?
DUPLEX_FULL : DUPLEX_HALF;
}
}
staticint cas_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
{ struct cas *cp = netdev_priv(dev); struct mii_ioctl_data *data = if_mii(ifr); unsignedlong flags; int rc = -EOPNOTSUPP;
/* Hold the PM mutex while doing ioctl's or we may collide *withopen/closeandpowermanagementandoops.
*/
mutex_lock(&cp->pm_mutex); switch (cmd) { case SIOCGMIIPHY: /* Get address of MII PHY in use. */
data->phy_id = cp->phy_addr;
fallthrough;
/* When this chip sits underneath an Intel 31154 bridge, it is the *onlysubordinatedeviceandwecantweakthebridgesettingsto *reflectthatfact.
*/ staticvoid cas_program_bridge(struct pci_dev *cas_pdev)
{ struct pci_dev *pdev = cas_pdev->bus->self;
u32 val;
if (!pdev) return;
if (pdev->vendor != 0x8086 || pdev->device != 0x537c) return;
/* Clear bit 10 (Bus Parking Control) in the Secondary *ArbiterControl/StatusRegisterwhichlivesatoffset *0x41.Usinga32-bitwordread/modify/writeat0x40 *ismuchsimplersothat'showwedothis.
*/
pci_read_config_dword(pdev, 0x40, &val);
val &= ~0x00040000;
pci_write_config_dword(pdev, 0x40, val);
/* Max out the Multi-Transaction Timer settings since *Cassiniistheonlydevicepresent. * *Theregisteris16-bitandlivesat0x50.Whenthe *settingsareenabled,itextendstheGRANT#signal *forarequestorafteratransactioniscomplete.This *allowsthenextrequesttorunwithoutfirstneeding *tonegotiatetheGRANT#signalback. * *Bits12:10definethegrantduration: * *1--16clocks *2--32clocks *3--64clocks *4--128clocks *5--256clocks * *Allothervaluesareillegal. * *Bits09:00definewhichREQ/GNTsignalpairsgetthe *GRANT#signaltreatment.Wesetthemall.
*/
pci_write_config_word(pdev, 0x50, (5 << 10) | 0x3ff);
/* we must always turn on parity response or else parity *doesn'tgetgeneratedproperly.disableSERR/PERRaswell. *inaddition,wewanttoturnMWIon.
*/
pci_read_config_word(pdev, PCI_COMMAND, &pci_cmd);
pci_cmd &= ~PCI_COMMAND_SERR;
pci_cmd |= PCI_COMMAND_PARITY;
pci_write_config_word(pdev, PCI_COMMAND, pci_cmd); if (pci_try_set_mwi(pdev))
pr_warn("Could not enable MWI for %s\n", pci_name(pdev));
spin_lock_init(&cp->lock);
spin_lock_init(&cp->rx_inuse_lock);
spin_lock_init(&cp->rx_spare_lock); for (i = 0; i < N_TX_RINGS; i++) {
spin_lock_init(&cp->stat_lock[i]);
spin_lock_init(&cp->tx_lock[i]);
}
spin_lock_init(&cp->stat_lock[N_TX_RINGS]);
mutex_init(&cp->pm_mutex);
timer_setup(&cp->link_timer, cas_link_timer, 0);
#if1 /* Just in case the implementation of atomic operations *changesothatanexplicitinitializationisnecessary.
*/
atomic_set(&cp->reset_task_pending, 0);
atomic_set(&cp->reset_task_pending_all, 0);
atomic_set(&cp->reset_task_pending_spare, 0);
atomic_set(&cp->reset_task_pending_mtu, 0); #endif
INIT_WORK(&cp->reset_task, cas_reset_task);
/* If the driver is opened, we stop the DMA */ if (cp->opened) {
netif_device_detach(dev);
cas_lock_all_save(cp, flags);
/* We can set the second arg of cas_reset to 0 *becauseonresume,we'llcallcas_init_hwwith *itssecondargsetsothatautonegotiationis *restarted.
*/
cas_reset(cp, 0);
cas_clean_rings(cp);
cas_unlock_all_restore(cp, flags);
}
if (cp->hw_running)
cas_shutdown(cp);
mutex_unlock(&cp->pm_mutex);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.