Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 Cavium, Inc. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms of version 2 of the GNU General Public License |
| 6 | * as published by the Free Software Foundation. |
| 7 | */ |
| 8 | |
David Daney | 46b903a | 2015-08-10 17:58:37 -0700 | [diff] [blame] | 9 | #include <linux/acpi.h> |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 10 | #include <linux/module.h> |
| 11 | #include <linux/interrupt.h> |
| 12 | #include <linux/pci.h> |
| 13 | #include <linux/netdevice.h> |
| 14 | #include <linux/etherdevice.h> |
| 15 | #include <linux/phy.h> |
| 16 | #include <linux/of.h> |
| 17 | #include <linux/of_mdio.h> |
| 18 | #include <linux/of_net.h> |
| 19 | |
| 20 | #include "nic_reg.h" |
| 21 | #include "nic.h" |
| 22 | #include "thunder_bgx.h" |
| 23 | |
| 24 | #define DRV_NAME "thunder-BGX" |
| 25 | #define DRV_VERSION "1.0" |
| 26 | |
| 27 | struct lmac { |
| 28 | struct bgx *bgx; |
| 29 | int dmac; |
David Daney | 46b903a | 2015-08-10 17:58:37 -0700 | [diff] [blame] | 30 | u8 mac[ETH_ALEN]; |
Sunil Goutham | 0bcb7d5 | 2016-08-12 16:51:30 +0530 | [diff] [blame] | 31 | u8 lmac_type; |
| 32 | u8 lane_to_sds; |
| 33 | bool use_training; |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 34 | bool link_up; |
| 35 | int lmacid; /* ID within BGX */ |
| 36 | int lmacid_bd; /* ID on board */ |
| 37 | struct net_device netdev; |
| 38 | struct phy_device *phydev; |
| 39 | unsigned int last_duplex; |
| 40 | unsigned int last_link; |
| 41 | unsigned int last_speed; |
| 42 | bool is_sgmii; |
| 43 | struct delayed_work dwork; |
| 44 | struct workqueue_struct *check_link; |
Aleksey Makarov | 0c886a1 | 2015-06-02 11:00:22 -0700 | [diff] [blame] | 45 | }; |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 46 | |
| 47 | struct bgx { |
| 48 | u8 bgx_id; |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 49 | struct lmac lmac[MAX_LMAC_PER_BGX]; |
Vadim Lomovtsev | 7aa4865 | 2017-01-12 07:28:06 -0800 | [diff] [blame] | 50 | u8 lmac_count; |
Sunil Goutham | 6465859 | 2016-08-12 16:51:33 +0530 | [diff] [blame] | 51 | u8 max_lmac; |
Vadim Lomovtsev | 7aa4865 | 2017-01-12 07:28:06 -0800 | [diff] [blame] | 52 | u8 acpi_lmac_idx; |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 53 | void __iomem *reg_base; |
| 54 | struct pci_dev *pdev; |
Sunil Goutham | 09de391 | 2016-08-12 16:51:35 +0530 | [diff] [blame] | 55 | bool is_dlm; |
Sunil Goutham | 6465859 | 2016-08-12 16:51:33 +0530 | [diff] [blame] | 56 | bool is_rgx; |
Aleksey Makarov | 0c886a1 | 2015-06-02 11:00:22 -0700 | [diff] [blame] | 57 | }; |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 58 | |
Aleksey Makarov | fd7ec06 | 2015-06-02 11:00:23 -0700 | [diff] [blame] | 59 | static struct bgx *bgx_vnic[MAX_BGX_THUNDER]; |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 60 | static int lmac_count; /* Total no of LMACs in system */ |
| 61 | |
| 62 | static int bgx_xaui_check_link(struct lmac *lmac); |
| 63 | |
| 64 | /* Supported devices */ |
| 65 | static const struct pci_device_id bgx_id_table[] = { |
| 66 | { PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, PCI_DEVICE_ID_THUNDER_BGX) }, |
Sunil Goutham | 6465859 | 2016-08-12 16:51:33 +0530 | [diff] [blame] | 67 | { PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, PCI_DEVICE_ID_THUNDER_RGX) }, |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 68 | { 0, } /* end of table */ |
| 69 | }; |
| 70 | |
| 71 | MODULE_AUTHOR("Cavium Inc"); |
| 72 | MODULE_DESCRIPTION("Cavium Thunder BGX/MAC Driver"); |
| 73 | MODULE_LICENSE("GPL v2"); |
| 74 | MODULE_VERSION(DRV_VERSION); |
| 75 | MODULE_DEVICE_TABLE(pci, bgx_id_table); |
| 76 | |
| 77 | /* The Cavium ThunderX network controller can *only* be found in SoCs |
| 78 | * containing the ThunderX ARM64 CPU implementation. All accesses to the device |
| 79 | * registers on this platform are implicitly strongly ordered with respect |
| 80 | * to memory accesses. So writeq_relaxed() and readq_relaxed() are safe to use |
| 81 | * with no memory barriers in this driver. The readq()/writeq() functions add |
| 82 | * explicit ordering operation which in this case are redundant, and only |
| 83 | * add overhead. |
| 84 | */ |
| 85 | |
| 86 | /* Register read/write APIs */ |
| 87 | static u64 bgx_reg_read(struct bgx *bgx, u8 lmac, u64 offset) |
| 88 | { |
| 89 | void __iomem *addr = bgx->reg_base + ((u32)lmac << 20) + offset; |
| 90 | |
| 91 | return readq_relaxed(addr); |
| 92 | } |
| 93 | |
| 94 | static void bgx_reg_write(struct bgx *bgx, u8 lmac, u64 offset, u64 val) |
| 95 | { |
| 96 | void __iomem *addr = bgx->reg_base + ((u32)lmac << 20) + offset; |
| 97 | |
| 98 | writeq_relaxed(val, addr); |
| 99 | } |
| 100 | |
| 101 | static void bgx_reg_modify(struct bgx *bgx, u8 lmac, u64 offset, u64 val) |
| 102 | { |
| 103 | void __iomem *addr = bgx->reg_base + ((u32)lmac << 20) + offset; |
| 104 | |
| 105 | writeq_relaxed(val | readq_relaxed(addr), addr); |
| 106 | } |
| 107 | |
| 108 | static int bgx_poll_reg(struct bgx *bgx, u8 lmac, u64 reg, u64 mask, bool zero) |
| 109 | { |
| 110 | int timeout = 100; |
| 111 | u64 reg_val; |
| 112 | |
| 113 | while (timeout) { |
| 114 | reg_val = bgx_reg_read(bgx, lmac, reg); |
| 115 | if (zero && !(reg_val & mask)) |
| 116 | return 0; |
| 117 | if (!zero && (reg_val & mask)) |
| 118 | return 0; |
| 119 | usleep_range(1000, 2000); |
| 120 | timeout--; |
| 121 | } |
| 122 | return 1; |
| 123 | } |
| 124 | |
| 125 | /* Return number of BGX present in HW */ |
| 126 | unsigned bgx_get_map(int node) |
| 127 | { |
| 128 | int i; |
| 129 | unsigned map = 0; |
| 130 | |
Sunil Goutham | 09de391 | 2016-08-12 16:51:35 +0530 | [diff] [blame] | 131 | for (i = 0; i < MAX_BGX_PER_NODE; i++) { |
| 132 | if (bgx_vnic[(node * MAX_BGX_PER_NODE) + i]) |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 133 | map |= (1 << i); |
| 134 | } |
| 135 | |
| 136 | return map; |
| 137 | } |
| 138 | EXPORT_SYMBOL(bgx_get_map); |
| 139 | |
| 140 | /* Return number of LMAC configured for this BGX */ |
| 141 | int bgx_get_lmac_count(int node, int bgx_idx) |
| 142 | { |
| 143 | struct bgx *bgx; |
| 144 | |
Sunil Goutham | 09de391 | 2016-08-12 16:51:35 +0530 | [diff] [blame] | 145 | bgx = bgx_vnic[(node * MAX_BGX_PER_NODE) + bgx_idx]; |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 146 | if (bgx) |
| 147 | return bgx->lmac_count; |
| 148 | |
| 149 | return 0; |
| 150 | } |
| 151 | EXPORT_SYMBOL(bgx_get_lmac_count); |
| 152 | |
| 153 | /* Returns the current link status of LMAC */ |
| 154 | void bgx_get_lmac_link_state(int node, int bgx_idx, int lmacid, void *status) |
| 155 | { |
| 156 | struct bgx_link_status *link = (struct bgx_link_status *)status; |
| 157 | struct bgx *bgx; |
| 158 | struct lmac *lmac; |
| 159 | |
Sunil Goutham | 09de391 | 2016-08-12 16:51:35 +0530 | [diff] [blame] | 160 | bgx = bgx_vnic[(node * MAX_BGX_PER_NODE) + bgx_idx]; |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 161 | if (!bgx) |
| 162 | return; |
| 163 | |
| 164 | lmac = &bgx->lmac[lmacid]; |
Thanneeru Srinivasulu | 1cc7025 | 2016-11-24 14:48:01 +0530 | [diff] [blame] | 165 | link->mac_type = lmac->lmac_type; |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 166 | link->link_up = lmac->link_up; |
| 167 | link->duplex = lmac->last_duplex; |
| 168 | link->speed = lmac->last_speed; |
| 169 | } |
| 170 | EXPORT_SYMBOL(bgx_get_lmac_link_state); |
| 171 | |
Aleksey Makarov | e610cb3 | 2015-06-02 11:00:21 -0700 | [diff] [blame] | 172 | const u8 *bgx_get_lmac_mac(int node, int bgx_idx, int lmacid) |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 173 | { |
Sunil Goutham | 09de391 | 2016-08-12 16:51:35 +0530 | [diff] [blame] | 174 | struct bgx *bgx = bgx_vnic[(node * MAX_BGX_PER_NODE) + bgx_idx]; |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 175 | |
| 176 | if (bgx) |
| 177 | return bgx->lmac[lmacid].mac; |
| 178 | |
| 179 | return NULL; |
| 180 | } |
| 181 | EXPORT_SYMBOL(bgx_get_lmac_mac); |
| 182 | |
Aleksey Makarov | e610cb3 | 2015-06-02 11:00:21 -0700 | [diff] [blame] | 183 | void bgx_set_lmac_mac(int node, int bgx_idx, int lmacid, const u8 *mac) |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 184 | { |
Sunil Goutham | 09de391 | 2016-08-12 16:51:35 +0530 | [diff] [blame] | 185 | struct bgx *bgx = bgx_vnic[(node * MAX_BGX_PER_NODE) + bgx_idx]; |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 186 | |
| 187 | if (!bgx) |
| 188 | return; |
| 189 | |
| 190 | ether_addr_copy(bgx->lmac[lmacid].mac, mac); |
| 191 | } |
| 192 | EXPORT_SYMBOL(bgx_set_lmac_mac); |
| 193 | |
Sunil Goutham | bc69fdf | 2015-12-02 15:36:17 +0530 | [diff] [blame] | 194 | void bgx_lmac_rx_tx_enable(int node, int bgx_idx, int lmacid, bool enable) |
| 195 | { |
Sunil Goutham | 09de391 | 2016-08-12 16:51:35 +0530 | [diff] [blame] | 196 | struct bgx *bgx = bgx_vnic[(node * MAX_BGX_PER_NODE) + bgx_idx]; |
Sunil Goutham | 6465859 | 2016-08-12 16:51:33 +0530 | [diff] [blame] | 197 | struct lmac *lmac; |
Sunil Goutham | bc69fdf | 2015-12-02 15:36:17 +0530 | [diff] [blame] | 198 | u64 cfg; |
| 199 | |
| 200 | if (!bgx) |
| 201 | return; |
Sunil Goutham | 6465859 | 2016-08-12 16:51:33 +0530 | [diff] [blame] | 202 | lmac = &bgx->lmac[lmacid]; |
Sunil Goutham | bc69fdf | 2015-12-02 15:36:17 +0530 | [diff] [blame] | 203 | |
| 204 | cfg = bgx_reg_read(bgx, lmacid, BGX_CMRX_CFG); |
| 205 | if (enable) |
| 206 | cfg |= CMR_PKT_RX_EN | CMR_PKT_TX_EN; |
| 207 | else |
| 208 | cfg &= ~(CMR_PKT_RX_EN | CMR_PKT_TX_EN); |
| 209 | bgx_reg_write(bgx, lmacid, BGX_CMRX_CFG, cfg); |
Sunil Goutham | 6465859 | 2016-08-12 16:51:33 +0530 | [diff] [blame] | 210 | |
| 211 | if (bgx->is_rgx) |
| 212 | xcv_setup_link(enable ? lmac->link_up : 0, lmac->last_speed); |
Sunil Goutham | bc69fdf | 2015-12-02 15:36:17 +0530 | [diff] [blame] | 213 | } |
| 214 | EXPORT_SYMBOL(bgx_lmac_rx_tx_enable); |
| 215 | |
Sunil Goutham | 430da20 | 2016-11-24 14:48:03 +0530 | [diff] [blame] | 216 | void bgx_lmac_get_pfc(int node, int bgx_idx, int lmacid, void *pause) |
| 217 | { |
| 218 | struct pfc *pfc = (struct pfc *)pause; |
| 219 | struct bgx *bgx = bgx_vnic[(node * MAX_BGX_PER_CN88XX) + bgx_idx]; |
| 220 | struct lmac *lmac; |
| 221 | u64 cfg; |
| 222 | |
| 223 | if (!bgx) |
| 224 | return; |
| 225 | lmac = &bgx->lmac[lmacid]; |
| 226 | if (lmac->is_sgmii) |
| 227 | return; |
| 228 | |
| 229 | cfg = bgx_reg_read(bgx, lmacid, BGX_SMUX_CBFC_CTL); |
| 230 | pfc->fc_rx = cfg & RX_EN; |
| 231 | pfc->fc_tx = cfg & TX_EN; |
| 232 | pfc->autoneg = 0; |
| 233 | } |
| 234 | EXPORT_SYMBOL(bgx_lmac_get_pfc); |
| 235 | |
| 236 | void bgx_lmac_set_pfc(int node, int bgx_idx, int lmacid, void *pause) |
| 237 | { |
| 238 | struct pfc *pfc = (struct pfc *)pause; |
| 239 | struct bgx *bgx = bgx_vnic[(node * MAX_BGX_PER_CN88XX) + bgx_idx]; |
| 240 | struct lmac *lmac; |
| 241 | u64 cfg; |
| 242 | |
| 243 | if (!bgx) |
| 244 | return; |
| 245 | lmac = &bgx->lmac[lmacid]; |
| 246 | if (lmac->is_sgmii) |
| 247 | return; |
| 248 | |
| 249 | cfg = bgx_reg_read(bgx, lmacid, BGX_SMUX_CBFC_CTL); |
| 250 | cfg &= ~(RX_EN | TX_EN); |
| 251 | cfg |= (pfc->fc_rx ? RX_EN : 0x00); |
| 252 | cfg |= (pfc->fc_tx ? TX_EN : 0x00); |
| 253 | bgx_reg_write(bgx, lmacid, BGX_SMUX_CBFC_CTL, cfg); |
| 254 | } |
| 255 | EXPORT_SYMBOL(bgx_lmac_set_pfc); |
| 256 | |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 257 | static void bgx_sgmii_change_link_state(struct lmac *lmac) |
| 258 | { |
| 259 | struct bgx *bgx = lmac->bgx; |
| 260 | u64 cmr_cfg; |
| 261 | u64 port_cfg = 0; |
| 262 | u64 misc_ctl = 0; |
| 263 | |
| 264 | cmr_cfg = bgx_reg_read(bgx, lmac->lmacid, BGX_CMRX_CFG); |
| 265 | cmr_cfg &= ~CMR_EN; |
| 266 | bgx_reg_write(bgx, lmac->lmacid, BGX_CMRX_CFG, cmr_cfg); |
| 267 | |
| 268 | port_cfg = bgx_reg_read(bgx, lmac->lmacid, BGX_GMP_GMI_PRTX_CFG); |
| 269 | misc_ctl = bgx_reg_read(bgx, lmac->lmacid, BGX_GMP_PCS_MISCX_CTL); |
| 270 | |
| 271 | if (lmac->link_up) { |
| 272 | misc_ctl &= ~PCS_MISC_CTL_GMX_ENO; |
| 273 | port_cfg &= ~GMI_PORT_CFG_DUPLEX; |
| 274 | port_cfg |= (lmac->last_duplex << 2); |
| 275 | } else { |
| 276 | misc_ctl |= PCS_MISC_CTL_GMX_ENO; |
| 277 | } |
| 278 | |
| 279 | switch (lmac->last_speed) { |
| 280 | case 10: |
| 281 | port_cfg &= ~GMI_PORT_CFG_SPEED; /* speed 0 */ |
| 282 | port_cfg |= GMI_PORT_CFG_SPEED_MSB; /* speed_msb 1 */ |
| 283 | port_cfg &= ~GMI_PORT_CFG_SLOT_TIME; /* slottime 0 */ |
| 284 | misc_ctl &= ~PCS_MISC_CTL_SAMP_PT_MASK; |
| 285 | misc_ctl |= 50; /* samp_pt */ |
| 286 | bgx_reg_write(bgx, lmac->lmacid, BGX_GMP_GMI_TXX_SLOT, 64); |
| 287 | bgx_reg_write(bgx, lmac->lmacid, BGX_GMP_GMI_TXX_BURST, 0); |
| 288 | break; |
| 289 | case 100: |
| 290 | port_cfg &= ~GMI_PORT_CFG_SPEED; /* speed 0 */ |
| 291 | port_cfg &= ~GMI_PORT_CFG_SPEED_MSB; /* speed_msb 0 */ |
| 292 | port_cfg &= ~GMI_PORT_CFG_SLOT_TIME; /* slottime 0 */ |
| 293 | misc_ctl &= ~PCS_MISC_CTL_SAMP_PT_MASK; |
| 294 | misc_ctl |= 5; /* samp_pt */ |
| 295 | bgx_reg_write(bgx, lmac->lmacid, BGX_GMP_GMI_TXX_SLOT, 64); |
| 296 | bgx_reg_write(bgx, lmac->lmacid, BGX_GMP_GMI_TXX_BURST, 0); |
| 297 | break; |
| 298 | case 1000: |
| 299 | port_cfg |= GMI_PORT_CFG_SPEED; /* speed 1 */ |
| 300 | port_cfg &= ~GMI_PORT_CFG_SPEED_MSB; /* speed_msb 0 */ |
| 301 | port_cfg |= GMI_PORT_CFG_SLOT_TIME; /* slottime 1 */ |
| 302 | misc_ctl &= ~PCS_MISC_CTL_SAMP_PT_MASK; |
| 303 | misc_ctl |= 1; /* samp_pt */ |
| 304 | bgx_reg_write(bgx, lmac->lmacid, BGX_GMP_GMI_TXX_SLOT, 512); |
| 305 | if (lmac->last_duplex) |
| 306 | bgx_reg_write(bgx, lmac->lmacid, |
| 307 | BGX_GMP_GMI_TXX_BURST, 0); |
| 308 | else |
| 309 | bgx_reg_write(bgx, lmac->lmacid, |
| 310 | BGX_GMP_GMI_TXX_BURST, 8192); |
| 311 | break; |
| 312 | default: |
| 313 | break; |
| 314 | } |
| 315 | bgx_reg_write(bgx, lmac->lmacid, BGX_GMP_PCS_MISCX_CTL, misc_ctl); |
| 316 | bgx_reg_write(bgx, lmac->lmacid, BGX_GMP_GMI_PRTX_CFG, port_cfg); |
| 317 | |
| 318 | port_cfg = bgx_reg_read(bgx, lmac->lmacid, BGX_GMP_GMI_PRTX_CFG); |
| 319 | |
Sunil Goutham | 6465859 | 2016-08-12 16:51:33 +0530 | [diff] [blame] | 320 | /* Re-enable lmac */ |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 321 | cmr_cfg |= CMR_EN; |
| 322 | bgx_reg_write(bgx, lmac->lmacid, BGX_CMRX_CFG, cmr_cfg); |
Sunil Goutham | 6465859 | 2016-08-12 16:51:33 +0530 | [diff] [blame] | 323 | |
| 324 | if (bgx->is_rgx && (cmr_cfg & (CMR_PKT_RX_EN | CMR_PKT_TX_EN))) |
| 325 | xcv_setup_link(lmac->link_up, lmac->last_speed); |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 326 | } |
| 327 | |
Aleksey Makarov | fd7ec06 | 2015-06-02 11:00:23 -0700 | [diff] [blame] | 328 | static void bgx_lmac_handler(struct net_device *netdev) |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 329 | { |
| 330 | struct lmac *lmac = container_of(netdev, struct lmac, netdev); |
xypron.glpk@gmx.de | 099a728 | 2016-05-17 21:40:38 +0200 | [diff] [blame] | 331 | struct phy_device *phydev; |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 332 | int link_changed = 0; |
| 333 | |
| 334 | if (!lmac) |
| 335 | return; |
| 336 | |
xypron.glpk@gmx.de | 099a728 | 2016-05-17 21:40:38 +0200 | [diff] [blame] | 337 | phydev = lmac->phydev; |
| 338 | |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 339 | if (!phydev->link && lmac->last_link) |
| 340 | link_changed = -1; |
| 341 | |
| 342 | if (phydev->link && |
| 343 | (lmac->last_duplex != phydev->duplex || |
| 344 | lmac->last_link != phydev->link || |
| 345 | lmac->last_speed != phydev->speed)) { |
| 346 | link_changed = 1; |
| 347 | } |
| 348 | |
| 349 | lmac->last_link = phydev->link; |
| 350 | lmac->last_speed = phydev->speed; |
| 351 | lmac->last_duplex = phydev->duplex; |
| 352 | |
| 353 | if (!link_changed) |
| 354 | return; |
| 355 | |
| 356 | if (link_changed > 0) |
| 357 | lmac->link_up = true; |
| 358 | else |
| 359 | lmac->link_up = false; |
| 360 | |
| 361 | if (lmac->is_sgmii) |
| 362 | bgx_sgmii_change_link_state(lmac); |
| 363 | else |
| 364 | bgx_xaui_check_link(lmac); |
| 365 | } |
| 366 | |
| 367 | u64 bgx_get_rx_stats(int node, int bgx_idx, int lmac, int idx) |
| 368 | { |
| 369 | struct bgx *bgx; |
| 370 | |
Sunil Goutham | 09de391 | 2016-08-12 16:51:35 +0530 | [diff] [blame] | 371 | bgx = bgx_vnic[(node * MAX_BGX_PER_NODE) + bgx_idx]; |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 372 | if (!bgx) |
| 373 | return 0; |
| 374 | |
| 375 | if (idx > 8) |
| 376 | lmac = 0; |
| 377 | return bgx_reg_read(bgx, lmac, BGX_CMRX_RX_STAT0 + (idx * 8)); |
| 378 | } |
| 379 | EXPORT_SYMBOL(bgx_get_rx_stats); |
| 380 | |
| 381 | u64 bgx_get_tx_stats(int node, int bgx_idx, int lmac, int idx) |
| 382 | { |
| 383 | struct bgx *bgx; |
| 384 | |
Sunil Goutham | 09de391 | 2016-08-12 16:51:35 +0530 | [diff] [blame] | 385 | bgx = bgx_vnic[(node * MAX_BGX_PER_NODE) + bgx_idx]; |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 386 | if (!bgx) |
| 387 | return 0; |
| 388 | |
| 389 | return bgx_reg_read(bgx, lmac, BGX_CMRX_TX_STAT0 + (idx * 8)); |
| 390 | } |
| 391 | EXPORT_SYMBOL(bgx_get_tx_stats); |
| 392 | |
| 393 | static void bgx_flush_dmac_addrs(struct bgx *bgx, int lmac) |
| 394 | { |
| 395 | u64 offset; |
| 396 | |
| 397 | while (bgx->lmac[lmac].dmac > 0) { |
| 398 | offset = ((bgx->lmac[lmac].dmac - 1) * sizeof(u64)) + |
| 399 | (lmac * MAX_DMAC_PER_LMAC * sizeof(u64)); |
| 400 | bgx_reg_write(bgx, 0, BGX_CMR_RX_DMACX_CAM + offset, 0); |
| 401 | bgx->lmac[lmac].dmac--; |
| 402 | } |
| 403 | } |
| 404 | |
Sunil Goutham | d77a238 | 2015-08-30 12:29:16 +0300 | [diff] [blame] | 405 | /* Configure BGX LMAC in internal loopback mode */ |
| 406 | void bgx_lmac_internal_loopback(int node, int bgx_idx, |
| 407 | int lmac_idx, bool enable) |
| 408 | { |
| 409 | struct bgx *bgx; |
| 410 | struct lmac *lmac; |
| 411 | u64 cfg; |
| 412 | |
Sunil Goutham | 09de391 | 2016-08-12 16:51:35 +0530 | [diff] [blame] | 413 | bgx = bgx_vnic[(node * MAX_BGX_PER_NODE) + bgx_idx]; |
Sunil Goutham | d77a238 | 2015-08-30 12:29:16 +0300 | [diff] [blame] | 414 | if (!bgx) |
| 415 | return; |
| 416 | |
| 417 | lmac = &bgx->lmac[lmac_idx]; |
| 418 | if (lmac->is_sgmii) { |
| 419 | cfg = bgx_reg_read(bgx, lmac_idx, BGX_GMP_PCS_MRX_CTL); |
| 420 | if (enable) |
| 421 | cfg |= PCS_MRX_CTL_LOOPBACK1; |
| 422 | else |
| 423 | cfg &= ~PCS_MRX_CTL_LOOPBACK1; |
| 424 | bgx_reg_write(bgx, lmac_idx, BGX_GMP_PCS_MRX_CTL, cfg); |
| 425 | } else { |
| 426 | cfg = bgx_reg_read(bgx, lmac_idx, BGX_SPUX_CONTROL1); |
| 427 | if (enable) |
| 428 | cfg |= SPU_CTL_LOOPBACK; |
| 429 | else |
| 430 | cfg &= ~SPU_CTL_LOOPBACK; |
| 431 | bgx_reg_write(bgx, lmac_idx, BGX_SPUX_CONTROL1, cfg); |
| 432 | } |
| 433 | } |
| 434 | EXPORT_SYMBOL(bgx_lmac_internal_loopback); |
| 435 | |
Sunil Goutham | 3f8057c | 2016-08-12 16:51:32 +0530 | [diff] [blame] | 436 | static int bgx_lmac_sgmii_init(struct bgx *bgx, struct lmac *lmac) |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 437 | { |
Sunil Goutham | 3f8057c | 2016-08-12 16:51:32 +0530 | [diff] [blame] | 438 | int lmacid = lmac->lmacid; |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 439 | u64 cfg; |
| 440 | |
| 441 | bgx_reg_modify(bgx, lmacid, BGX_GMP_GMI_TXX_THRESH, 0x30); |
| 442 | /* max packet size */ |
| 443 | bgx_reg_modify(bgx, lmacid, BGX_GMP_GMI_RXX_JABBER, MAX_FRAME_SIZE); |
| 444 | |
| 445 | /* Disable frame alignment if using preamble */ |
| 446 | cfg = bgx_reg_read(bgx, lmacid, BGX_GMP_GMI_TXX_APPEND); |
| 447 | if (cfg & 1) |
| 448 | bgx_reg_write(bgx, lmacid, BGX_GMP_GMI_TXX_SGMII_CTL, 0); |
| 449 | |
| 450 | /* Enable lmac */ |
| 451 | bgx_reg_modify(bgx, lmacid, BGX_CMRX_CFG, CMR_EN); |
| 452 | |
| 453 | /* PCS reset */ |
| 454 | bgx_reg_modify(bgx, lmacid, BGX_GMP_PCS_MRX_CTL, PCS_MRX_CTL_RESET); |
| 455 | if (bgx_poll_reg(bgx, lmacid, BGX_GMP_PCS_MRX_CTL, |
| 456 | PCS_MRX_CTL_RESET, true)) { |
| 457 | dev_err(&bgx->pdev->dev, "BGX PCS reset not completed\n"); |
| 458 | return -1; |
| 459 | } |
| 460 | |
| 461 | /* power down, reset autoneg, autoneg enable */ |
| 462 | cfg = bgx_reg_read(bgx, lmacid, BGX_GMP_PCS_MRX_CTL); |
| 463 | cfg &= ~PCS_MRX_CTL_PWR_DN; |
| 464 | cfg |= (PCS_MRX_CTL_RST_AN | PCS_MRX_CTL_AN_EN); |
| 465 | bgx_reg_write(bgx, lmacid, BGX_GMP_PCS_MRX_CTL, cfg); |
| 466 | |
Sunil Goutham | 3f8057c | 2016-08-12 16:51:32 +0530 | [diff] [blame] | 467 | if (lmac->lmac_type == BGX_MODE_QSGMII) { |
| 468 | /* Disable disparity check for QSGMII */ |
| 469 | cfg = bgx_reg_read(bgx, lmacid, BGX_GMP_PCS_MISCX_CTL); |
| 470 | cfg &= ~PCS_MISC_CTL_DISP_EN; |
| 471 | bgx_reg_write(bgx, lmacid, BGX_GMP_PCS_MISCX_CTL, cfg); |
| 472 | return 0; |
| 473 | } |
| 474 | |
Sunil Goutham | 6465859 | 2016-08-12 16:51:33 +0530 | [diff] [blame] | 475 | if (lmac->lmac_type == BGX_MODE_SGMII) { |
| 476 | if (bgx_poll_reg(bgx, lmacid, BGX_GMP_PCS_MRX_STATUS, |
| 477 | PCS_MRX_STATUS_AN_CPT, false)) { |
| 478 | dev_err(&bgx->pdev->dev, "BGX AN_CPT not completed\n"); |
| 479 | return -1; |
| 480 | } |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | return 0; |
| 484 | } |
| 485 | |
Sunil Goutham | 0bcb7d5 | 2016-08-12 16:51:30 +0530 | [diff] [blame] | 486 | static int bgx_lmac_xaui_init(struct bgx *bgx, struct lmac *lmac) |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 487 | { |
| 488 | u64 cfg; |
Sunil Goutham | 0bcb7d5 | 2016-08-12 16:51:30 +0530 | [diff] [blame] | 489 | int lmacid = lmac->lmacid; |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 490 | |
| 491 | /* Reset SPU */ |
| 492 | bgx_reg_modify(bgx, lmacid, BGX_SPUX_CONTROL1, SPU_CTL_RESET); |
| 493 | if (bgx_poll_reg(bgx, lmacid, BGX_SPUX_CONTROL1, SPU_CTL_RESET, true)) { |
| 494 | dev_err(&bgx->pdev->dev, "BGX SPU reset not completed\n"); |
| 495 | return -1; |
| 496 | } |
| 497 | |
| 498 | /* Disable LMAC */ |
| 499 | cfg = bgx_reg_read(bgx, lmacid, BGX_CMRX_CFG); |
| 500 | cfg &= ~CMR_EN; |
| 501 | bgx_reg_write(bgx, lmacid, BGX_CMRX_CFG, cfg); |
| 502 | |
| 503 | bgx_reg_modify(bgx, lmacid, BGX_SPUX_CONTROL1, SPU_CTL_LOW_POWER); |
| 504 | /* Set interleaved running disparity for RXAUI */ |
Sunil Goutham | 93db2cf | 2016-08-12 16:51:44 +0530 | [diff] [blame] | 505 | if (lmac->lmac_type == BGX_MODE_RXAUI) |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 506 | bgx_reg_modify(bgx, lmacid, BGX_SPUX_MISC_CONTROL, |
Sunil Goutham | 93db2cf | 2016-08-12 16:51:44 +0530 | [diff] [blame] | 507 | SPU_MISC_CTL_INTLV_RDISP); |
| 508 | |
| 509 | /* Clear receive packet disable */ |
| 510 | cfg = bgx_reg_read(bgx, lmacid, BGX_SPUX_MISC_CONTROL); |
| 511 | cfg &= ~SPU_MISC_CTL_RX_DIS; |
| 512 | bgx_reg_write(bgx, lmacid, BGX_SPUX_MISC_CONTROL, cfg); |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 513 | |
| 514 | /* clear all interrupts */ |
| 515 | cfg = bgx_reg_read(bgx, lmacid, BGX_SMUX_RX_INT); |
| 516 | bgx_reg_write(bgx, lmacid, BGX_SMUX_RX_INT, cfg); |
| 517 | cfg = bgx_reg_read(bgx, lmacid, BGX_SMUX_TX_INT); |
| 518 | bgx_reg_write(bgx, lmacid, BGX_SMUX_TX_INT, cfg); |
| 519 | cfg = bgx_reg_read(bgx, lmacid, BGX_SPUX_INT); |
| 520 | bgx_reg_write(bgx, lmacid, BGX_SPUX_INT, cfg); |
| 521 | |
Sunil Goutham | 0bcb7d5 | 2016-08-12 16:51:30 +0530 | [diff] [blame] | 522 | if (lmac->use_training) { |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 523 | bgx_reg_write(bgx, lmacid, BGX_SPUX_BR_PMD_LP_CUP, 0x00); |
| 524 | bgx_reg_write(bgx, lmacid, BGX_SPUX_BR_PMD_LD_CUP, 0x00); |
| 525 | bgx_reg_write(bgx, lmacid, BGX_SPUX_BR_PMD_LD_REP, 0x00); |
| 526 | /* training enable */ |
| 527 | bgx_reg_modify(bgx, lmacid, |
| 528 | BGX_SPUX_BR_PMD_CRTL, SPU_PMD_CRTL_TRAIN_EN); |
| 529 | } |
| 530 | |
| 531 | /* Append FCS to each packet */ |
| 532 | bgx_reg_modify(bgx, lmacid, BGX_SMUX_TX_APPEND, SMU_TX_APPEND_FCS_D); |
| 533 | |
| 534 | /* Disable forward error correction */ |
| 535 | cfg = bgx_reg_read(bgx, lmacid, BGX_SPUX_FEC_CONTROL); |
| 536 | cfg &= ~SPU_FEC_CTL_FEC_EN; |
| 537 | bgx_reg_write(bgx, lmacid, BGX_SPUX_FEC_CONTROL, cfg); |
| 538 | |
| 539 | /* Disable autoneg */ |
| 540 | cfg = bgx_reg_read(bgx, lmacid, BGX_SPUX_AN_CONTROL); |
| 541 | cfg = cfg & ~(SPU_AN_CTL_AN_EN | SPU_AN_CTL_XNP_EN); |
| 542 | bgx_reg_write(bgx, lmacid, BGX_SPUX_AN_CONTROL, cfg); |
| 543 | |
| 544 | cfg = bgx_reg_read(bgx, lmacid, BGX_SPUX_AN_ADV); |
Sunil Goutham | 0bcb7d5 | 2016-08-12 16:51:30 +0530 | [diff] [blame] | 545 | if (lmac->lmac_type == BGX_MODE_10G_KR) |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 546 | cfg |= (1 << 23); |
Sunil Goutham | 0bcb7d5 | 2016-08-12 16:51:30 +0530 | [diff] [blame] | 547 | else if (lmac->lmac_type == BGX_MODE_40G_KR) |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 548 | cfg |= (1 << 24); |
| 549 | else |
| 550 | cfg &= ~((1 << 23) | (1 << 24)); |
| 551 | cfg = cfg & (~((1ULL << 25) | (1ULL << 22) | (1ULL << 12))); |
| 552 | bgx_reg_write(bgx, lmacid, BGX_SPUX_AN_ADV, cfg); |
| 553 | |
| 554 | cfg = bgx_reg_read(bgx, 0, BGX_SPU_DBG_CONTROL); |
| 555 | cfg &= ~SPU_DBG_CTL_AN_ARB_LINK_CHK_EN; |
| 556 | bgx_reg_write(bgx, 0, BGX_SPU_DBG_CONTROL, cfg); |
| 557 | |
| 558 | /* Enable lmac */ |
| 559 | bgx_reg_modify(bgx, lmacid, BGX_CMRX_CFG, CMR_EN); |
| 560 | |
| 561 | cfg = bgx_reg_read(bgx, lmacid, BGX_SPUX_CONTROL1); |
| 562 | cfg &= ~SPU_CTL_LOW_POWER; |
| 563 | bgx_reg_write(bgx, lmacid, BGX_SPUX_CONTROL1, cfg); |
| 564 | |
| 565 | cfg = bgx_reg_read(bgx, lmacid, BGX_SMUX_TX_CTL); |
| 566 | cfg &= ~SMU_TX_CTL_UNI_EN; |
| 567 | cfg |= SMU_TX_CTL_DIC_EN; |
| 568 | bgx_reg_write(bgx, lmacid, BGX_SMUX_TX_CTL, cfg); |
| 569 | |
Sunil Goutham | 430da20 | 2016-11-24 14:48:03 +0530 | [diff] [blame] | 570 | /* Enable receive and transmission of pause frames */ |
| 571 | bgx_reg_write(bgx, lmacid, BGX_SMUX_CBFC_CTL, ((0xffffULL << 32) | |
| 572 | BCK_EN | DRP_EN | TX_EN | RX_EN)); |
| 573 | /* Configure pause time and interval */ |
| 574 | bgx_reg_write(bgx, lmacid, |
| 575 | BGX_SMUX_TX_PAUSE_PKT_TIME, DEFAULT_PAUSE_TIME); |
| 576 | cfg = bgx_reg_read(bgx, lmacid, BGX_SMUX_TX_PAUSE_PKT_INTERVAL); |
| 577 | cfg &= ~0xFFFFull; |
| 578 | bgx_reg_write(bgx, lmacid, BGX_SMUX_TX_PAUSE_PKT_INTERVAL, |
| 579 | cfg | (DEFAULT_PAUSE_TIME - 0x1000)); |
| 580 | bgx_reg_write(bgx, lmacid, BGX_SMUX_TX_PAUSE_ZERO, 0x01); |
| 581 | |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 582 | /* take lmac_count into account */ |
| 583 | bgx_reg_modify(bgx, lmacid, BGX_SMUX_TX_THRESH, (0x100 - 1)); |
| 584 | /* max packet size */ |
| 585 | bgx_reg_modify(bgx, lmacid, BGX_SMUX_RX_JABBER, MAX_FRAME_SIZE); |
| 586 | |
| 587 | return 0; |
| 588 | } |
| 589 | |
| 590 | static int bgx_xaui_check_link(struct lmac *lmac) |
| 591 | { |
| 592 | struct bgx *bgx = lmac->bgx; |
| 593 | int lmacid = lmac->lmacid; |
Sunil Goutham | 0bcb7d5 | 2016-08-12 16:51:30 +0530 | [diff] [blame] | 594 | int lmac_type = lmac->lmac_type; |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 595 | u64 cfg; |
| 596 | |
Sunil Goutham | 0bcb7d5 | 2016-08-12 16:51:30 +0530 | [diff] [blame] | 597 | if (lmac->use_training) { |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 598 | cfg = bgx_reg_read(bgx, lmacid, BGX_SPUX_INT); |
| 599 | if (!(cfg & (1ull << 13))) { |
| 600 | cfg = (1ull << 13) | (1ull << 14); |
| 601 | bgx_reg_write(bgx, lmacid, BGX_SPUX_INT, cfg); |
| 602 | cfg = bgx_reg_read(bgx, lmacid, BGX_SPUX_BR_PMD_CRTL); |
| 603 | cfg |= (1ull << 0); |
| 604 | bgx_reg_write(bgx, lmacid, BGX_SPUX_BR_PMD_CRTL, cfg); |
| 605 | return -1; |
| 606 | } |
| 607 | } |
| 608 | |
| 609 | /* wait for PCS to come out of reset */ |
| 610 | if (bgx_poll_reg(bgx, lmacid, BGX_SPUX_CONTROL1, SPU_CTL_RESET, true)) { |
| 611 | dev_err(&bgx->pdev->dev, "BGX SPU reset not completed\n"); |
| 612 | return -1; |
| 613 | } |
| 614 | |
| 615 | if ((lmac_type == BGX_MODE_10G_KR) || (lmac_type == BGX_MODE_XFI) || |
| 616 | (lmac_type == BGX_MODE_40G_KR) || (lmac_type == BGX_MODE_XLAUI)) { |
| 617 | if (bgx_poll_reg(bgx, lmacid, BGX_SPUX_BR_STATUS1, |
| 618 | SPU_BR_STATUS_BLK_LOCK, false)) { |
| 619 | dev_err(&bgx->pdev->dev, |
| 620 | "SPU_BR_STATUS_BLK_LOCK not completed\n"); |
| 621 | return -1; |
| 622 | } |
| 623 | } else { |
| 624 | if (bgx_poll_reg(bgx, lmacid, BGX_SPUX_BX_STATUS, |
| 625 | SPU_BX_STATUS_RX_ALIGN, false)) { |
| 626 | dev_err(&bgx->pdev->dev, |
| 627 | "SPU_BX_STATUS_RX_ALIGN not completed\n"); |
| 628 | return -1; |
| 629 | } |
| 630 | } |
| 631 | |
| 632 | /* Clear rcvflt bit (latching high) and read it back */ |
Sunil Goutham | 3f4c68c | 2016-06-27 15:30:02 +0530 | [diff] [blame] | 633 | if (bgx_reg_read(bgx, lmacid, BGX_SPUX_STATUS2) & SPU_STATUS2_RCVFLT) |
| 634 | bgx_reg_modify(bgx, lmacid, |
| 635 | BGX_SPUX_STATUS2, SPU_STATUS2_RCVFLT); |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 636 | if (bgx_reg_read(bgx, lmacid, BGX_SPUX_STATUS2) & SPU_STATUS2_RCVFLT) { |
| 637 | dev_err(&bgx->pdev->dev, "Receive fault, retry training\n"); |
Sunil Goutham | 0bcb7d5 | 2016-08-12 16:51:30 +0530 | [diff] [blame] | 638 | if (lmac->use_training) { |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 639 | cfg = bgx_reg_read(bgx, lmacid, BGX_SPUX_INT); |
| 640 | if (!(cfg & (1ull << 13))) { |
| 641 | cfg = (1ull << 13) | (1ull << 14); |
| 642 | bgx_reg_write(bgx, lmacid, BGX_SPUX_INT, cfg); |
| 643 | cfg = bgx_reg_read(bgx, lmacid, |
| 644 | BGX_SPUX_BR_PMD_CRTL); |
| 645 | cfg |= (1ull << 0); |
| 646 | bgx_reg_write(bgx, lmacid, |
| 647 | BGX_SPUX_BR_PMD_CRTL, cfg); |
| 648 | return -1; |
| 649 | } |
| 650 | } |
| 651 | return -1; |
| 652 | } |
| 653 | |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 654 | /* Wait for BGX RX to be idle */ |
| 655 | if (bgx_poll_reg(bgx, lmacid, BGX_SMUX_CTL, SMU_CTL_RX_IDLE, false)) { |
| 656 | dev_err(&bgx->pdev->dev, "SMU RX not idle\n"); |
| 657 | return -1; |
| 658 | } |
| 659 | |
| 660 | /* Wait for BGX TX to be idle */ |
| 661 | if (bgx_poll_reg(bgx, lmacid, BGX_SMUX_CTL, SMU_CTL_TX_IDLE, false)) { |
| 662 | dev_err(&bgx->pdev->dev, "SMU TX not idle\n"); |
| 663 | return -1; |
| 664 | } |
| 665 | |
Sunil Goutham | 3f4c68c | 2016-06-27 15:30:02 +0530 | [diff] [blame] | 666 | /* Check for MAC RX faults */ |
| 667 | cfg = bgx_reg_read(bgx, lmacid, BGX_SMUX_RX_CTL); |
| 668 | /* 0 - Link is okay, 1 - Local fault, 2 - Remote fault */ |
| 669 | cfg &= SMU_RX_CTL_STATUS; |
| 670 | if (!cfg) |
| 671 | return 0; |
| 672 | |
| 673 | /* Rx local/remote fault seen. |
| 674 | * Do lmac reinit to see if condition recovers |
| 675 | */ |
Sunil Goutham | 0bcb7d5 | 2016-08-12 16:51:30 +0530 | [diff] [blame] | 676 | bgx_lmac_xaui_init(bgx, lmac); |
Sunil Goutham | 3f4c68c | 2016-06-27 15:30:02 +0530 | [diff] [blame] | 677 | |
| 678 | return -1; |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | static void bgx_poll_for_link(struct work_struct *work) |
| 682 | { |
| 683 | struct lmac *lmac; |
Sunil Goutham | 3f4c68c | 2016-06-27 15:30:02 +0530 | [diff] [blame] | 684 | u64 spu_link, smu_link; |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 685 | |
| 686 | lmac = container_of(work, struct lmac, dwork.work); |
| 687 | |
| 688 | /* Receive link is latching low. Force it high and verify it */ |
| 689 | bgx_reg_modify(lmac->bgx, lmac->lmacid, |
| 690 | BGX_SPUX_STATUS1, SPU_STATUS1_RCV_LNK); |
| 691 | bgx_poll_reg(lmac->bgx, lmac->lmacid, BGX_SPUX_STATUS1, |
| 692 | SPU_STATUS1_RCV_LNK, false); |
| 693 | |
Sunil Goutham | 3f4c68c | 2016-06-27 15:30:02 +0530 | [diff] [blame] | 694 | spu_link = bgx_reg_read(lmac->bgx, lmac->lmacid, BGX_SPUX_STATUS1); |
| 695 | smu_link = bgx_reg_read(lmac->bgx, lmac->lmacid, BGX_SMUX_RX_CTL); |
| 696 | |
| 697 | if ((spu_link & SPU_STATUS1_RCV_LNK) && |
| 698 | !(smu_link & SMU_RX_CTL_STATUS)) { |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 699 | lmac->link_up = 1; |
Sunil Goutham | 0bcb7d5 | 2016-08-12 16:51:30 +0530 | [diff] [blame] | 700 | if (lmac->lmac_type == BGX_MODE_XLAUI) |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 701 | lmac->last_speed = 40000; |
| 702 | else |
| 703 | lmac->last_speed = 10000; |
| 704 | lmac->last_duplex = 1; |
| 705 | } else { |
| 706 | lmac->link_up = 0; |
Sunil Goutham | 0b72a9a | 2015-12-02 15:36:16 +0530 | [diff] [blame] | 707 | lmac->last_speed = SPEED_UNKNOWN; |
| 708 | lmac->last_duplex = DUPLEX_UNKNOWN; |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | if (lmac->last_link != lmac->link_up) { |
Sunil Goutham | 3f4c68c | 2016-06-27 15:30:02 +0530 | [diff] [blame] | 712 | if (lmac->link_up) { |
| 713 | if (bgx_xaui_check_link(lmac)) { |
| 714 | /* Errors, clear link_up state */ |
| 715 | lmac->link_up = 0; |
| 716 | lmac->last_speed = SPEED_UNKNOWN; |
| 717 | lmac->last_duplex = DUPLEX_UNKNOWN; |
| 718 | } |
| 719 | } |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 720 | lmac->last_link = lmac->link_up; |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | queue_delayed_work(lmac->check_link, &lmac->dwork, HZ * 2); |
| 724 | } |
| 725 | |
Sunil Goutham | 3f8057c | 2016-08-12 16:51:32 +0530 | [diff] [blame] | 726 | static int phy_interface_mode(u8 lmac_type) |
| 727 | { |
| 728 | if (lmac_type == BGX_MODE_QSGMII) |
| 729 | return PHY_INTERFACE_MODE_QSGMII; |
Sunil Goutham | 6465859 | 2016-08-12 16:51:33 +0530 | [diff] [blame] | 730 | if (lmac_type == BGX_MODE_RGMII) |
| 731 | return PHY_INTERFACE_MODE_RGMII; |
Sunil Goutham | 3f8057c | 2016-08-12 16:51:32 +0530 | [diff] [blame] | 732 | |
| 733 | return PHY_INTERFACE_MODE_SGMII; |
| 734 | } |
| 735 | |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 736 | static int bgx_lmac_enable(struct bgx *bgx, u8 lmacid) |
| 737 | { |
| 738 | struct lmac *lmac; |
| 739 | u64 cfg; |
| 740 | |
| 741 | lmac = &bgx->lmac[lmacid]; |
| 742 | lmac->bgx = bgx; |
| 743 | |
Sunil Goutham | 3f8057c | 2016-08-12 16:51:32 +0530 | [diff] [blame] | 744 | if ((lmac->lmac_type == BGX_MODE_SGMII) || |
Sunil Goutham | 6465859 | 2016-08-12 16:51:33 +0530 | [diff] [blame] | 745 | (lmac->lmac_type == BGX_MODE_QSGMII) || |
| 746 | (lmac->lmac_type == BGX_MODE_RGMII)) { |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 747 | lmac->is_sgmii = 1; |
Sunil Goutham | 3f8057c | 2016-08-12 16:51:32 +0530 | [diff] [blame] | 748 | if (bgx_lmac_sgmii_init(bgx, lmac)) |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 749 | return -1; |
| 750 | } else { |
| 751 | lmac->is_sgmii = 0; |
Sunil Goutham | 0bcb7d5 | 2016-08-12 16:51:30 +0530 | [diff] [blame] | 752 | if (bgx_lmac_xaui_init(bgx, lmac)) |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 753 | return -1; |
| 754 | } |
| 755 | |
| 756 | if (lmac->is_sgmii) { |
| 757 | cfg = bgx_reg_read(bgx, lmacid, BGX_GMP_GMI_TXX_APPEND); |
| 758 | cfg |= ((1ull << 2) | (1ull << 1)); /* FCS and PAD */ |
| 759 | bgx_reg_modify(bgx, lmacid, BGX_GMP_GMI_TXX_APPEND, cfg); |
| 760 | bgx_reg_write(bgx, lmacid, BGX_GMP_GMI_TXX_MIN_PKT, 60 - 1); |
| 761 | } else { |
| 762 | cfg = bgx_reg_read(bgx, lmacid, BGX_SMUX_TX_APPEND); |
| 763 | cfg |= ((1ull << 2) | (1ull << 1)); /* FCS and PAD */ |
| 764 | bgx_reg_modify(bgx, lmacid, BGX_SMUX_TX_APPEND, cfg); |
| 765 | bgx_reg_write(bgx, lmacid, BGX_SMUX_TX_MIN_PKT, 60 + 4); |
| 766 | } |
| 767 | |
| 768 | /* Enable lmac */ |
Sunil Goutham | bc69fdf | 2015-12-02 15:36:17 +0530 | [diff] [blame] | 769 | bgx_reg_modify(bgx, lmacid, BGX_CMRX_CFG, CMR_EN); |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 770 | |
| 771 | /* Restore default cfg, incase low level firmware changed it */ |
| 772 | bgx_reg_write(bgx, lmacid, BGX_CMRX_RX_DMAC_CTL, 0x03); |
| 773 | |
Sunil Goutham | 0bcb7d5 | 2016-08-12 16:51:30 +0530 | [diff] [blame] | 774 | if ((lmac->lmac_type != BGX_MODE_XFI) && |
| 775 | (lmac->lmac_type != BGX_MODE_XLAUI) && |
| 776 | (lmac->lmac_type != BGX_MODE_40G_KR) && |
| 777 | (lmac->lmac_type != BGX_MODE_10G_KR)) { |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 778 | if (!lmac->phydev) |
| 779 | return -ENODEV; |
| 780 | |
| 781 | lmac->phydev->dev_flags = 0; |
| 782 | |
| 783 | if (phy_connect_direct(&lmac->netdev, lmac->phydev, |
| 784 | bgx_lmac_handler, |
Sunil Goutham | 3f8057c | 2016-08-12 16:51:32 +0530 | [diff] [blame] | 785 | phy_interface_mode(lmac->lmac_type))) |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 786 | return -ENODEV; |
| 787 | |
| 788 | phy_start_aneg(lmac->phydev); |
| 789 | } else { |
| 790 | lmac->check_link = alloc_workqueue("check_link", WQ_UNBOUND | |
| 791 | WQ_MEM_RECLAIM, 1); |
| 792 | if (!lmac->check_link) |
| 793 | return -ENOMEM; |
| 794 | INIT_DELAYED_WORK(&lmac->dwork, bgx_poll_for_link); |
| 795 | queue_delayed_work(lmac->check_link, &lmac->dwork, 0); |
| 796 | } |
| 797 | |
| 798 | return 0; |
| 799 | } |
| 800 | |
Aleksey Makarov | fd7ec06 | 2015-06-02 11:00:23 -0700 | [diff] [blame] | 801 | static void bgx_lmac_disable(struct bgx *bgx, u8 lmacid) |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 802 | { |
| 803 | struct lmac *lmac; |
Sunil Goutham | 3f4c68c | 2016-06-27 15:30:02 +0530 | [diff] [blame] | 804 | u64 cfg; |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 805 | |
| 806 | lmac = &bgx->lmac[lmacid]; |
| 807 | if (lmac->check_link) { |
| 808 | /* Destroy work queue */ |
Thanneeru Srinivasulu | a7b1f53 | 2015-12-02 15:36:14 +0530 | [diff] [blame] | 809 | cancel_delayed_work_sync(&lmac->dwork); |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 810 | destroy_workqueue(lmac->check_link); |
| 811 | } |
| 812 | |
Sunil Goutham | 3f4c68c | 2016-06-27 15:30:02 +0530 | [diff] [blame] | 813 | /* Disable packet reception */ |
| 814 | cfg = bgx_reg_read(bgx, lmacid, BGX_CMRX_CFG); |
| 815 | cfg &= ~CMR_PKT_RX_EN; |
| 816 | bgx_reg_write(bgx, lmacid, BGX_CMRX_CFG, cfg); |
| 817 | |
| 818 | /* Give chance for Rx/Tx FIFO to get drained */ |
| 819 | bgx_poll_reg(bgx, lmacid, BGX_CMRX_RX_FIFO_LEN, (u64)0x1FFF, true); |
| 820 | bgx_poll_reg(bgx, lmacid, BGX_CMRX_TX_FIFO_LEN, (u64)0x3FFF, true); |
| 821 | |
| 822 | /* Disable packet transmission */ |
| 823 | cfg = bgx_reg_read(bgx, lmacid, BGX_CMRX_CFG); |
| 824 | cfg &= ~CMR_PKT_TX_EN; |
| 825 | bgx_reg_write(bgx, lmacid, BGX_CMRX_CFG, cfg); |
| 826 | |
| 827 | /* Disable serdes lanes */ |
| 828 | if (!lmac->is_sgmii) |
| 829 | bgx_reg_modify(bgx, lmacid, |
| 830 | BGX_SPUX_CONTROL1, SPU_CTL_LOW_POWER); |
| 831 | else |
| 832 | bgx_reg_modify(bgx, lmacid, |
| 833 | BGX_GMP_PCS_MRX_CTL, PCS_MRX_CTL_PWR_DN); |
| 834 | |
| 835 | /* Disable LMAC */ |
| 836 | cfg = bgx_reg_read(bgx, lmacid, BGX_CMRX_CFG); |
| 837 | cfg &= ~CMR_EN; |
| 838 | bgx_reg_write(bgx, lmacid, BGX_CMRX_CFG, cfg); |
| 839 | |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 840 | bgx_flush_dmac_addrs(bgx, lmacid); |
| 841 | |
Sunil Goutham | 0bcb7d5 | 2016-08-12 16:51:30 +0530 | [diff] [blame] | 842 | if ((lmac->lmac_type != BGX_MODE_XFI) && |
| 843 | (lmac->lmac_type != BGX_MODE_XLAUI) && |
| 844 | (lmac->lmac_type != BGX_MODE_40G_KR) && |
| 845 | (lmac->lmac_type != BGX_MODE_10G_KR) && lmac->phydev) |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 846 | phy_disconnect(lmac->phydev); |
| 847 | |
| 848 | lmac->phydev = NULL; |
| 849 | } |
| 850 | |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 851 | static void bgx_init_hw(struct bgx *bgx) |
| 852 | { |
| 853 | int i; |
Sunil Goutham | 0bcb7d5 | 2016-08-12 16:51:30 +0530 | [diff] [blame] | 854 | struct lmac *lmac; |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 855 | |
| 856 | bgx_reg_modify(bgx, 0, BGX_CMR_GLOBAL_CFG, CMR_GLOBAL_CFG_FCS_STRIP); |
| 857 | if (bgx_reg_read(bgx, 0, BGX_CMR_BIST_STATUS)) |
| 858 | dev_err(&bgx->pdev->dev, "BGX%d BIST failed\n", bgx->bgx_id); |
| 859 | |
| 860 | /* Set lmac type and lane2serdes mapping */ |
| 861 | for (i = 0; i < bgx->lmac_count; i++) { |
Sunil Goutham | 0bcb7d5 | 2016-08-12 16:51:30 +0530 | [diff] [blame] | 862 | lmac = &bgx->lmac[i]; |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 863 | bgx_reg_write(bgx, i, BGX_CMRX_CFG, |
Sunil Goutham | 0bcb7d5 | 2016-08-12 16:51:30 +0530 | [diff] [blame] | 864 | (lmac->lmac_type << 8) | lmac->lane_to_sds); |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 865 | bgx->lmac[i].lmacid_bd = lmac_count; |
| 866 | lmac_count++; |
| 867 | } |
| 868 | |
| 869 | bgx_reg_write(bgx, 0, BGX_CMR_TX_LMACS, bgx->lmac_count); |
| 870 | bgx_reg_write(bgx, 0, BGX_CMR_RX_LMACS, bgx->lmac_count); |
| 871 | |
| 872 | /* Set the backpressure AND mask */ |
| 873 | for (i = 0; i < bgx->lmac_count; i++) |
| 874 | bgx_reg_modify(bgx, 0, BGX_CMR_CHAN_MSK_AND, |
| 875 | ((1ULL << MAX_BGX_CHANS_PER_LMAC) - 1) << |
| 876 | (i * MAX_BGX_CHANS_PER_LMAC)); |
| 877 | |
| 878 | /* Disable all MAC filtering */ |
| 879 | for (i = 0; i < RX_DMAC_COUNT; i++) |
| 880 | bgx_reg_write(bgx, 0, BGX_CMR_RX_DMACX_CAM + (i * 8), 0x00); |
| 881 | |
| 882 | /* Disable MAC steering (NCSI traffic) */ |
| 883 | for (i = 0; i < RX_TRAFFIC_STEER_RULE_COUNT; i++) |
| 884 | bgx_reg_write(bgx, 0, BGX_CMR_RX_STREERING + (i * 8), 0x00); |
| 885 | } |
| 886 | |
Sunil Goutham | 3f8057c | 2016-08-12 16:51:32 +0530 | [diff] [blame] | 887 | static u8 bgx_get_lane2sds_cfg(struct bgx *bgx, struct lmac *lmac) |
| 888 | { |
| 889 | return (u8)(bgx_reg_read(bgx, lmac->lmacid, BGX_CMRX_CFG) & 0xFF); |
| 890 | } |
| 891 | |
Sunil Goutham | 0bcb7d5 | 2016-08-12 16:51:30 +0530 | [diff] [blame] | 892 | static void bgx_print_qlm_mode(struct bgx *bgx, u8 lmacid) |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 893 | { |
| 894 | struct device *dev = &bgx->pdev->dev; |
Sunil Goutham | 0bcb7d5 | 2016-08-12 16:51:30 +0530 | [diff] [blame] | 895 | struct lmac *lmac; |
| 896 | char str[20]; |
Sunil Goutham | 57aaf63 | 2016-08-12 16:51:31 +0530 | [diff] [blame] | 897 | |
Sunil Goutham | fff37fd | 2017-01-25 17:36:24 +0530 | [diff] [blame^] | 898 | if (!bgx->is_dlm && lmacid) |
Sunil Goutham | 57aaf63 | 2016-08-12 16:51:31 +0530 | [diff] [blame] | 899 | return; |
Sunil Goutham | 0bcb7d5 | 2016-08-12 16:51:30 +0530 | [diff] [blame] | 900 | |
| 901 | lmac = &bgx->lmac[lmacid]; |
Sunil Goutham | 09de391 | 2016-08-12 16:51:35 +0530 | [diff] [blame] | 902 | if (!bgx->is_dlm) |
Sunil Goutham | 57aaf63 | 2016-08-12 16:51:31 +0530 | [diff] [blame] | 903 | sprintf(str, "BGX%d QLM mode", bgx->bgx_id); |
| 904 | else |
Sunil Goutham | fff37fd | 2017-01-25 17:36:24 +0530 | [diff] [blame^] | 905 | sprintf(str, "BGX%d LMAC%d mode", bgx->bgx_id, lmacid); |
Sunil Goutham | 0bcb7d5 | 2016-08-12 16:51:30 +0530 | [diff] [blame] | 906 | |
| 907 | switch (lmac->lmac_type) { |
| 908 | case BGX_MODE_SGMII: |
| 909 | dev_info(dev, "%s: SGMII\n", (char *)str); |
| 910 | break; |
| 911 | case BGX_MODE_XAUI: |
| 912 | dev_info(dev, "%s: XAUI\n", (char *)str); |
| 913 | break; |
| 914 | case BGX_MODE_RXAUI: |
| 915 | dev_info(dev, "%s: RXAUI\n", (char *)str); |
| 916 | break; |
| 917 | case BGX_MODE_XFI: |
| 918 | if (!lmac->use_training) |
| 919 | dev_info(dev, "%s: XFI\n", (char *)str); |
| 920 | else |
| 921 | dev_info(dev, "%s: 10G_KR\n", (char *)str); |
| 922 | break; |
| 923 | case BGX_MODE_XLAUI: |
| 924 | if (!lmac->use_training) |
| 925 | dev_info(dev, "%s: XLAUI\n", (char *)str); |
| 926 | else |
| 927 | dev_info(dev, "%s: 40G_KR4\n", (char *)str); |
| 928 | break; |
Sunil Goutham | 3f8057c | 2016-08-12 16:51:32 +0530 | [diff] [blame] | 929 | case BGX_MODE_QSGMII: |
| 930 | if ((lmacid == 0) && |
| 931 | (bgx_get_lane2sds_cfg(bgx, lmac) != lmacid)) |
| 932 | return; |
| 933 | if ((lmacid == 2) && |
| 934 | (bgx_get_lane2sds_cfg(bgx, lmac) == lmacid)) |
| 935 | return; |
| 936 | dev_info(dev, "%s: QSGMII\n", (char *)str); |
| 937 | break; |
Sunil Goutham | 6465859 | 2016-08-12 16:51:33 +0530 | [diff] [blame] | 938 | case BGX_MODE_RGMII: |
| 939 | dev_info(dev, "%s: RGMII\n", (char *)str); |
| 940 | break; |
Sunil Goutham | 3f8057c | 2016-08-12 16:51:32 +0530 | [diff] [blame] | 941 | case BGX_MODE_INVALID: |
| 942 | /* Nothing to do */ |
| 943 | break; |
Sunil Goutham | 0bcb7d5 | 2016-08-12 16:51:30 +0530 | [diff] [blame] | 944 | } |
| 945 | } |
| 946 | |
Sunil Goutham | 3f8057c | 2016-08-12 16:51:32 +0530 | [diff] [blame] | 947 | static void lmac_set_lane2sds(struct bgx *bgx, struct lmac *lmac) |
Sunil Goutham | 0bcb7d5 | 2016-08-12 16:51:30 +0530 | [diff] [blame] | 948 | { |
| 949 | switch (lmac->lmac_type) { |
| 950 | case BGX_MODE_SGMII: |
| 951 | case BGX_MODE_XFI: |
| 952 | lmac->lane_to_sds = lmac->lmacid; |
| 953 | break; |
| 954 | case BGX_MODE_XAUI: |
| 955 | case BGX_MODE_XLAUI: |
Sunil Goutham | 6465859 | 2016-08-12 16:51:33 +0530 | [diff] [blame] | 956 | case BGX_MODE_RGMII: |
Sunil Goutham | 0bcb7d5 | 2016-08-12 16:51:30 +0530 | [diff] [blame] | 957 | lmac->lane_to_sds = 0xE4; |
| 958 | break; |
| 959 | case BGX_MODE_RXAUI: |
| 960 | lmac->lane_to_sds = (lmac->lmacid) ? 0xE : 0x4; |
| 961 | break; |
Sunil Goutham | 3f8057c | 2016-08-12 16:51:32 +0530 | [diff] [blame] | 962 | case BGX_MODE_QSGMII: |
| 963 | /* There is no way to determine if DLM0/2 is QSGMII or |
| 964 | * DLM1/3 is configured to QSGMII as bootloader will |
| 965 | * configure all LMACs, so take whatever is configured |
| 966 | * by low level firmware. |
| 967 | */ |
| 968 | lmac->lane_to_sds = bgx_get_lane2sds_cfg(bgx, lmac); |
| 969 | break; |
Sunil Goutham | 0bcb7d5 | 2016-08-12 16:51:30 +0530 | [diff] [blame] | 970 | default: |
| 971 | lmac->lane_to_sds = 0; |
| 972 | break; |
| 973 | } |
| 974 | } |
| 975 | |
Sunil Goutham | 6465859 | 2016-08-12 16:51:33 +0530 | [diff] [blame] | 976 | static void lmac_set_training(struct bgx *bgx, struct lmac *lmac, int lmacid) |
| 977 | { |
| 978 | if ((lmac->lmac_type != BGX_MODE_10G_KR) && |
| 979 | (lmac->lmac_type != BGX_MODE_40G_KR)) { |
| 980 | lmac->use_training = 0; |
| 981 | return; |
| 982 | } |
| 983 | |
| 984 | lmac->use_training = bgx_reg_read(bgx, lmacid, BGX_SPUX_BR_PMD_CRTL) & |
| 985 | SPU_PMD_CRTL_TRAIN_EN; |
| 986 | } |
| 987 | |
Sunil Goutham | 0bcb7d5 | 2016-08-12 16:51:30 +0530 | [diff] [blame] | 988 | static void bgx_set_lmac_config(struct bgx *bgx, u8 idx) |
| 989 | { |
| 990 | struct lmac *lmac; |
| 991 | u64 cmr_cfg; |
Sunil Goutham | 57aaf63 | 2016-08-12 16:51:31 +0530 | [diff] [blame] | 992 | u8 lmac_type; |
| 993 | u8 lane_to_sds; |
Sunil Goutham | 0bcb7d5 | 2016-08-12 16:51:30 +0530 | [diff] [blame] | 994 | |
| 995 | lmac = &bgx->lmac[idx]; |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 996 | |
Sunil Goutham | 09de391 | 2016-08-12 16:51:35 +0530 | [diff] [blame] | 997 | if (!bgx->is_dlm || bgx->is_rgx) { |
Sunil Goutham | 57aaf63 | 2016-08-12 16:51:31 +0530 | [diff] [blame] | 998 | /* Read LMAC0 type to figure out QLM mode |
| 999 | * This is configured by low level firmware |
| 1000 | */ |
| 1001 | cmr_cfg = bgx_reg_read(bgx, 0, BGX_CMRX_CFG); |
| 1002 | lmac->lmac_type = (cmr_cfg >> 8) & 0x07; |
Sunil Goutham | 6465859 | 2016-08-12 16:51:33 +0530 | [diff] [blame] | 1003 | if (bgx->is_rgx) |
| 1004 | lmac->lmac_type = BGX_MODE_RGMII; |
| 1005 | lmac_set_training(bgx, lmac, 0); |
Sunil Goutham | 3f8057c | 2016-08-12 16:51:32 +0530 | [diff] [blame] | 1006 | lmac_set_lane2sds(bgx, lmac); |
Sunil Goutham | 57aaf63 | 2016-08-12 16:51:31 +0530 | [diff] [blame] | 1007 | return; |
| 1008 | } |
| 1009 | |
Sunil Goutham | fff37fd | 2017-01-25 17:36:24 +0530 | [diff] [blame^] | 1010 | /* For DLMs or SLMs on 80/81/83xx so many lane configurations |
| 1011 | * are possible and vary across boards. Also Kernel doesn't have |
| 1012 | * any way to identify board type/info and since firmware does, |
| 1013 | * just take lmac type and serdes lane config as is. |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 1014 | */ |
Sunil Goutham | fff37fd | 2017-01-25 17:36:24 +0530 | [diff] [blame^] | 1015 | cmr_cfg = bgx_reg_read(bgx, idx, BGX_CMRX_CFG); |
| 1016 | lmac_type = (u8)((cmr_cfg >> 8) & 0x07); |
| 1017 | lane_to_sds = (u8)(cmr_cfg & 0xFF); |
| 1018 | /* Check if config is reset value */ |
| 1019 | if ((lmac_type == 0) && (lane_to_sds == 0xE4)) |
| 1020 | lmac->lmac_type = BGX_MODE_INVALID; |
| 1021 | else |
| 1022 | lmac->lmac_type = lmac_type; |
| 1023 | lmac->lane_to_sds = lane_to_sds; |
| 1024 | lmac_set_training(bgx, lmac, lmac->lmacid); |
Sunil Goutham | 0bcb7d5 | 2016-08-12 16:51:30 +0530 | [diff] [blame] | 1025 | } |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 1026 | |
Sunil Goutham | 0bcb7d5 | 2016-08-12 16:51:30 +0530 | [diff] [blame] | 1027 | static void bgx_get_qlm_mode(struct bgx *bgx) |
| 1028 | { |
Sunil Goutham | 57aaf63 | 2016-08-12 16:51:31 +0530 | [diff] [blame] | 1029 | struct lmac *lmac; |
Sunil Goutham | 0bcb7d5 | 2016-08-12 16:51:30 +0530 | [diff] [blame] | 1030 | u8 idx; |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 1031 | |
Sunil Goutham | 57aaf63 | 2016-08-12 16:51:31 +0530 | [diff] [blame] | 1032 | /* Init all LMAC's type to invalid */ |
Sunil Goutham | 6465859 | 2016-08-12 16:51:33 +0530 | [diff] [blame] | 1033 | for (idx = 0; idx < bgx->max_lmac; idx++) { |
Sunil Goutham | 57aaf63 | 2016-08-12 16:51:31 +0530 | [diff] [blame] | 1034 | lmac = &bgx->lmac[idx]; |
Sunil Goutham | 57aaf63 | 2016-08-12 16:51:31 +0530 | [diff] [blame] | 1035 | lmac->lmacid = idx; |
Sunil Goutham | 6465859 | 2016-08-12 16:51:33 +0530 | [diff] [blame] | 1036 | lmac->lmac_type = BGX_MODE_INVALID; |
| 1037 | lmac->use_training = false; |
Sunil Goutham | 57aaf63 | 2016-08-12 16:51:31 +0530 | [diff] [blame] | 1038 | } |
| 1039 | |
Sunil Goutham | 0bcb7d5 | 2016-08-12 16:51:30 +0530 | [diff] [blame] | 1040 | /* It is assumed that low level firmware sets this value */ |
| 1041 | bgx->lmac_count = bgx_reg_read(bgx, 0, BGX_CMR_RX_LMACS) & 0x7; |
Sunil Goutham | 6465859 | 2016-08-12 16:51:33 +0530 | [diff] [blame] | 1042 | if (bgx->lmac_count > bgx->max_lmac) |
| 1043 | bgx->lmac_count = bgx->max_lmac; |
Sunil Goutham | 0bcb7d5 | 2016-08-12 16:51:30 +0530 | [diff] [blame] | 1044 | |
Sunil Goutham | 57aaf63 | 2016-08-12 16:51:31 +0530 | [diff] [blame] | 1045 | for (idx = 0; idx < bgx->lmac_count; idx++) { |
Sunil Goutham | fff37fd | 2017-01-25 17:36:24 +0530 | [diff] [blame^] | 1046 | bgx_set_lmac_config(bgx, idx); |
| 1047 | bgx_print_qlm_mode(bgx, idx); |
Sunil Goutham | 57aaf63 | 2016-08-12 16:51:31 +0530 | [diff] [blame] | 1048 | } |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 1049 | } |
| 1050 | |
David Daney | 46b903a | 2015-08-10 17:58:37 -0700 | [diff] [blame] | 1051 | #ifdef CONFIG_ACPI |
| 1052 | |
Robert Richter | 1d82efa | 2016-02-11 21:50:25 +0530 | [diff] [blame] | 1053 | static int acpi_get_mac_address(struct device *dev, struct acpi_device *adev, |
| 1054 | u8 *dst) |
David Daney | 46b903a | 2015-08-10 17:58:37 -0700 | [diff] [blame] | 1055 | { |
| 1056 | u8 mac[ETH_ALEN]; |
| 1057 | int ret; |
| 1058 | |
| 1059 | ret = fwnode_property_read_u8_array(acpi_fwnode_handle(adev), |
| 1060 | "mac-address", mac, ETH_ALEN); |
| 1061 | if (ret) |
| 1062 | goto out; |
| 1063 | |
| 1064 | if (!is_valid_ether_addr(mac)) { |
Robert Richter | 1d82efa | 2016-02-11 21:50:25 +0530 | [diff] [blame] | 1065 | dev_err(dev, "MAC address invalid: %pM\n", mac); |
David Daney | 46b903a | 2015-08-10 17:58:37 -0700 | [diff] [blame] | 1066 | ret = -EINVAL; |
| 1067 | goto out; |
| 1068 | } |
| 1069 | |
Robert Richter | 1d82efa | 2016-02-11 21:50:25 +0530 | [diff] [blame] | 1070 | dev_info(dev, "MAC address set to: %pM\n", mac); |
| 1071 | |
David Daney | 46b903a | 2015-08-10 17:58:37 -0700 | [diff] [blame] | 1072 | memcpy(dst, mac, ETH_ALEN); |
| 1073 | out: |
| 1074 | return ret; |
| 1075 | } |
| 1076 | |
| 1077 | /* Currently only sets the MAC address. */ |
| 1078 | static acpi_status bgx_acpi_register_phy(acpi_handle handle, |
| 1079 | u32 lvl, void *context, void **rv) |
| 1080 | { |
| 1081 | struct bgx *bgx = context; |
Robert Richter | 1d82efa | 2016-02-11 21:50:25 +0530 | [diff] [blame] | 1082 | struct device *dev = &bgx->pdev->dev; |
David Daney | 46b903a | 2015-08-10 17:58:37 -0700 | [diff] [blame] | 1083 | struct acpi_device *adev; |
| 1084 | |
| 1085 | if (acpi_bus_get_device(handle, &adev)) |
| 1086 | goto out; |
| 1087 | |
Vadim Lomovtsev | 7aa4865 | 2017-01-12 07:28:06 -0800 | [diff] [blame] | 1088 | acpi_get_mac_address(dev, adev, bgx->lmac[bgx->acpi_lmac_idx].mac); |
David Daney | 46b903a | 2015-08-10 17:58:37 -0700 | [diff] [blame] | 1089 | |
Vadim Lomovtsev | 7aa4865 | 2017-01-12 07:28:06 -0800 | [diff] [blame] | 1090 | SET_NETDEV_DEV(&bgx->lmac[bgx->acpi_lmac_idx].netdev, dev); |
David Daney | 46b903a | 2015-08-10 17:58:37 -0700 | [diff] [blame] | 1091 | |
Vadim Lomovtsev | 7aa4865 | 2017-01-12 07:28:06 -0800 | [diff] [blame] | 1092 | bgx->lmac[bgx->acpi_lmac_idx].lmacid = bgx->acpi_lmac_idx; |
| 1093 | bgx->acpi_lmac_idx++; /* move to next LMAC */ |
David Daney | 46b903a | 2015-08-10 17:58:37 -0700 | [diff] [blame] | 1094 | out: |
David Daney | 46b903a | 2015-08-10 17:58:37 -0700 | [diff] [blame] | 1095 | return AE_OK; |
| 1096 | } |
| 1097 | |
| 1098 | static acpi_status bgx_acpi_match_id(acpi_handle handle, u32 lvl, |
| 1099 | void *context, void **ret_val) |
| 1100 | { |
| 1101 | struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 1102 | struct bgx *bgx = context; |
| 1103 | char bgx_sel[5]; |
| 1104 | |
| 1105 | snprintf(bgx_sel, 5, "BGX%d", bgx->bgx_id); |
| 1106 | if (ACPI_FAILURE(acpi_get_name(handle, ACPI_SINGLE_NAME, &string))) { |
| 1107 | pr_warn("Invalid link device\n"); |
| 1108 | return AE_OK; |
| 1109 | } |
| 1110 | |
| 1111 | if (strncmp(string.pointer, bgx_sel, 4)) |
| 1112 | return AE_OK; |
| 1113 | |
| 1114 | acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, 1, |
| 1115 | bgx_acpi_register_phy, NULL, bgx, NULL); |
| 1116 | |
| 1117 | kfree(string.pointer); |
| 1118 | return AE_CTRL_TERMINATE; |
| 1119 | } |
| 1120 | |
| 1121 | static int bgx_init_acpi_phy(struct bgx *bgx) |
| 1122 | { |
| 1123 | acpi_get_devices(NULL, bgx_acpi_match_id, bgx, (void **)NULL); |
| 1124 | return 0; |
| 1125 | } |
| 1126 | |
| 1127 | #else |
| 1128 | |
| 1129 | static int bgx_init_acpi_phy(struct bgx *bgx) |
| 1130 | { |
| 1131 | return -ENODEV; |
| 1132 | } |
| 1133 | |
| 1134 | #endif /* CONFIG_ACPI */ |
| 1135 | |
Robert Richter | de387e1 | 2015-08-10 17:58:36 -0700 | [diff] [blame] | 1136 | #if IS_ENABLED(CONFIG_OF_MDIO) |
| 1137 | |
| 1138 | static int bgx_init_of_phy(struct bgx *bgx) |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 1139 | { |
David Daney | eee326f | 2016-02-11 21:50:24 +0530 | [diff] [blame] | 1140 | struct fwnode_handle *fwn; |
David Daney | b7d3e3d | 2016-03-14 17:30:39 -0700 | [diff] [blame] | 1141 | struct device_node *node = NULL; |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 1142 | u8 lmac = 0; |
Robert Richter | de387e1 | 2015-08-10 17:58:36 -0700 | [diff] [blame] | 1143 | |
David Daney | eee326f | 2016-02-11 21:50:24 +0530 | [diff] [blame] | 1144 | device_for_each_child_node(&bgx->pdev->dev, fwn) { |
David Daney | 5fc7cf1 | 2016-03-11 09:53:09 -0800 | [diff] [blame] | 1145 | struct phy_device *pd; |
David Daney | eee326f | 2016-02-11 21:50:24 +0530 | [diff] [blame] | 1146 | struct device_node *phy_np; |
David Daney | b7d3e3d | 2016-03-14 17:30:39 -0700 | [diff] [blame] | 1147 | const char *mac; |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 1148 | |
David Daney | 5fc7cf1 | 2016-03-11 09:53:09 -0800 | [diff] [blame] | 1149 | /* Should always be an OF node. But if it is not, we |
| 1150 | * cannot handle it, so exit the loop. |
David Daney | eee326f | 2016-02-11 21:50:24 +0530 | [diff] [blame] | 1151 | */ |
David Daney | b7d3e3d | 2016-03-14 17:30:39 -0700 | [diff] [blame] | 1152 | node = to_of_node(fwn); |
David Daney | eee326f | 2016-02-11 21:50:24 +0530 | [diff] [blame] | 1153 | if (!node) |
| 1154 | break; |
| 1155 | |
David Daney | eee326f | 2016-02-11 21:50:24 +0530 | [diff] [blame] | 1156 | mac = of_get_mac_address(node); |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 1157 | if (mac) |
| 1158 | ether_addr_copy(bgx->lmac[lmac].mac, mac); |
| 1159 | |
| 1160 | SET_NETDEV_DEV(&bgx->lmac[lmac].netdev, &bgx->pdev->dev); |
| 1161 | bgx->lmac[lmac].lmacid = lmac; |
David Daney | 5fc7cf1 | 2016-03-11 09:53:09 -0800 | [diff] [blame] | 1162 | |
| 1163 | phy_np = of_parse_phandle(node, "phy-handle", 0); |
| 1164 | /* If there is no phy or defective firmware presents |
| 1165 | * this cortina phy, for which there is no driver |
| 1166 | * support, ignore it. |
| 1167 | */ |
| 1168 | if (phy_np && |
| 1169 | !of_device_is_compatible(phy_np, "cortina,cs4223-slice")) { |
| 1170 | /* Wait until the phy drivers are available */ |
| 1171 | pd = of_phy_find_device(phy_np); |
| 1172 | if (!pd) |
David Daney | b7d3e3d | 2016-03-14 17:30:39 -0700 | [diff] [blame] | 1173 | goto defer; |
David Daney | 5fc7cf1 | 2016-03-11 09:53:09 -0800 | [diff] [blame] | 1174 | bgx->lmac[lmac].phydev = pd; |
| 1175 | } |
| 1176 | |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 1177 | lmac++; |
Sunil Goutham | 6465859 | 2016-08-12 16:51:33 +0530 | [diff] [blame] | 1178 | if (lmac == bgx->max_lmac) { |
David Daney | 65c66af | 2016-04-08 13:37:27 -0700 | [diff] [blame] | 1179 | of_node_put(node); |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 1180 | break; |
David Daney | 65c66af | 2016-04-08 13:37:27 -0700 | [diff] [blame] | 1181 | } |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 1182 | } |
Robert Richter | de387e1 | 2015-08-10 17:58:36 -0700 | [diff] [blame] | 1183 | return 0; |
David Daney | b7d3e3d | 2016-03-14 17:30:39 -0700 | [diff] [blame] | 1184 | |
| 1185 | defer: |
| 1186 | /* We are bailing out, try not to leak device reference counts |
| 1187 | * for phy devices we may have already found. |
| 1188 | */ |
| 1189 | while (lmac) { |
| 1190 | if (bgx->lmac[lmac].phydev) { |
| 1191 | put_device(&bgx->lmac[lmac].phydev->mdio.dev); |
| 1192 | bgx->lmac[lmac].phydev = NULL; |
| 1193 | } |
| 1194 | lmac--; |
| 1195 | } |
| 1196 | of_node_put(node); |
| 1197 | return -EPROBE_DEFER; |
Robert Richter | de387e1 | 2015-08-10 17:58:36 -0700 | [diff] [blame] | 1198 | } |
| 1199 | |
| 1200 | #else |
| 1201 | |
| 1202 | static int bgx_init_of_phy(struct bgx *bgx) |
| 1203 | { |
| 1204 | return -ENODEV; |
| 1205 | } |
| 1206 | |
| 1207 | #endif /* CONFIG_OF_MDIO */ |
| 1208 | |
| 1209 | static int bgx_init_phy(struct bgx *bgx) |
| 1210 | { |
David Daney | 46b903a | 2015-08-10 17:58:37 -0700 | [diff] [blame] | 1211 | if (!acpi_disabled) |
| 1212 | return bgx_init_acpi_phy(bgx); |
| 1213 | |
Robert Richter | de387e1 | 2015-08-10 17:58:36 -0700 | [diff] [blame] | 1214 | return bgx_init_of_phy(bgx); |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 1215 | } |
| 1216 | |
| 1217 | static int bgx_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 1218 | { |
| 1219 | int err; |
| 1220 | struct device *dev = &pdev->dev; |
| 1221 | struct bgx *bgx = NULL; |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 1222 | u8 lmac; |
Sunil Goutham | 57aaf63 | 2016-08-12 16:51:31 +0530 | [diff] [blame] | 1223 | u16 sdevid; |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 1224 | |
| 1225 | bgx = devm_kzalloc(dev, sizeof(*bgx), GFP_KERNEL); |
| 1226 | if (!bgx) |
| 1227 | return -ENOMEM; |
| 1228 | bgx->pdev = pdev; |
| 1229 | |
| 1230 | pci_set_drvdata(pdev, bgx); |
| 1231 | |
| 1232 | err = pci_enable_device(pdev); |
| 1233 | if (err) { |
| 1234 | dev_err(dev, "Failed to enable PCI device\n"); |
| 1235 | pci_set_drvdata(pdev, NULL); |
| 1236 | return err; |
| 1237 | } |
| 1238 | |
| 1239 | err = pci_request_regions(pdev, DRV_NAME); |
| 1240 | if (err) { |
| 1241 | dev_err(dev, "PCI request regions failed 0x%x\n", err); |
| 1242 | goto err_disable_device; |
| 1243 | } |
| 1244 | |
| 1245 | /* MAP configuration registers */ |
| 1246 | bgx->reg_base = pcim_iomap(pdev, PCI_CFG_REG_BAR_NUM, 0); |
| 1247 | if (!bgx->reg_base) { |
| 1248 | dev_err(dev, "BGX: Cannot map CSR memory space, aborting\n"); |
| 1249 | err = -ENOMEM; |
| 1250 | goto err_release_regions; |
| 1251 | } |
Robert Richter | d768b67 | 2015-06-02 11:00:18 -0700 | [diff] [blame] | 1252 | |
Sunil Goutham | 6465859 | 2016-08-12 16:51:33 +0530 | [diff] [blame] | 1253 | pci_read_config_word(pdev, PCI_DEVICE_ID, &sdevid); |
| 1254 | if (sdevid != PCI_DEVICE_ID_THUNDER_RGX) { |
Radha Mohan Chintakuntla | 612e94b | 2016-11-15 17:37:16 +0530 | [diff] [blame] | 1255 | bgx->bgx_id = (pci_resource_start(pdev, |
| 1256 | PCI_CFG_REG_BAR_NUM) >> 24) & BGX_ID_MASK; |
Sunil Goutham | 09de391 | 2016-08-12 16:51:35 +0530 | [diff] [blame] | 1257 | bgx->bgx_id += nic_get_node_id(pdev) * MAX_BGX_PER_NODE; |
Sunil Goutham | 6465859 | 2016-08-12 16:51:33 +0530 | [diff] [blame] | 1258 | bgx->max_lmac = MAX_LMAC_PER_BGX; |
| 1259 | bgx_vnic[bgx->bgx_id] = bgx; |
| 1260 | } else { |
| 1261 | bgx->is_rgx = true; |
| 1262 | bgx->max_lmac = 1; |
| 1263 | bgx->bgx_id = MAX_BGX_PER_CN81XX - 1; |
| 1264 | bgx_vnic[bgx->bgx_id] = bgx; |
| 1265 | xcv_init_hw(); |
| 1266 | } |
| 1267 | |
Sunil Goutham | 09de391 | 2016-08-12 16:51:35 +0530 | [diff] [blame] | 1268 | /* On 81xx all are DLMs and on 83xx there are 3 BGX QLMs and one |
| 1269 | * BGX i.e BGX2 can be split across 2 DLMs. |
| 1270 | */ |
| 1271 | pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &sdevid); |
| 1272 | if ((sdevid == PCI_SUBSYS_DEVID_81XX_BGX) || |
| 1273 | ((sdevid == PCI_SUBSYS_DEVID_83XX_BGX) && (bgx->bgx_id == 2))) |
| 1274 | bgx->is_dlm = true; |
| 1275 | |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 1276 | bgx_get_qlm_mode(bgx); |
| 1277 | |
Robert Richter | de387e1 | 2015-08-10 17:58:36 -0700 | [diff] [blame] | 1278 | err = bgx_init_phy(bgx); |
| 1279 | if (err) |
| 1280 | goto err_enable; |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 1281 | |
| 1282 | bgx_init_hw(bgx); |
| 1283 | |
| 1284 | /* Enable all LMACs */ |
| 1285 | for (lmac = 0; lmac < bgx->lmac_count; lmac++) { |
| 1286 | err = bgx_lmac_enable(bgx, lmac); |
| 1287 | if (err) { |
| 1288 | dev_err(dev, "BGX%d failed to enable lmac%d\n", |
| 1289 | bgx->bgx_id, lmac); |
Sunil Goutham | 57aaf63 | 2016-08-12 16:51:31 +0530 | [diff] [blame] | 1290 | while (lmac) |
| 1291 | bgx_lmac_disable(bgx, --lmac); |
Sunil Goutham | 4863dea | 2015-05-26 19:20:15 -0700 | [diff] [blame] | 1292 | goto err_enable; |
| 1293 | } |
| 1294 | } |
| 1295 | |
| 1296 | return 0; |
| 1297 | |
| 1298 | err_enable: |
| 1299 | bgx_vnic[bgx->bgx_id] = NULL; |
| 1300 | err_release_regions: |
| 1301 | pci_release_regions(pdev); |
| 1302 | err_disable_device: |
| 1303 | pci_disable_device(pdev); |
| 1304 | pci_set_drvdata(pdev, NULL); |
| 1305 | return err; |
| 1306 | } |
| 1307 | |
| 1308 | static void bgx_remove(struct pci_dev *pdev) |
| 1309 | { |
| 1310 | struct bgx *bgx = pci_get_drvdata(pdev); |
| 1311 | u8 lmac; |
| 1312 | |
| 1313 | /* Disable all LMACs */ |
| 1314 | for (lmac = 0; lmac < bgx->lmac_count; lmac++) |
| 1315 | bgx_lmac_disable(bgx, lmac); |
| 1316 | |
| 1317 | bgx_vnic[bgx->bgx_id] = NULL; |
| 1318 | pci_release_regions(pdev); |
| 1319 | pci_disable_device(pdev); |
| 1320 | pci_set_drvdata(pdev, NULL); |
| 1321 | } |
| 1322 | |
| 1323 | static struct pci_driver bgx_driver = { |
| 1324 | .name = DRV_NAME, |
| 1325 | .id_table = bgx_id_table, |
| 1326 | .probe = bgx_probe, |
| 1327 | .remove = bgx_remove, |
| 1328 | }; |
| 1329 | |
| 1330 | static int __init bgx_init_module(void) |
| 1331 | { |
| 1332 | pr_info("%s, ver %s\n", DRV_NAME, DRV_VERSION); |
| 1333 | |
| 1334 | return pci_register_driver(&bgx_driver); |
| 1335 | } |
| 1336 | |
| 1337 | static void __exit bgx_cleanup_module(void) |
| 1338 | { |
| 1339 | pci_unregister_driver(&bgx_driver); |
| 1340 | } |
| 1341 | |
| 1342 | module_init(bgx_init_module); |
| 1343 | module_exit(bgx_cleanup_module); |