18c2ecf20Sopenharmony_ci/*****************************************************************************
28c2ecf20Sopenharmony_ci *                                                                           *
38c2ecf20Sopenharmony_ci * File: cphy.h                                                              *
48c2ecf20Sopenharmony_ci * $Revision: 1.7 $                                                          *
58c2ecf20Sopenharmony_ci * $Date: 2005/06/21 18:29:47 $                                              *
68c2ecf20Sopenharmony_ci * Description:                                                              *
78c2ecf20Sopenharmony_ci *  part of the Chelsio 10Gb Ethernet Driver.                                *
88c2ecf20Sopenharmony_ci *                                                                           *
98c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or modify      *
108c2ecf20Sopenharmony_ci * it under the terms of the GNU General Public License, version 2, as       *
118c2ecf20Sopenharmony_ci * published by the Free Software Foundation.                                *
128c2ecf20Sopenharmony_ci *                                                                           *
138c2ecf20Sopenharmony_ci * You should have received a copy of the GNU General Public License along   *
148c2ecf20Sopenharmony_ci * with this program; if not, see <http://www.gnu.org/licenses/>.            *
158c2ecf20Sopenharmony_ci *                                                                           *
168c2ecf20Sopenharmony_ci * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED    *
178c2ecf20Sopenharmony_ci * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF      *
188c2ecf20Sopenharmony_ci * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.                     *
198c2ecf20Sopenharmony_ci *                                                                           *
208c2ecf20Sopenharmony_ci * http://www.chelsio.com                                                    *
218c2ecf20Sopenharmony_ci *                                                                           *
228c2ecf20Sopenharmony_ci * Copyright (c) 2003 - 2005 Chelsio Communications, Inc.                    *
238c2ecf20Sopenharmony_ci * All rights reserved.                                                      *
248c2ecf20Sopenharmony_ci *                                                                           *
258c2ecf20Sopenharmony_ci * Maintainers: maintainers@chelsio.com                                      *
268c2ecf20Sopenharmony_ci *                                                                           *
278c2ecf20Sopenharmony_ci * Authors: Dimitrios Michailidis   <dm@chelsio.com>                         *
288c2ecf20Sopenharmony_ci *          Tina Yang               <tainay@chelsio.com>                     *
298c2ecf20Sopenharmony_ci *          Felix Marti             <felix@chelsio.com>                      *
308c2ecf20Sopenharmony_ci *          Scott Bardone           <sbardone@chelsio.com>                   *
318c2ecf20Sopenharmony_ci *          Kurt Ottaway            <kottaway@chelsio.com>                   *
328c2ecf20Sopenharmony_ci *          Frank DiMambro          <frank@chelsio.com>                      *
338c2ecf20Sopenharmony_ci *                                                                           *
348c2ecf20Sopenharmony_ci * History:                                                                  *
358c2ecf20Sopenharmony_ci *                                                                           *
368c2ecf20Sopenharmony_ci ****************************************************************************/
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci#ifndef _CXGB_CPHY_H_
398c2ecf20Sopenharmony_ci#define _CXGB_CPHY_H_
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci#include "common.h"
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_cistruct mdio_ops {
448c2ecf20Sopenharmony_ci	void (*init)(adapter_t *adapter, const struct board_info *bi);
458c2ecf20Sopenharmony_ci	int  (*read)(struct net_device *dev, int phy_addr, int mmd_addr,
468c2ecf20Sopenharmony_ci		     u16 reg_addr);
478c2ecf20Sopenharmony_ci	int  (*write)(struct net_device *dev, int phy_addr, int mmd_addr,
488c2ecf20Sopenharmony_ci		      u16 reg_addr, u16 val);
498c2ecf20Sopenharmony_ci	unsigned mode_support;
508c2ecf20Sopenharmony_ci};
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci/* PHY interrupt types */
538c2ecf20Sopenharmony_cienum {
548c2ecf20Sopenharmony_ci	cphy_cause_link_change = 0x1,
558c2ecf20Sopenharmony_ci	cphy_cause_error = 0x2,
568c2ecf20Sopenharmony_ci	cphy_cause_fifo_error = 0x3
578c2ecf20Sopenharmony_ci};
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_cienum {
608c2ecf20Sopenharmony_ci	PHY_LINK_UP = 0x1,
618c2ecf20Sopenharmony_ci	PHY_AUTONEG_RDY = 0x2,
628c2ecf20Sopenharmony_ci	PHY_AUTONEG_EN = 0x4
638c2ecf20Sopenharmony_ci};
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_cistruct cphy;
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci/* PHY operations */
688c2ecf20Sopenharmony_cistruct cphy_ops {
698c2ecf20Sopenharmony_ci	void (*destroy)(struct cphy *);
708c2ecf20Sopenharmony_ci	int (*reset)(struct cphy *, int wait);
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci	int (*interrupt_enable)(struct cphy *);
738c2ecf20Sopenharmony_ci	int (*interrupt_disable)(struct cphy *);
748c2ecf20Sopenharmony_ci	int (*interrupt_clear)(struct cphy *);
758c2ecf20Sopenharmony_ci	int (*interrupt_handler)(struct cphy *);
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci	int (*autoneg_enable)(struct cphy *);
788c2ecf20Sopenharmony_ci	int (*autoneg_disable)(struct cphy *);
798c2ecf20Sopenharmony_ci	int (*autoneg_restart)(struct cphy *);
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci	int (*advertise)(struct cphy *phy, unsigned int advertise_map);
828c2ecf20Sopenharmony_ci	int (*set_loopback)(struct cphy *, int on);
838c2ecf20Sopenharmony_ci	int (*set_speed_duplex)(struct cphy *phy, int speed, int duplex);
848c2ecf20Sopenharmony_ci	int (*get_link_status)(struct cphy *phy, int *link_ok, int *speed,
858c2ecf20Sopenharmony_ci			       int *duplex, int *fc);
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci	u32 mmds;
888c2ecf20Sopenharmony_ci};
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci/* A PHY instance */
918c2ecf20Sopenharmony_cistruct cphy {
928c2ecf20Sopenharmony_ci	int state;	/* Link status state machine */
938c2ecf20Sopenharmony_ci	adapter_t *adapter;                  /* associated adapter */
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci	struct delayed_work phy_update;
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci	u16 bmsr;
988c2ecf20Sopenharmony_ci	int count;
998c2ecf20Sopenharmony_ci	int act_count;
1008c2ecf20Sopenharmony_ci	int act_on;
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ci	u32 elmer_gpo;
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci	const struct cphy_ops *ops;            /* PHY operations */
1058c2ecf20Sopenharmony_ci	struct mdio_if_info mdio;
1068c2ecf20Sopenharmony_ci	struct cphy_instance *instance;
1078c2ecf20Sopenharmony_ci};
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci/* Convenience MDIO read/write wrappers */
1108c2ecf20Sopenharmony_cistatic inline int cphy_mdio_read(struct cphy *cphy, int mmd, int reg,
1118c2ecf20Sopenharmony_ci				 unsigned int *valp)
1128c2ecf20Sopenharmony_ci{
1138c2ecf20Sopenharmony_ci	int rc = cphy->mdio.mdio_read(cphy->mdio.dev, cphy->mdio.prtad, mmd,
1148c2ecf20Sopenharmony_ci				      reg);
1158c2ecf20Sopenharmony_ci	*valp = (rc >= 0) ? rc : -1;
1168c2ecf20Sopenharmony_ci	return (rc >= 0) ? 0 : rc;
1178c2ecf20Sopenharmony_ci}
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_cistatic inline int cphy_mdio_write(struct cphy *cphy, int mmd, int reg,
1208c2ecf20Sopenharmony_ci				  unsigned int val)
1218c2ecf20Sopenharmony_ci{
1228c2ecf20Sopenharmony_ci	return cphy->mdio.mdio_write(cphy->mdio.dev, cphy->mdio.prtad, mmd,
1238c2ecf20Sopenharmony_ci				     reg, val);
1248c2ecf20Sopenharmony_ci}
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_cistatic inline int simple_mdio_read(struct cphy *cphy, int reg,
1278c2ecf20Sopenharmony_ci				   unsigned int *valp)
1288c2ecf20Sopenharmony_ci{
1298c2ecf20Sopenharmony_ci	return cphy_mdio_read(cphy, MDIO_DEVAD_NONE, reg, valp);
1308c2ecf20Sopenharmony_ci}
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_cistatic inline int simple_mdio_write(struct cphy *cphy, int reg,
1338c2ecf20Sopenharmony_ci				    unsigned int val)
1348c2ecf20Sopenharmony_ci{
1358c2ecf20Sopenharmony_ci	return cphy_mdio_write(cphy, MDIO_DEVAD_NONE, reg, val);
1368c2ecf20Sopenharmony_ci}
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci/* Convenience initializer */
1398c2ecf20Sopenharmony_cistatic inline void cphy_init(struct cphy *phy, struct net_device *dev,
1408c2ecf20Sopenharmony_ci			     int phy_addr, const struct cphy_ops *phy_ops,
1418c2ecf20Sopenharmony_ci			     const struct mdio_ops *mdio_ops)
1428c2ecf20Sopenharmony_ci{
1438c2ecf20Sopenharmony_ci	struct adapter *adapter = netdev_priv(dev);
1448c2ecf20Sopenharmony_ci	phy->adapter = adapter;
1458c2ecf20Sopenharmony_ci	phy->ops     = phy_ops;
1468c2ecf20Sopenharmony_ci	if (mdio_ops) {
1478c2ecf20Sopenharmony_ci		phy->mdio.prtad = phy_addr;
1488c2ecf20Sopenharmony_ci		phy->mdio.mmds = phy_ops->mmds;
1498c2ecf20Sopenharmony_ci		phy->mdio.mode_support = mdio_ops->mode_support;
1508c2ecf20Sopenharmony_ci		phy->mdio.mdio_read = mdio_ops->read;
1518c2ecf20Sopenharmony_ci		phy->mdio.mdio_write = mdio_ops->write;
1528c2ecf20Sopenharmony_ci	}
1538c2ecf20Sopenharmony_ci	phy->mdio.dev = dev;
1548c2ecf20Sopenharmony_ci}
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_ci/* Operations of the PHY-instance factory */
1578c2ecf20Sopenharmony_cistruct gphy {
1588c2ecf20Sopenharmony_ci	/* Construct a PHY instance with the given PHY address */
1598c2ecf20Sopenharmony_ci	struct cphy *(*create)(struct net_device *dev, int phy_addr,
1608c2ecf20Sopenharmony_ci			       const struct mdio_ops *mdio_ops);
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_ci	/*
1638c2ecf20Sopenharmony_ci	 * Reset the PHY chip.  This resets the whole PHY chip, not individual
1648c2ecf20Sopenharmony_ci	 * ports.
1658c2ecf20Sopenharmony_ci	 */
1668c2ecf20Sopenharmony_ci	int (*reset)(adapter_t *adapter);
1678c2ecf20Sopenharmony_ci};
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_ciextern const struct gphy t1_my3126_ops;
1708c2ecf20Sopenharmony_ciextern const struct gphy t1_mv88e1xxx_ops;
1718c2ecf20Sopenharmony_ciextern const struct gphy t1_vsc8244_ops;
1728c2ecf20Sopenharmony_ciextern const struct gphy t1_mv88x201x_ops;
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_ci#endif /* _CXGB_CPHY_H_ */
175