cxgb2.c

来自「linux 内核源代码」· C语言 代码 · 共 1,428 行 · 第 1/3 页

C
1,428
字号
/***************************************************************************** *                                                                           * * 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/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/dma-mapping.h>#include <asm/uaccess.h>#include "cpl5_cmd.h"#include "regs.h"#include "gmac.h"#include "cphy.h"#include "sge.h"#include "tp.h"#include "espi.h"#include "elmer0.h"#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);}#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 MAX_TX_BUFFERS		1460U#define MIN_FL_ENTRIES		32#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_param(dflt_msg_enable, int, 0);MODULE_PARM_DESC(dflt_msg_enable, "Chelsio T1 default message enable bitmap");#define HCLOCK 0x0#define LCLOCK 0x1/* T1 cards powersave mode */static int t1_clock(struct adapter *adapter, int mode);static int t1powersave = 1;	/* HW default is powersave mode. */module_param(t1powersave, int, 0);MODULE_PARM_DESC(t1powersave, "Enable/Disable T1 powersaving mode");static int disable_msi = 0;module_param(disable_msi, int, 0);MODULE_PARM_DESC(disable_msi, "Disable Message Signaled Interrupt (MSI)");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_negotiated(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);		/* multi-ports: inform toe */		if ((speed > 0) && (adapter->params.nports > 1)) {			unsigned int sched_speed = 10;			switch (speed) {			case SPEED_1000:				sched_speed = 1000;				break;			case SPEED_100:				sched_speed = 100;				break;			case SPEED_10:				sched_speed = 10;				break;			}			t1_sched_update_parms(adapter->sge, port_id, 0, sched_speed);		}	}}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->tp, 1);	/* for TSO only */	if (adapter->flags & UDP_CSUM_CAPABLE)		t1_tp_set_udp_checksum_offload(adapter->tp, 1);	t1_tp_set_tcp_checksum_offload(adapter->tp, 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);	adapter->params.has_msi = !disable_msi && !pci_enable_msi(adapter->pdev);	err = request_irq(adapter->pdev->irq, t1_interrupt,			  adapter->params.has_msi ? 0 : IRQF_SHARED,			  adapter->name, adapter);	if (err) {		if (adapter->params.has_msi)			pci_disable_msi(adapter->pdev);		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);	if (adapter->params.has_msi)		pci_disable_msi(adapter->pdev);}static int cxgb_open(struct net_device *dev){	int err;	struct adapter *adapter = dev->priv;	int other_ports = adapter->open_device_map & PORT_MASK;	napi_enable(&adapter->napi);	if (!adapter->open_device_map && (err = cxgb_up(adapter)) < 0) {		napi_disable(&adapter->napi);		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);	napi_disable(&adapter->napi);	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",	"TxJumboFramesOk",	"TxJumboOctetsOk",		"RxOctetsOK",	"RxOctetsBad",	"RxUnicastFramesOK",	"RxMulticastFramesOK",	"RxBroadcastFramesOK",	"RxPauseFrames",	"RxFCSErrors",	"RxAlignErrors",	"RxSymbolErrors",	"RxDataErrors",	"RxSequenceErrors",	"RxRuntErrors",	"RxJabberErrors",	"RxInternalMACRcvError",	"RxInRangeLengthErrors",	"RxOutOfRangeLengthField",	"RxFrameTooLongErrors",	"RxJumboFramesOk",	"RxJumboOctetsOk",	/* Port stats */	"RxCsumGood",	"TxCsumOffload",	"TxTso",	"RxVlan",	"TxVlan",	"TxNeedHeadroom", 		/* Interrupt stats */	"rx drops",	"pure_rsps",	"unhandled irqs",	"respQ_empty",	"respQ_overflow",	"freelistQ_empty",	"pkt_too_big",	"pkt_mismatch",	"cmdQ_full0",	"cmdQ_full1",	"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;	strcpy(info->driver, DRV_NAME);	strcpy(info->version, DRV_VERSION);	strcpy(info->fw_version, "N/A");	strcpy(info->bus_info, pci_name(adapter->pdev));}static int get_sset_count(struct net_device *dev, int sset){	switch (sset) {	case ETH_SS_STATS:		return ARRAY_SIZE(stats_strings);	default:		return -EOPNOTSUPP;	}}static void get_strings(struct net_device *dev, u32 stringset, u8 *data){	if (stringset == ETH_SS_STATS)		memcpy(data, stats_strings, sizeof(stats_strings));}static void get_stats(struct net_device *dev, struct ethtool_stats *stats,		      u64 *data){	struct adapter *adapter = dev->priv;	struct cmac *mac = adapter->port[dev->if_port].mac;	const struct cmac_statistics *s;	const struct sge_intr_counts *t;	struct sge_port_stats ss;	s = mac->ops->statistics_update(mac, MAC_STATS_UPDATE_FULL);	t = t1_sge_get_intr_counts(adapter->sge);	t1_sge_get_port_stats(adapter->sge, dev->if_port, &ss);	*data++ = s->TxOctetsOK;	*data++ = s->TxOctetsBad;	*data++ = s->TxUnicastFramesOK;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?