40 #include <linux/module.h>
42 #include <linux/pci.h>
43 #include <linux/netdevice.h>
45 #include <linux/if_vlan.h>
46 #include <linux/mii.h>
49 #include <asm/uaccess.h>
62 static inline void schedule_mac_stats_update(
struct adapter *ap,
int secs)
67 static inline void cancel_mac_stats_update(
struct adapter *ap)
72 #define MAX_CMDQ_ENTRIES 16384
73 #define MAX_CMDQ1_ENTRIES 1024
74 #define MAX_RX_BUFFERS 16384
75 #define MAX_RX_JUMBO_BUFFERS 16384
76 #define MAX_TX_BUFFERS_HIGH 16384U
77 #define MAX_TX_BUFFERS_LOW 1536U
78 #define MAX_TX_BUFFERS 1460U
79 #define MIN_FL_ENTRIES 32
81 #define DFLT_MSG_ENABLE (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK | \
82 NETIF_MSG_TIMER | NETIF_MSG_IFDOWN | NETIF_MSG_IFUP |\
83 NETIF_MSG_RX_ERR | NETIF_MSG_TX_ERR)
89 #define EEPROM_SIZE 32
98 MODULE_PARM_DESC(dflt_msg_enable,
"Chelsio T1 default message enable bitmap");
105 static int t1powersave = 1;
110 static int disable_msi = 0;
114 static const char pci_speed[][4] = {
115 "33",
"66",
"100",
"133"
128 mac->
ops->set_rx_mode(mac, &rm);
133 if (!netif_carrier_ok(p->
dev))
136 const char *
s =
"10Mbps";
155 if (link_stat != netif_carrier_ok(p->
dev)) {
163 if ((speed > 0) && (adapter->
params.nports > 1)) {
164 unsigned int sched_speed = 10;
181 static void link_start(
struct port_info *p)
185 mac->
ops->reset(mac);
186 if (mac->
ops->macaddress_set)
187 mac->
ops->macaddress_set(mac, p->
dev->dev_addr);
188 t1_set_rxmode(p->
dev);
193 static void enable_hw_csum(
struct adapter *adapter)
204 static int cxgb_up(
struct adapter *adapter)
213 enable_hw_csum(adapter);
219 adapter->
params.has_msi = !disable_msi && !pci_enable_msi(adapter->
pdev);
222 adapter->
name, adapter);
224 if (adapter->
params.has_msi)
239 static void cxgb_down(
struct adapter *adapter)
244 if (adapter->
params.has_msi)
251 struct adapter *adapter = dev->
ml_priv;
254 napi_enable(&adapter->
napi);
256 napi_disable(&adapter->
napi);
262 netif_start_queue(dev);
263 if (!other_ports && adapter->
params.stats_update_period)
264 schedule_mac_stats_update(adapter,
265 adapter->
params.stats_update_period);
273 struct adapter *adapter = dev->
ml_priv;
277 netif_stop_queue(dev);
278 napi_disable(&adapter->
napi);
283 if (adapter->
params.stats_update_period &&
289 cancel_mac_stats_update(adapter);
299 struct adapter *adapter = dev->
ml_priv;
305 pstats = p->
mac->ops->statistics_update(p->
mac,
347 struct adapter *adapter = dev->
ml_priv;
354 struct adapter *adapter = dev->
ml_priv;
363 "TxMulticastFramesOK",
364 "TxBroadcastFramesOK",
366 "TxFramesWithDeferredXmissions",
369 "TxFramesAbortedDueToXSCollisions",
372 "TxInternalMACXmitError",
373 "TxFramesWithExcessiveDeferral",
381 "RxMulticastFramesOK",
382 "RxBroadcastFramesOK",
391 "RxInternalMACRcvError",
392 "RxInRangeLengthErrors",
393 "RxOutOfRangeLengthField",
394 "RxFrameTooLongErrors",
418 "espi_DIP2ParityErr",
426 #define T2_REGMAP_SIZE (3 * 1024)
428 static int get_regs_len(
struct net_device *dev)
435 struct adapter *adapter = dev->
ml_priv;
443 static int get_sset_count(
struct net_device *dev,
int sset)
456 memcpy(data, stats_strings,
sizeof(stats_strings));
462 struct adapter *adapter = dev->
ml_priv;
472 *data++ = s->TxOctetsOK;
473 *data++ = s->TxOctetsBad;
474 *data++ = s->TxUnicastFramesOK;
475 *data++ = s->TxMulticastFramesOK;
476 *data++ = s->TxBroadcastFramesOK;
477 *data++ = s->TxPauseFrames;
478 *data++ = s->TxFramesWithDeferredXmissions;
479 *data++ = s->TxLateCollisions;
480 *data++ = s->TxTotalCollisions;
481 *data++ = s->TxFramesAbortedDueToXSCollisions;
482 *data++ = s->TxUnderrun;
483 *data++ = s->TxLengthErrors;
484 *data++ = s->TxInternalMACXmitError;
485 *data++ = s->TxFramesWithExcessiveDeferral;
486 *data++ = s->TxFCSErrors;
487 *data++ = s->TxJumboFramesOK;
488 *data++ = s->TxJumboOctetsOK;
490 *data++ = s->RxOctetsOK;
491 *data++ = s->RxOctetsBad;
492 *data++ = s->RxUnicastFramesOK;
493 *data++ = s->RxMulticastFramesOK;
494 *data++ = s->RxBroadcastFramesOK;
495 *data++ = s->RxPauseFrames;
496 *data++ = s->RxFCSErrors;
497 *data++ = s->RxAlignErrors;
498 *data++ = s->RxSymbolErrors;
499 *data++ = s->RxDataErrors;
500 *data++ = s->RxSequenceErrors;
501 *data++ = s->RxRuntErrors;
502 *data++ = s->RxJabberErrors;
503 *data++ = s->RxInternalMACRcvError;
504 *data++ = s->RxInRangeLengthErrors;
505 *data++ = s->RxOutOfRangeLengthField;
506 *data++ = s->RxFrameTooLongErrors;
507 *data++ = s->RxJumboFramesOK;
508 *data++ = s->RxJumboOctetsOK;
510 *data++ =
ss.rx_cso_good;
513 *data++ =
ss.vlan_xtract;
514 *data++ =
ss.vlan_insert;
515 *data++ =
ss.tx_need_hdrroom;
541 static inline void reg_block_dump(
struct adapter *ap,
void *
buf,
542 unsigned int start,
unsigned int end)
546 for ( ; start <=
end; start +=
sizeof(
u32))
553 struct adapter *ap = dev->
ml_priv;
575 struct adapter *adapter = dev->
ml_priv;
581 if (netif_carrier_ok(dev)) {
585 ethtool_cmd_speed_set(cmd, -1);
598 static int speed_duplex_to_caps(
int speed,
int duplex)
628 #define ADVERTISED_MASK (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | \
629 ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | \
630 ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full | \
631 ADVERTISED_10000baseT_Full)
635 struct adapter *adapter = dev->
ml_priv;
643 u32 speed = ethtool_cmd_speed(cmd);
644 int cap = speed_duplex_to_caps(speed, cmd->
duplex);
663 if (netif_running(dev))
668 static void get_pauseparam(
struct net_device *dev,
671 struct adapter *adapter = dev->
ml_priv;
679 static int set_pauseparam(
struct net_device *dev,
682 struct adapter *adapter = dev->
ml_priv;
698 if (netif_running(dev))
702 if (netif_running(dev))
703 p->
mac->ops->set_speed_duplex_fc(p->
mac, -1, -1,
711 struct adapter *adapter = dev->
ml_priv;
712 int jumbo_fl =
t1_is_T1B(adapter) ? 1 : 0;
725 struct adapter *adapter = dev->
ml_priv;
726 int jumbo_fl =
t1_is_T1B(adapter) ? 1 : 0;
749 struct adapter *adapter = dev->
ml_priv;
760 struct adapter *adapter = dev->
ml_priv;
768 static int get_eeprom_len(
struct net_device *dev)
770 struct adapter *adapter = dev->
ml_priv;
775 #define EEPROM_MAGIC(ap) \
776 (PCI_VENDOR_ID_CHELSIO | ((ap)->params.chip_version << 16))
783 struct adapter *adapter = dev->
ml_priv;
798 .get_ringparam = get_sge_param,
799 .set_ringparam = set_sge_param,
816 struct adapter *adapter = dev->
ml_priv;
822 static int t1_change_mtu(
struct net_device *dev,
int new_mtu)
825 struct adapter *adapter = dev->
ml_priv;
828 if (!mac->
ops->set_mtu)
832 if ((ret = mac->
ops->set_mtu(mac, new_mtu)))
838 static int t1_set_mac_addr(
struct net_device *dev,
void *p)
840 struct adapter *adapter = dev->
ml_priv;
844 if (!mac->
ops->macaddress_set)
870 struct adapter *adapter = dev->
ml_priv;
877 #ifdef CONFIG_NET_POLL_CONTROLLER
878 static void t1_netpoll(
struct net_device *dev)
881 struct adapter *adapter = dev->
ml_priv;
896 struct adapter *adapter =
902 if (netif_running(p->
dev))
903 p->
mac->ops->statistics_update(p->
mac,
910 schedule_mac_stats_update(adapter,
911 adapter->
params.stats_update_period);
918 static void ext_intr_task(
struct work_struct *work)
920 struct adapter *adapter =
926 spin_lock_irq(&adapter->async_lock);
931 spin_unlock_irq(&adapter->async_lock);
956 pr_alert(
"%s: encountered fatal error, operation suspended\n",
961 .ndo_open = cxgb_open,
962 .ndo_stop = cxgb_close,
964 .ndo_get_stats = t1_get_stats,
966 .ndo_set_rx_mode = t1_set_rxmode,
967 .ndo_do_ioctl = t1_ioctl,
968 .ndo_change_mtu = t1_change_mtu,
969 .ndo_set_mac_address = t1_set_mac_addr,
970 .ndo_fix_features = t1_fix_features,
971 .ndo_set_features = t1_set_features,
972 #ifdef CONFIG_NET_POLL_CONTROLLER
973 .ndo_poll_controller = t1_netpoll,
980 static int version_printed;
982 int i,
err, pci_using_dac = 0;
983 unsigned long mmio_start, mmio_len;
985 struct adapter *adapter =
NULL;
988 if (!version_printed) {
999 pr_err(
"%s: cannot find PCI device memory base address\n",
1002 goto out_disable_pdev;
1008 if (pci_set_consistent_dma_mask(pdev,
DMA_BIT_MASK(64))) {
1009 pr_err(
"%s: unable to obtain 64-bit DMA for "
1010 "consistent allocations\n", pci_name(pdev));
1012 goto out_disable_pdev;
1015 }
else if ((err = pci_set_dma_mask(pdev,
DMA_BIT_MASK(32))) != 0) {
1016 pr_err(
"%s: no usable DMA configuration\n", pci_name(pdev));
1017 goto out_disable_pdev;
1022 pr_err(
"%s: cannot obtain PCI resources\n", pci_name(pdev));
1023 goto out_disable_pdev;
1035 netdev = alloc_etherdev(adapter ? 0 :
sizeof(*adapter));
1044 adapter = netdev_priv(netdev);
1045 adapter->
pdev = pdev;
1046 adapter->
port[0].dev = netdev;
1049 if (!adapter->
regs) {
1050 pr_err(
"%s: cannot map device registers\n",
1061 adapter->
name = pci_name(pdev);
1075 pci_set_drvdata(pdev, netdev);
1078 pi = &adapter->
port[
i];
1084 netdev->
mem_end = mmio_start + mmio_len - 1;
1093 if (vlan_tso_capable(adapter)) {
1128 pr_warning(
"%s: cannot register net device %s, skipping\n",
1129 pci_name(pdev), adapter->
port[i].dev->name);
1136 adapter->
name = adapter->
port[
i].dev->name;
1142 pr_err(
"%s: could not register any net devices\n",
1144 goto out_release_adapter_res;
1149 adapter->
params.pci.is_pcix ?
"PCIX" :
"PCI",
1160 t1_clock(adapter, t1powersave);
1164 out_release_adapter_res:
1171 if (adapter->
port[i].dev)
1177 pci_set_drvdata(pdev,
NULL);
1181 static void bit_bang(
struct adapter *adapter,
int bitdata,
int nbits)
1192 for (i = (nbits - 1); i > -1; i--) {
1196 data = ((bitdata >>
i) & 0x1);
1219 static int t1_clock(
struct adapter *adapter,
int mode)
1237 S_LOAD_MEM = 1 << 5,
1238 S_LOAD_CORE = 1 << 6,
1251 if ((mode & 1) ==
HCLOCK) {
1271 val &= ~S_LOAD_CORE;
1277 bit_bang(adapter, T_CORE_VAL, T_CORE_BITS);
1278 bit_bang(adapter, N_CORE_VAL, N_CORE_BITS);
1279 bit_bang(adapter, M_CORE_VAL, M_CORE_BITS);
1289 val &= ~S_LOAD_CORE;
1308 bit_bang(adapter, T_MEM_VAL, T_MEM_BITS);
1309 bit_bang(adapter, N_MEM_VAL, N_MEM_BITS);
1310 bit_bang(adapter, M_MEM_VAL, M_MEM_BITS);
1329 static inline void t1_sw_reset(
struct pci_dev *pdev)
1337 struct net_device *dev = pci_get_drvdata(pdev);
1338 struct adapter *adapter = dev->
ml_priv;
1350 if (adapter->
port[i].dev)
1356 pci_set_drvdata(pdev,
NULL);
1367 static int __init t1_init_module(
void)
1369 return pci_register_driver(&driver);
1372 static void __exit t1_cleanup_module(
void)