📄 cxgb2.c
字号:
/***************************************************************************** * * * File: cxgb2.c * * $Revision: 1.25 $ * * $Date: 2005/06/22 00:43:25 $ * * Description: * * Chelsio 10Gb Ethernet Driver. * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License, version 2, as * * published by the Free Software Foundation. * * * * You should have received a copy of the GNU General Public License along * * with this program; if not, write to the Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED * * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * * * * http://www.chelsio.com * * * * Copyright (c) 2003 - 2005 Chelsio Communications, Inc. * * All rights reserved. * * * * Maintainers: maintainers@chelsio.com * * * * Authors: Dimitrios Michailidis <dm@chelsio.com> * * Tina Yang <tainay@chelsio.com> * * Felix Marti <felix@chelsio.com> * * Scott Bardone <sbardone@chelsio.com> * * Kurt Ottaway <kottaway@chelsio.com> * * Frank DiMambro <frank@chelsio.com> * * * * History: * * * ****************************************************************************/#include "common.h"#include <linux/config.h>#include <linux/module.h>#include <linux/init.h>#include <linux/pci.h>#include <linux/netdevice.h>#include <linux/etherdevice.h>#include <linux/if_vlan.h>#include <linux/mii.h>#include <linux/sockios.h>#include <linux/proc_fs.h>#include <linux/dma-mapping.h>#include <asm/uaccess.h>#include "cpl5_cmd.h"#include "regs.h"#include "gmac.h"#include "cphy.h"#include "sge.h"#include "espi.h"#ifdef work_struct#include <linux/tqueue.h>#define INIT_WORK INIT_TQUEUE#define schedule_work schedule_task#define flush_scheduled_work flush_scheduled_tasksstatic inline void schedule_mac_stats_update(struct adapter *ap, int secs){ mod_timer(&ap->stats_update_timer, jiffies + secs * HZ);}static inline void cancel_mac_stats_update(struct adapter *ap){ del_timer_sync(&ap->stats_update_timer); flush_scheduled_tasks();}/* * Stats update timer for 2.4. It schedules a task to do the actual update as * we need to access MAC statistics in process context. */static void mac_stats_timer(unsigned long data){ struct adapter *ap = (struct adapter *)data; schedule_task(&ap->stats_update_task);}#else#include <linux/workqueue.h>static inline void schedule_mac_stats_update(struct adapter *ap, int secs){ schedule_delayed_work(&ap->stats_update_task, secs * HZ);}static inline void cancel_mac_stats_update(struct adapter *ap){ cancel_delayed_work(&ap->stats_update_task);}#endif#define MAX_CMDQ_ENTRIES 16384#define MAX_CMDQ1_ENTRIES 1024#define MAX_RX_BUFFERS 16384#define MAX_RX_JUMBO_BUFFERS 16384#define MAX_TX_BUFFERS_HIGH 16384U#define MAX_TX_BUFFERS_LOW 1536U#define MIN_FL_ENTRIES 32#define PORT_MASK ((1 << MAX_NPORTS) - 1)#define DFLT_MSG_ENABLE (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK | \ NETIF_MSG_TIMER | NETIF_MSG_IFDOWN | NETIF_MSG_IFUP |\ NETIF_MSG_RX_ERR | NETIF_MSG_TX_ERR)/* * The EEPROM is actually bigger but only the first few bytes are used so we * only report those. */#define EEPROM_SIZE 32MODULE_DESCRIPTION(DRV_DESCRIPTION);MODULE_AUTHOR("Chelsio Communications");MODULE_LICENSE("GPL");static int dflt_msg_enable = DFLT_MSG_ENABLE;MODULE_PARM(dflt_msg_enable, "i");MODULE_PARM_DESC(dflt_msg_enable, "Chelsio T1 message enable bitmap");static const char pci_speed[][4] = { "33", "66", "100", "133"};/* * Setup MAC to receive the types of packets we want. */static void t1_set_rxmode(struct net_device *dev){ struct adapter *adapter = dev->priv; struct cmac *mac = adapter->port[dev->if_port].mac; struct t1_rx_mode rm; rm.dev = dev; rm.idx = 0; rm.list = dev->mc_list; mac->ops->set_rx_mode(mac, &rm);}static void link_report(struct port_info *p){ if (!netif_carrier_ok(p->dev)) printk(KERN_INFO "%s: link down\n", p->dev->name); else { const char *s = "10Mbps"; switch (p->link_config.speed) { case SPEED_10000: s = "10Gbps"; break; case SPEED_1000: s = "1000Mbps"; break; case SPEED_100: s = "100Mbps"; break; } printk(KERN_INFO "%s: link up, %s, %s-duplex\n", p->dev->name, s, p->link_config.duplex == DUPLEX_FULL ? "full" : "half"); }}void t1_link_changed(struct adapter *adapter, int port_id, int link_stat, int speed, int duplex, int pause){ struct port_info *p = &adapter->port[port_id]; if (link_stat != netif_carrier_ok(p->dev)) { if (link_stat) netif_carrier_on(p->dev); else netif_carrier_off(p->dev); link_report(p); }}static void link_start(struct port_info *p){ struct cmac *mac = p->mac; mac->ops->reset(mac); if (mac->ops->macaddress_set) mac->ops->macaddress_set(mac, p->dev->dev_addr); t1_set_rxmode(p->dev); t1_link_start(p->phy, mac, &p->link_config); mac->ops->enable(mac, MAC_DIRECTION_RX | MAC_DIRECTION_TX);}static void enable_hw_csum(struct adapter *adapter){ if (adapter->flags & TSO_CAPABLE) t1_tp_set_ip_checksum_offload(adapter, 1); /* for TSO only */ t1_tp_set_tcp_checksum_offload(adapter, 1);}/* * Things to do upon first use of a card. * This must run with the rtnl lock held. */static int cxgb_up(struct adapter *adapter){ int err = 0; if (!(adapter->flags & FULL_INIT_DONE)) { err = t1_init_hw_modules(adapter); if (err) goto out_err; enable_hw_csum(adapter); adapter->flags |= FULL_INIT_DONE; } t1_interrupts_clear(adapter); if ((err = request_irq(adapter->pdev->irq, t1_select_intr_handler(adapter), SA_SHIRQ, adapter->name, adapter))) { goto out_err; } t1_sge_start(adapter->sge); t1_interrupts_enable(adapter); out_err: return err;}/* * Release resources when all the ports have been stopped. */static void cxgb_down(struct adapter *adapter){ t1_sge_stop(adapter->sge); t1_interrupts_disable(adapter); free_irq(adapter->pdev->irq, adapter);}static int cxgb_open(struct net_device *dev){ int err; struct adapter *adapter = dev->priv; int other_ports = adapter->open_device_map & PORT_MASK; if (!adapter->open_device_map && (err = cxgb_up(adapter)) < 0) return err; __set_bit(dev->if_port, &adapter->open_device_map); link_start(&adapter->port[dev->if_port]); netif_start_queue(dev); if (!other_ports && adapter->params.stats_update_period) schedule_mac_stats_update(adapter, adapter->params.stats_update_period); return 0;}static int cxgb_close(struct net_device *dev){ struct adapter *adapter = dev->priv; struct port_info *p = &adapter->port[dev->if_port]; struct cmac *mac = p->mac; netif_stop_queue(dev); mac->ops->disable(mac, MAC_DIRECTION_TX | MAC_DIRECTION_RX); netif_carrier_off(dev); clear_bit(dev->if_port, &adapter->open_device_map); if (adapter->params.stats_update_period && !(adapter->open_device_map & PORT_MASK)) { /* Stop statistics accumulation. */ smp_mb__after_clear_bit(); spin_lock(&adapter->work_lock); /* sync with update task */ spin_unlock(&adapter->work_lock); cancel_mac_stats_update(adapter); } if (!adapter->open_device_map) cxgb_down(adapter); return 0;}static struct net_device_stats *t1_get_stats(struct net_device *dev){ struct adapter *adapter = dev->priv; struct port_info *p = &adapter->port[dev->if_port]; struct net_device_stats *ns = &p->netstats; const struct cmac_statistics *pstats; /* Do a full update of the MAC stats */ pstats = p->mac->ops->statistics_update(p->mac, MAC_STATS_UPDATE_FULL); ns->tx_packets = pstats->TxUnicastFramesOK + pstats->TxMulticastFramesOK + pstats->TxBroadcastFramesOK; ns->rx_packets = pstats->RxUnicastFramesOK + pstats->RxMulticastFramesOK + pstats->RxBroadcastFramesOK; ns->tx_bytes = pstats->TxOctetsOK; ns->rx_bytes = pstats->RxOctetsOK; ns->tx_errors = pstats->TxLateCollisions + pstats->TxLengthErrors + pstats->TxUnderrun + pstats->TxFramesAbortedDueToXSCollisions; ns->rx_errors = pstats->RxDataErrors + pstats->RxJabberErrors + pstats->RxFCSErrors + pstats->RxAlignErrors + pstats->RxSequenceErrors + pstats->RxFrameTooLongErrors + pstats->RxSymbolErrors + pstats->RxRuntErrors; ns->multicast = pstats->RxMulticastFramesOK; ns->collisions = pstats->TxTotalCollisions; /* detailed rx_errors */ ns->rx_length_errors = pstats->RxFrameTooLongErrors + pstats->RxJabberErrors; ns->rx_over_errors = 0; ns->rx_crc_errors = pstats->RxFCSErrors; ns->rx_frame_errors = pstats->RxAlignErrors; ns->rx_fifo_errors = 0; ns->rx_missed_errors = 0; /* detailed tx_errors */ ns->tx_aborted_errors = pstats->TxFramesAbortedDueToXSCollisions; ns->tx_carrier_errors = 0; ns->tx_fifo_errors = pstats->TxUnderrun; ns->tx_heartbeat_errors = 0; ns->tx_window_errors = pstats->TxLateCollisions; return ns;}static u32 get_msglevel(struct net_device *dev){ struct adapter *adapter = dev->priv; return adapter->msg_enable;}static void set_msglevel(struct net_device *dev, u32 val){ struct adapter *adapter = dev->priv; adapter->msg_enable = val;}static char stats_strings[][ETH_GSTRING_LEN] = { "TxOctetsOK", "TxOctetsBad", "TxUnicastFramesOK", "TxMulticastFramesOK", "TxBroadcastFramesOK", "TxPauseFrames", "TxFramesWithDeferredXmissions", "TxLateCollisions", "TxTotalCollisions", "TxFramesAbortedDueToXSCollisions", "TxUnderrun", "TxLengthErrors", "TxInternalMACXmitError", "TxFramesWithExcessiveDeferral", "TxFCSErrors", "RxOctetsOK", "RxOctetsBad", "RxUnicastFramesOK", "RxMulticastFramesOK", "RxBroadcastFramesOK", "RxPauseFrames", "RxFCSErrors", "RxAlignErrors", "RxSymbolErrors", "RxDataErrors", "RxSequenceErrors", "RxRuntErrors", "RxJabberErrors", "RxInternalMACRcvError", "RxInRangeLengthErrors", "RxOutOfRangeLengthField", "RxFrameTooLongErrors", "TSO", "VLANextractions", "VLANinsertions", "RxCsumGood", "TxCsumOffload", "RxDrops" "respQ_empty", "respQ_overflow", "freelistQ_empty", "pkt_too_big", "pkt_mismatch", "cmdQ_full0", "cmdQ_full1", "tx_ipfrags", "tx_reg_pkts", "tx_lso_pkts", "tx_do_cksum", "espi_DIP2ParityErr", "espi_DIP4Err", "espi_RxDrops", "espi_TxDrops", "espi_RxOvfl", "espi_ParityErr"}; #define T2_REGMAP_SIZE (3 * 1024)static int get_regs_len(struct net_device *dev){ return T2_REGMAP_SIZE;}static void get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info){ struct adapter *adapter = dev->priv;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -