24 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
27 #include <linux/ethtool.h>
30 #include <linux/mii.h>
33 #include <asm/div64.h>
35 #define IPG_RX_RING_BYTES (sizeof(struct ipg_rx) * IPG_RFDLIST_LENGTH)
36 #define IPG_TX_RING_BYTES (sizeof(struct ipg_tx) * IPG_TFDLIST_LENGTH)
37 #define IPG_RESET_MASK \
38 (IPG_AC_GLOBAL_RESET | IPG_AC_RX_RESET | IPG_AC_TX_RESET | \
39 IPG_AC_DMA | IPG_AC_FIFO | IPG_AC_NETWORK | IPG_AC_HOST | \
42 #define ipg_w32(val32, reg) iowrite32((val32), ioaddr + (reg))
43 #define ipg_w16(val16, reg) iowrite16((val16), ioaddr + (reg))
44 #define ipg_w8(val8, reg) iowrite8((val8), ioaddr + (reg))
46 #define ipg_r32(reg) ioread32(ioaddr + (reg))
47 #define ipg_r16(reg) ioread16(ioaddr + (reg))
48 #define ipg_r8(reg) ioread8(ioaddr + (reg))
55 #define DRV_NAME "ipg"
64 #define IPG_MAX_RXFRAME_SIZE 0x0600
65 #define IPG_RXFRAG_SIZE 0x0600
66 #define IPG_RXSUPPORT_SIZE 0x0600
67 #define IPG_IS_JUMBO false
73 static const unsigned short DefaultPhyParam[] = {
81 (0x4000 | (07 * 4)), 31, 0x0001, 27, 0x01e0, 31, 0x0002, 27, 0xeb8e, 31,
83 30, 0x005e, 9, 0x0700,
85 (0x4100 | (07 * 4)), 31, 0x0001, 27, 0x01e0, 31, 0x0002, 27, 0xeb8e, 31,
87 30, 0x005e, 9, 0x0700,
91 static const char *
const ipg_brand_name[] = {
92 "IC PLUS IP1000 1000/100/10 based NIC",
93 "Sundance Technology ST2021 based NIC",
94 "Tamarack Microelectronics TC9020/9021 based NIC",
124 netdev_info(dev,
"rx_current = %02x\n", sp->
rx_current);
125 netdev_info(dev,
"rx_dirty = %02x\n", sp->
rx_dirty);
126 netdev_info(dev,
"RFDList start address = %016lx\n",
128 netdev_info(dev,
"RFDListPtr register = %08x%08x\n",
133 netdev_info(dev,
"%02x %04x RFDNextPtr = %016lx\n",
134 i, offset, (
unsigned long)sp->
rxd[i].next_desc);
136 netdev_info(dev,
"%02x %04x RFS = %016lx\n",
137 i, offset, (
unsigned long)sp->
rxd[i].rfs);
139 netdev_info(dev,
"%02x %04x frag_info = %016lx\n",
140 i, offset, (
unsigned long)sp->
rxd[i].frag_info);
144 static void ipg_dump_tfdlist(
struct net_device *dev)
153 netdev_info(dev,
"tx_current = %02x\n", sp->
tx_current);
154 netdev_info(dev,
"tx_dirty = %02x\n", sp->
tx_dirty);
155 netdev_info(dev,
"TFDList start address = %016lx\n",
157 netdev_info(dev,
"TFDListPtr register = %08x%08x\n",
162 netdev_info(dev,
"%02x %04x TFDNextPtr = %016lx\n",
163 i, offset, (
unsigned long)sp->
txd[i].next_desc);
166 netdev_info(dev,
"%02x %04x TFC = %016lx\n",
167 i, offset, (
unsigned long) sp->
txd[i].tfc);
169 netdev_info(dev,
"%02x %04x frag_info = %016lx\n",
170 i, offset, (
unsigned long) sp->
txd[i].frag_info);
181 static void ipg_drive_phy_ctl_low_high(
void __iomem *ioaddr,
u8 data)
187 static void send_three_state(
void __iomem *ioaddr,
u8 phyctrlpolarity)
191 ipg_drive_phy_ctl_low_high(ioaddr, phyctrlpolarity);
194 static void send_end(
void __iomem *ioaddr,
u8 phyctrlpolarity)
200 static u16 read_phy_bit(
void __iomem *ioaddr,
u8 phyctrlpolarity)
219 void __iomem *ioaddr = ipg_ioaddr(dev);
255 for (j = 0; j < 5; j++) {
256 for (i = 0; i <
p[
j].len; i++) {
274 data = (
p[
j].field >> (
p[
j].len - 1 -
i)) << 1;
278 ipg_drive_phy_ctl_low_high(ioaddr, data);
282 send_three_state(ioaddr, polarity);
284 read_phy_bit(ioaddr, polarity);
290 for (i = 0; i <
p[6].len; i++) {
292 (read_phy_bit(ioaddr, polarity) << (
p[6].len - 1 -
i));
295 send_three_state(ioaddr, polarity);
296 send_three_state(ioaddr, polarity);
297 send_three_state(ioaddr, polarity);
298 send_end(ioaddr, polarity);
308 static void mdio_write(
struct net_device *dev,
int phy_id,
int phy_reg,
int val)
310 void __iomem *ioaddr = ipg_ioaddr(dev);
336 { val & 0xffff, 16 },
346 for (j = 0; j < 7; j++) {
347 for (i = 0; i <
p[
j].len; i++) {
365 data = (
p[
j].field >> (
p[
j].len - 1 -
i)) << 1;
369 ipg_drive_phy_ctl_low_high(ioaddr, data);
379 static void ipg_set_led_mode(
struct net_device *dev)
400 static void ipg_set_phy_set(
struct net_device *dev)
408 physet |= ((sp->
led_mode & 0x70) >> 4);
418 void __iomem *ioaddr = ipg_ioaddr(dev);
419 unsigned int timeout_count = 0;
434 ipg_set_led_mode(dev);
437 ipg_set_phy_set(dev);
442 static int ipg_find_phyaddr(
struct net_device *dev)
446 for (i = 0; i < 32; i++) {
456 status = mdio_read(dev, phyaddr,
MII_BMSR);
458 if ((status != 0xFFFF) && (status != 0))
469 static int ipg_config_autoneg(
struct net_device *dev)
473 unsigned int txflowcontrol;
474 unsigned int rxflowcontrol;
475 unsigned int fullduplex;
515 speed =
"undefined!";
519 netdev_info(dev,
"Link speed = %s\n", speed);
521 netdev_info(dev,
"10Mbps operational mode enabled\n");
530 if (fullduplex == 1) {
538 if (txflowcontrol == 1) {
546 if (rxflowcontrol == 1) {
562 netdev_info(dev,
"setting %s duplex, %sTX, %sRX flow control\n",
563 duplex, tx_desc, rx_desc);
572 static void ipg_nic_set_multicast_list(
struct net_device *dev)
574 void __iomem *ioaddr = ipg_ioaddr(dev);
576 unsigned int hashindex;
610 hashtable[0] = 0x00000000;
611 hashtable[1] = 0x00000000;
620 hashindex = hashindex & 0x3F;
625 set_bit(hashindex, (
void *)hashtable);
639 static int ipg_io_config(
struct net_device *dev)
642 void __iomem *ioaddr = ipg_ioaddr(dev);
679 ipg_nic_set_multicast_list(dev);
760 static int init_rfdlist(
struct net_device *dev)
772 pci_unmap_single(sp->
pdev,
780 rxfd->
rfs = 0x0000000000000000;
782 if (ipg_get_rxbuff(dev, i) < 0) {
793 netdev_err(dev,
"No memory available for RFD list\n");
799 sizeof(
struct ipg_rx)*(i + 1));
813 static void init_tfdlist(
struct net_device *dev)
832 sizeof(
struct ipg_tx)*(i + 1));
852 static void ipg_nic_txfree(
struct net_device *dev)
855 unsigned int released, pending,
dirty;
862 for (released = 0; released < pending; released++) {
878 pci_unmap_single(sp->
pdev,
886 dirty = (dirty + 1) % IPG_TFDLIST_LENGTH;
891 if (netif_queue_stopped(dev) &&
893 netif_wake_queue(dev);
897 static void ipg_tx_timeout(
struct net_device *dev)
905 spin_lock_irq(&sp->
lock);
908 if (ipg_io_config(dev) < 0)
909 netdev_info(dev,
"Error during re-configuration\n");
913 spin_unlock_irq(&sp->
lock);
924 static void ipg_nic_txcleanup(
struct net_device *dev)
948 netif_wake_queue(dev);
954 sp->
stats.tx_errors++;
976 sp->
stats.tx_fifo_errors++;
981 if (ipg_io_config(dev) < 0) {
982 netdev_info(dev,
"Error during re-configuration\n");
1041 static int ipg_nic_rxrestore(
struct net_device *dev)
1049 for (dirty = sp->
rx_dirty; curr - dirty > 0; dirty++) {
1060 if (ipg_get_rxbuff(dev, entry) < 0) {
1067 sp->
rxd[
entry].rfs = 0x0000000000000000;
1093 static void ipg_nic_rx_free_skb(
struct net_device *dev)
1101 pci_unmap_single(sp->
pdev,
1109 static int ipg_nic_rx_check_frame_type(
struct net_device *dev)
1122 static int ipg_nic_rx_check_error(
struct net_device *dev)
1133 (
unsigned long) rxfd->
rfs);
1136 sp->
stats.rx_errors++;
1142 sp->
stats.rx_fifo_errors++;
1147 sp->
stats.rx_length_errors++;
1156 sp->
stats.rx_frame_errors++;
1168 pci_unmap_single(sp->
pdev,
1180 static void ipg_nic_rx_with_start_and_end(
struct net_device *dev,
1182 struct ipg_rx *rxfd,
unsigned entry)
1210 skb_checksum_none_assert(skb);
1215 static void ipg_nic_rx_with_start(
struct net_device *dev,
1217 struct ipg_rx *rxfd,
unsigned entry)
1247 static void ipg_nic_rx_with_end(
struct net_device *dev,
1249 struct ipg_rx *rxfd,
unsigned entry)
1261 int framelen, endframelen;
1270 skb->
data, endframelen);
1272 jumbo->
skb->protocol =
1275 skb_checksum_none_assert(jumbo->
skb);
1284 ipg_nic_rx_free_skb(dev);
1293 static void ipg_nic_rx_no_start_no_end(
struct net_device *dev,
1295 struct ipg_rx *rxfd,
unsigned entry)
1312 ipg_nic_rx_free_skb(dev);
1322 static int ipg_nic_rx_jumbo(
struct net_device *dev)
1338 switch (ipg_nic_rx_check_frame_type(dev)) {
1340 ipg_nic_rx_with_start_and_end(dev, sp, rxfd, entry);
1343 ipg_nic_rx_with_start(dev, sp, rxfd, entry);
1346 ipg_nic_rx_with_end(dev, sp, rxfd, entry);
1349 ipg_nic_rx_no_start_no_end(dev, sp, rxfd, entry);
1356 if (i == IPG_MAXRFDPROCESS_COUNT) {
1365 ipg_nic_rxrestore(dev);
1370 static int ipg_nic_rx(
struct net_device *dev)
1381 #define __RFS_MASK \
1382 cpu_to_le64(IPG_RFS_RFDDONE | IPG_RFS_FRAMESTART | IPG_RFS_FRAMEEND)
1387 unsigned int framelen;
1391 if (((rxfd->
rfs & __RFS_MASK) != __RFS_MASK) || !skb)
1402 (
"RFS FrameLen > allocated fragment size\n");
1413 (
unsigned long int) rxfd->
rfs);
1416 sp->
stats.rx_errors++;
1421 sp->
stats.rx_fifo_errors++;
1426 sp->
stats.rx_length_errors++;
1436 sp->
stats.rx_frame_errors++;
1451 pci_unmap_single(sp->
pdev,
1473 skb_checksum_none_assert(skb);
1491 if (i == IPG_MAXRFDPROCESS_COUNT)
1497 sp->EmptyRFDListCount++;
1518 pci_unmap_single(sp->
pdev,
1534 ipg_nic_rxrestore(dev);
1554 if (ipg_io_config(dev) < 0) {
1555 netdev_info(dev,
"Cannot recover from PCI error\n");
1560 static irqreturn_t ipg_interrupt_handler(
int irq,
void *dev_inst)
1565 unsigned int handled = 0;
1571 ipg_nic_rxrestore(dev);
1573 spin_lock(&sp->
lock);
1603 ipg_nic_rxrestore(dev);
1607 sp->RFDlistendCount++;
1614 (status & IPG_IS_RFD_LIST_END) ||
1620 if (status & (~(IPG_IS_RX_DMA_PRIORITY | IPG_IS_RFD_LIST_END |
1621 IPG_IS_RX_DMA_COMPLETE | IPG_IS_INT_REQUESTED) &
1625 sp->RFDListCheckedCount++;
1629 ipg_nic_rx_jumbo(dev);
1636 ipg_nic_txfree(dev);
1642 ipg_nic_txcleanup(dev);
1646 ipg_nic_get_stats(dev);
1657 if (ipg_config_autoneg(dev) < 0)
1658 netdev_info(dev,
"Auto-negotiation error\n");
1679 spin_unlock(&sp->
lock);
1694 pci_unmap_single(sp->
pdev,
1709 pci_unmap_single(sp->
pdev,
1720 static int ipg_nic_open(
struct net_device *dev)
1745 netdev_info(dev,
"Error when requesting interrupt\n");
1756 goto err_free_irq_0;
1763 rc = init_rfdlist(dev);
1765 netdev_info(dev,
"Error during configuration\n");
1771 rc = ipg_io_config(dev);
1773 netdev_info(dev,
"Error during configuration\n");
1774 goto err_release_tfdlist_3;
1778 if (ipg_config_autoneg(dev) < 0)
1779 netdev_info(dev,
"Auto-negotiation error\n");
1782 sp->
jumbo.found_start = 0;
1783 sp->
jumbo.current_size = 0;
1790 netif_start_queue(dev);
1794 err_release_tfdlist_3:
1806 static int ipg_nic_stop(
struct net_device *dev)
1814 netif_stop_queue(dev);
1844 unsigned long flags;
1853 netif_stop_queue(dev);
1926 ((
u64) (skb->
len & 0xffff) << 48));
1942 netif_stop_queue(dev);
1944 spin_unlock_irqrestore(&sp->
lock, flags);
1949 static void ipg_set_phy_default_param(
unsigned char rev,
1954 const unsigned short *phy_param;
1957 phy_param = &DefaultPhyParam[0];
1958 length = *phy_param & 0x00FF;
1959 revision = (
unsigned char)((*phy_param) >> 8);
1961 while (length != 0) {
1962 if (rev == revision) {
1963 while (length > 1) {
1964 address = *phy_param;
1965 value = *(phy_param + 1);
1967 mdio_write(dev, phy_address, address, value);
1972 phy_param += length / 2;
1973 length = *phy_param & 0x00FF;
1974 revision = (
unsigned char)((*phy_param) >> 8);
1982 void __iomem *ioaddr = ipg_ioaddr(dev);
1990 for (i = 0; i < 1000; i++) {
2003 static void ipg_init_mii(
struct net_device *dev)
2015 mii_if->
phy_id = phyaddr = ipg_find_phyaddr(dev);
2017 if (phyaddr != 0x1f) {
2018 u16 mii_phyctrl, mii_1000cr;
2028 ipg_set_phy_default_param(sp->
pdev->revision, dev, phyaddr);
2037 static int ipg_hw_init(
struct net_device *dev)
2058 for (i = 0; i < 3; i++)
2061 for (i = 0; i < 3; i++)
2087 static int ipg_nic_change_mtu(
struct net_device *dev,
int new_mtu)
2103 if (new_mtu < 68 || new_mtu > 10240)
2106 err = ipg_nic_stop(dev);
2120 if (new_mtu > 0x0600)
2125 return ipg_nic_open(dev);
2152 static int ipg_nway_reset(
struct net_device *dev)
2164 static const struct ethtool_ops ipg_ethtool_ops = {
2165 .get_settings = ipg_get_settings,
2166 .set_settings = ipg_set_settings,
2167 .nway_reset = ipg_nway_reset,
2172 struct net_device *dev = pci_get_drvdata(pdev);
2186 pci_set_drvdata(pdev,
NULL);
2190 .ndo_open = ipg_nic_open,
2191 .ndo_stop = ipg_nic_stop,
2192 .ndo_start_xmit = ipg_nic_hard_start_xmit,
2193 .ndo_get_stats = ipg_nic_get_stats,
2194 .ndo_set_rx_mode = ipg_nic_set_multicast_list,
2195 .ndo_do_ioctl = ipg_ioctl,
2196 .ndo_tx_timeout = ipg_tx_timeout,
2197 .ndo_change_mtu = ipg_nic_change_mtu,
2205 unsigned int i =
id->driver_data;
2215 pr_info(
"%s: %s\n", pci_name(pdev), ipg_brand_name[i]);
2223 pr_err(
"%s: DMA config failed\n", pci_name(pdev));
2237 sp = netdev_priv(dev);
2254 goto err_free_dev_1;
2258 pr_err(
"%s: cannot map MMIO\n", pci_name(pdev));
2260 goto err_release_regions_2;
2270 pci_set_drvdata(pdev, dev);
2272 rc = ipg_hw_init(dev);
2280 netdev_info(dev,
"Ethernet device registered\n");
2286 err_release_regions_2:
2297 .id_table = ipg_pci_tbl,
2302 static int __init ipg_init_module(
void)
2304 return pci_register_driver(&ipg_pci_driver);
2307 static void __exit ipg_exit_module(
void)