Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright(c) 2015 EZchip Technologies. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms and conditions of the GNU General Public License, |
| 6 | * version 2, as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 11 | * more details. |
| 12 | * |
| 13 | * The full GNU General Public License is included in this distribution in |
| 14 | * the file called "COPYING". |
| 15 | */ |
| 16 | |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/etherdevice.h> |
| 19 | #include <linux/of_address.h> |
| 20 | #include <linux/of_irq.h> |
| 21 | #include <linux/of_net.h> |
| 22 | #include <linux/of_platform.h> |
| 23 | #include "nps_enet.h" |
| 24 | |
| 25 | #define DRV_NAME "nps_mgt_enet" |
| 26 | |
Elad Kanfi | 094f57a | 2016-07-13 16:58:07 +0300 | [diff] [blame^] | 27 | static inline bool nps_enet_is_tx_pending(struct nps_enet_priv *priv) |
| 28 | { |
| 29 | u32 tx_ctrl_value = nps_enet_reg_get(priv, NPS_ENET_REG_TX_CTL); |
| 30 | u32 tx_ctrl_ct = (tx_ctrl_value & TX_CTL_CT_MASK) >> TX_CTL_CT_SHIFT; |
| 31 | |
| 32 | return (!tx_ctrl_ct && priv->tx_skb); |
| 33 | } |
| 34 | |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 35 | static void nps_enet_clean_rx_fifo(struct net_device *ndev, u32 frame_len) |
| 36 | { |
| 37 | struct nps_enet_priv *priv = netdev_priv(ndev); |
| 38 | u32 i, len = DIV_ROUND_UP(frame_len, sizeof(u32)); |
| 39 | |
| 40 | /* Empty Rx FIFO buffer by reading all words */ |
| 41 | for (i = 0; i < len; i++) |
| 42 | nps_enet_reg_get(priv, NPS_ENET_REG_RX_BUF); |
| 43 | } |
| 44 | |
| 45 | static void nps_enet_read_rx_fifo(struct net_device *ndev, |
| 46 | unsigned char *dst, u32 length) |
| 47 | { |
| 48 | struct nps_enet_priv *priv = netdev_priv(ndev); |
| 49 | s32 i, last = length & (sizeof(u32) - 1); |
| 50 | u32 *reg = (u32 *)dst, len = length / sizeof(u32); |
| 51 | bool dst_is_aligned = IS_ALIGNED((unsigned long)dst, sizeof(u32)); |
| 52 | |
| 53 | /* In case dst is not aligned we need an intermediate buffer */ |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 54 | if (dst_is_aligned) { |
| 55 | ioread32_rep(priv->regs_base + NPS_ENET_REG_RX_BUF, reg, len); |
| 56 | reg += len; |
Elad Kanfi | ddbff3e | 2016-07-13 16:58:06 +0300 | [diff] [blame] | 57 | } else { /* !dst_is_aligned */ |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 58 | for (i = 0; i < len; i++, reg++) { |
Arnd Bergmann | b0a8d1a | 2015-12-08 16:28:59 +0100 | [diff] [blame] | 59 | u32 buf = nps_enet_reg_get(priv, NPS_ENET_REG_RX_BUF); |
Elad Kanfi | ddbff3e | 2016-07-13 16:58:06 +0300 | [diff] [blame] | 60 | |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 61 | put_unaligned_be32(buf, reg); |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 62 | } |
| 63 | } |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 64 | /* copy last bytes (if any) */ |
| 65 | if (last) { |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 66 | u32 buf; |
Elad Kanfi | ddbff3e | 2016-07-13 16:58:06 +0300 | [diff] [blame] | 67 | |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 68 | ioread32_rep(priv->regs_base + NPS_ENET_REG_RX_BUF, &buf, 1); |
| 69 | memcpy((u8 *)reg, &buf, last); |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 70 | } |
| 71 | } |
| 72 | |
| 73 | static u32 nps_enet_rx_handler(struct net_device *ndev) |
| 74 | { |
| 75 | u32 frame_len, err = 0; |
| 76 | u32 work_done = 0; |
| 77 | struct nps_enet_priv *priv = netdev_priv(ndev); |
| 78 | struct sk_buff *skb; |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 79 | u32 rx_ctrl_value = nps_enet_reg_get(priv, NPS_ENET_REG_RX_CTL); |
| 80 | u32 rx_ctrl_cr = (rx_ctrl_value & RX_CTL_CR_MASK) >> RX_CTL_CR_SHIFT; |
| 81 | u32 rx_ctrl_er = (rx_ctrl_value & RX_CTL_ER_MASK) >> RX_CTL_ER_SHIFT; |
| 82 | u32 rx_ctrl_crc = (rx_ctrl_value & RX_CTL_CRC_MASK) >> RX_CTL_CRC_SHIFT; |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 83 | |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 84 | frame_len = (rx_ctrl_value & RX_CTL_NR_MASK) >> RX_CTL_NR_SHIFT; |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 85 | |
| 86 | /* Check if we got RX */ |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 87 | if (!rx_ctrl_cr) |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 88 | return work_done; |
| 89 | |
| 90 | /* If we got here there is a work for us */ |
| 91 | work_done++; |
| 92 | |
| 93 | /* Check Rx error */ |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 94 | if (rx_ctrl_er) { |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 95 | ndev->stats.rx_errors++; |
| 96 | err = 1; |
| 97 | } |
| 98 | |
| 99 | /* Check Rx CRC error */ |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 100 | if (rx_ctrl_crc) { |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 101 | ndev->stats.rx_crc_errors++; |
| 102 | ndev->stats.rx_dropped++; |
| 103 | err = 1; |
| 104 | } |
| 105 | |
| 106 | /* Check Frame length Min 64b */ |
| 107 | if (unlikely(frame_len < ETH_ZLEN)) { |
| 108 | ndev->stats.rx_length_errors++; |
| 109 | ndev->stats.rx_dropped++; |
| 110 | err = 1; |
| 111 | } |
| 112 | |
| 113 | if (err) |
| 114 | goto rx_irq_clean; |
| 115 | |
| 116 | /* Skb allocation */ |
| 117 | skb = netdev_alloc_skb_ip_align(ndev, frame_len); |
| 118 | if (unlikely(!skb)) { |
| 119 | ndev->stats.rx_errors++; |
| 120 | ndev->stats.rx_dropped++; |
| 121 | goto rx_irq_clean; |
| 122 | } |
| 123 | |
| 124 | /* Copy frame from Rx fifo into the skb */ |
| 125 | nps_enet_read_rx_fifo(ndev, skb->data, frame_len); |
| 126 | |
| 127 | skb_put(skb, frame_len); |
| 128 | skb->protocol = eth_type_trans(skb, ndev); |
| 129 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 130 | |
| 131 | ndev->stats.rx_packets++; |
| 132 | ndev->stats.rx_bytes += frame_len; |
| 133 | netif_receive_skb(skb); |
| 134 | |
| 135 | goto rx_irq_frame_done; |
| 136 | |
| 137 | rx_irq_clean: |
| 138 | /* Clean Rx fifo */ |
| 139 | nps_enet_clean_rx_fifo(ndev, frame_len); |
| 140 | |
| 141 | rx_irq_frame_done: |
| 142 | /* Ack Rx ctrl register */ |
| 143 | nps_enet_reg_set(priv, NPS_ENET_REG_RX_CTL, 0); |
| 144 | |
| 145 | return work_done; |
| 146 | } |
| 147 | |
| 148 | static void nps_enet_tx_handler(struct net_device *ndev) |
| 149 | { |
| 150 | struct nps_enet_priv *priv = netdev_priv(ndev); |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 151 | u32 tx_ctrl_value = nps_enet_reg_get(priv, NPS_ENET_REG_TX_CTL); |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 152 | u32 tx_ctrl_et = (tx_ctrl_value & TX_CTL_ET_MASK) >> TX_CTL_ET_SHIFT; |
| 153 | u32 tx_ctrl_nt = (tx_ctrl_value & TX_CTL_NT_MASK) >> TX_CTL_NT_SHIFT; |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 154 | |
| 155 | /* Check if we got TX */ |
Elad Kanfi | 094f57a | 2016-07-13 16:58:07 +0300 | [diff] [blame^] | 156 | if (!nps_enet_is_tx_pending(priv)) |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 157 | return; |
| 158 | |
Noam Camus | 3d99b74 | 2015-08-20 08:00:04 +0300 | [diff] [blame] | 159 | /* Ack Tx ctrl register */ |
| 160 | nps_enet_reg_set(priv, NPS_ENET_REG_TX_CTL, 0); |
| 161 | |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 162 | /* Check Tx transmit error */ |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 163 | if (unlikely(tx_ctrl_et)) { |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 164 | ndev->stats.tx_errors++; |
| 165 | } else { |
| 166 | ndev->stats.tx_packets++; |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 167 | ndev->stats.tx_bytes += tx_ctrl_nt; |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 168 | } |
| 169 | |
Noam Camus | 93fcf83 | 2015-08-20 08:00:02 +0300 | [diff] [blame] | 170 | dev_kfree_skb(priv->tx_skb); |
Elad Kanfi | e5df49d | 2016-05-09 20:13:19 +0300 | [diff] [blame] | 171 | priv->tx_skb = NULL; |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 172 | |
| 173 | if (netif_queue_stopped(ndev)) |
| 174 | netif_wake_queue(ndev); |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * nps_enet_poll - NAPI poll handler. |
| 179 | * @napi: Pointer to napi_struct structure. |
| 180 | * @budget: How many frames to process on one call. |
| 181 | * |
| 182 | * returns: Number of processed frames |
| 183 | */ |
| 184 | static int nps_enet_poll(struct napi_struct *napi, int budget) |
| 185 | { |
| 186 | struct net_device *ndev = napi->dev; |
| 187 | struct nps_enet_priv *priv = netdev_priv(ndev); |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 188 | u32 work_done; |
| 189 | |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 190 | nps_enet_tx_handler(ndev); |
| 191 | work_done = nps_enet_rx_handler(ndev); |
| 192 | if (work_done < budget) { |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 193 | u32 buf_int_enable_value = 0; |
Noam Camus | 4149379 | 2015-08-20 08:00:05 +0300 | [diff] [blame] | 194 | |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 195 | napi_complete(napi); |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 196 | |
| 197 | /* set tx_done and rx_rdy bits */ |
| 198 | buf_int_enable_value |= NPS_ENET_ENABLE << RX_RDY_SHIFT; |
| 199 | buf_int_enable_value |= NPS_ENET_ENABLE << TX_DONE_SHIFT; |
| 200 | |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 201 | nps_enet_reg_set(priv, NPS_ENET_REG_BUF_INT_ENABLE, |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 202 | buf_int_enable_value); |
Elad Kanfi | 05c00d8 | 2016-05-09 20:13:20 +0300 | [diff] [blame] | 203 | |
| 204 | /* in case we will get a tx interrupt while interrupts |
| 205 | * are masked, we will lose it since the tx is edge interrupt. |
| 206 | * specifically, while executing the code section above, |
| 207 | * between nps_enet_tx_handler and the interrupts enable, all |
| 208 | * tx requests will be stuck until we will get an rx interrupt. |
| 209 | * the two code lines below will solve this situation by |
| 210 | * re-adding ourselves to the poll list. |
| 211 | */ |
Elad Kanfi | 094f57a | 2016-07-13 16:58:07 +0300 | [diff] [blame^] | 212 | if (nps_enet_is_tx_pending(priv)) { |
Elad Kanfi | 8665165 | 2016-05-26 15:00:06 +0300 | [diff] [blame] | 213 | nps_enet_reg_set(priv, NPS_ENET_REG_BUF_INT_ENABLE, 0); |
Elad Kanfi | 05c00d8 | 2016-05-09 20:13:20 +0300 | [diff] [blame] | 214 | napi_reschedule(napi); |
Elad Kanfi | 8665165 | 2016-05-26 15:00:06 +0300 | [diff] [blame] | 215 | } |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | return work_done; |
| 219 | } |
| 220 | |
| 221 | /** |
| 222 | * nps_enet_irq_handler - Global interrupt handler for ENET. |
| 223 | * @irq: irq number. |
| 224 | * @dev_instance: device instance. |
| 225 | * |
| 226 | * returns: IRQ_HANDLED for all cases. |
| 227 | * |
| 228 | * EZchip ENET has 2 interrupt causes, and depending on bits raised in |
| 229 | * CTRL registers we may tell what is a reason for interrupt to fire up. |
| 230 | * We got one for RX and the other for TX (completion). |
| 231 | */ |
| 232 | static irqreturn_t nps_enet_irq_handler(s32 irq, void *dev_instance) |
| 233 | { |
| 234 | struct net_device *ndev = dev_instance; |
| 235 | struct nps_enet_priv *priv = netdev_priv(ndev); |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 236 | u32 rx_ctrl_value = nps_enet_reg_get(priv, NPS_ENET_REG_RX_CTL); |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 237 | u32 rx_ctrl_cr = (rx_ctrl_value & RX_CTL_CR_MASK) >> RX_CTL_CR_SHIFT; |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 238 | |
Elad Kanfi | 094f57a | 2016-07-13 16:58:07 +0300 | [diff] [blame^] | 239 | if (nps_enet_is_tx_pending(priv) || rx_ctrl_cr) |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 240 | if (likely(napi_schedule_prep(&priv->napi))) { |
| 241 | nps_enet_reg_set(priv, NPS_ENET_REG_BUF_INT_ENABLE, 0); |
| 242 | __napi_schedule(&priv->napi); |
| 243 | } |
| 244 | |
| 245 | return IRQ_HANDLED; |
| 246 | } |
| 247 | |
| 248 | static void nps_enet_set_hw_mac_address(struct net_device *ndev) |
| 249 | { |
| 250 | struct nps_enet_priv *priv = netdev_priv(ndev); |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 251 | u32 ge_mac_cfg_1_value = 0; |
| 252 | u32 *ge_mac_cfg_2_value = &priv->ge_mac_cfg_2_value; |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 253 | |
| 254 | /* set MAC address in HW */ |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 255 | ge_mac_cfg_1_value |= ndev->dev_addr[0] << CFG_1_OCTET_0_SHIFT; |
| 256 | ge_mac_cfg_1_value |= ndev->dev_addr[1] << CFG_1_OCTET_1_SHIFT; |
| 257 | ge_mac_cfg_1_value |= ndev->dev_addr[2] << CFG_1_OCTET_2_SHIFT; |
| 258 | ge_mac_cfg_1_value |= ndev->dev_addr[3] << CFG_1_OCTET_3_SHIFT; |
| 259 | *ge_mac_cfg_2_value = (*ge_mac_cfg_2_value & ~CFG_2_OCTET_4_MASK) |
| 260 | | ndev->dev_addr[4] << CFG_2_OCTET_4_SHIFT; |
| 261 | *ge_mac_cfg_2_value = (*ge_mac_cfg_2_value & ~CFG_2_OCTET_5_MASK) |
| 262 | | ndev->dev_addr[5] << CFG_2_OCTET_5_SHIFT; |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 263 | |
| 264 | nps_enet_reg_set(priv, NPS_ENET_REG_GE_MAC_CFG_1, |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 265 | ge_mac_cfg_1_value); |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 266 | |
| 267 | nps_enet_reg_set(priv, NPS_ENET_REG_GE_MAC_CFG_2, |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 268 | *ge_mac_cfg_2_value); |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | /** |
| 272 | * nps_enet_hw_reset - Reset the network device. |
| 273 | * @ndev: Pointer to the network device. |
| 274 | * |
| 275 | * This function reset the PCS and TX fifo. |
| 276 | * The programming model is to set the relevant reset bits |
| 277 | * wait for some time for this to propagate and then unset |
| 278 | * the reset bits. This way we ensure that reset procedure |
| 279 | * is done successfully by device. |
| 280 | */ |
| 281 | static void nps_enet_hw_reset(struct net_device *ndev) |
| 282 | { |
| 283 | struct nps_enet_priv *priv = netdev_priv(ndev); |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 284 | u32 ge_rst_value = 0, phase_fifo_ctl_value = 0; |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 285 | |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 286 | /* Pcs reset sequence*/ |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 287 | ge_rst_value |= NPS_ENET_ENABLE << RST_GMAC_0_SHIFT; |
| 288 | nps_enet_reg_set(priv, NPS_ENET_REG_GE_RST, ge_rst_value); |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 289 | usleep_range(10, 20); |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 290 | nps_enet_reg_set(priv, NPS_ENET_REG_GE_RST, ge_rst_value); |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 291 | |
| 292 | /* Tx fifo reset sequence */ |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 293 | phase_fifo_ctl_value |= NPS_ENET_ENABLE << PHASE_FIFO_CTL_RST_SHIFT; |
| 294 | phase_fifo_ctl_value |= NPS_ENET_ENABLE << PHASE_FIFO_CTL_INIT_SHIFT; |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 295 | nps_enet_reg_set(priv, NPS_ENET_REG_PHASE_FIFO_CTL, |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 296 | phase_fifo_ctl_value); |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 297 | usleep_range(10, 20); |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 298 | phase_fifo_ctl_value = 0; |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 299 | nps_enet_reg_set(priv, NPS_ENET_REG_PHASE_FIFO_CTL, |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 300 | phase_fifo_ctl_value); |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | static void nps_enet_hw_enable_control(struct net_device *ndev) |
| 304 | { |
| 305 | struct nps_enet_priv *priv = netdev_priv(ndev); |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 306 | u32 ge_mac_cfg_0_value = 0, buf_int_enable_value = 0; |
| 307 | u32 *ge_mac_cfg_2_value = &priv->ge_mac_cfg_2_value; |
| 308 | u32 *ge_mac_cfg_3_value = &priv->ge_mac_cfg_3_value; |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 309 | s32 max_frame_length; |
| 310 | |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 311 | /* Enable Rx and Tx statistics */ |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 312 | *ge_mac_cfg_2_value = (*ge_mac_cfg_2_value & ~CFG_2_STAT_EN_MASK) |
| 313 | | NPS_ENET_GE_MAC_CFG_2_STAT_EN << CFG_2_STAT_EN_SHIFT; |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 314 | |
| 315 | /* Discard packets with different MAC address */ |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 316 | *ge_mac_cfg_2_value = (*ge_mac_cfg_2_value & ~CFG_2_DISK_DA_MASK) |
| 317 | | NPS_ENET_ENABLE << CFG_2_DISK_DA_SHIFT; |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 318 | |
| 319 | /* Discard multicast packets */ |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 320 | *ge_mac_cfg_2_value = (*ge_mac_cfg_2_value & ~CFG_2_DISK_MC_MASK) |
| 321 | | NPS_ENET_ENABLE << CFG_2_DISK_MC_SHIFT; |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 322 | |
| 323 | nps_enet_reg_set(priv, NPS_ENET_REG_GE_MAC_CFG_2, |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 324 | *ge_mac_cfg_2_value); |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 325 | |
| 326 | /* Discard Packets bigger than max frame length */ |
| 327 | max_frame_length = ETH_HLEN + ndev->mtu + ETH_FCS_LEN; |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 328 | if (max_frame_length <= NPS_ENET_MAX_FRAME_LENGTH) { |
| 329 | *ge_mac_cfg_3_value = |
| 330 | (*ge_mac_cfg_3_value & ~CFG_3_MAX_LEN_MASK) |
| 331 | | max_frame_length << CFG_3_MAX_LEN_SHIFT; |
| 332 | } |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 333 | |
| 334 | /* Enable interrupts */ |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 335 | buf_int_enable_value |= NPS_ENET_ENABLE << RX_RDY_SHIFT; |
| 336 | buf_int_enable_value |= NPS_ENET_ENABLE << TX_DONE_SHIFT; |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 337 | nps_enet_reg_set(priv, NPS_ENET_REG_BUF_INT_ENABLE, |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 338 | buf_int_enable_value); |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 339 | |
| 340 | /* Write device MAC address to HW */ |
| 341 | nps_enet_set_hw_mac_address(ndev); |
| 342 | |
| 343 | /* Rx and Tx HW features */ |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 344 | ge_mac_cfg_0_value |= NPS_ENET_ENABLE << CFG_0_TX_PAD_EN_SHIFT; |
| 345 | ge_mac_cfg_0_value |= NPS_ENET_ENABLE << CFG_0_TX_CRC_EN_SHIFT; |
| 346 | ge_mac_cfg_0_value |= NPS_ENET_ENABLE << CFG_0_RX_CRC_STRIP_SHIFT; |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 347 | |
| 348 | /* IFG configuration */ |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 349 | ge_mac_cfg_0_value |= |
| 350 | NPS_ENET_GE_MAC_CFG_0_RX_IFG << CFG_0_RX_IFG_SHIFT; |
| 351 | ge_mac_cfg_0_value |= |
| 352 | NPS_ENET_GE_MAC_CFG_0_TX_IFG << CFG_0_TX_IFG_SHIFT; |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 353 | |
| 354 | /* preamble configuration */ |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 355 | ge_mac_cfg_0_value |= NPS_ENET_ENABLE << CFG_0_RX_PR_CHECK_EN_SHIFT; |
| 356 | ge_mac_cfg_0_value |= |
| 357 | NPS_ENET_GE_MAC_CFG_0_TX_PR_LEN << CFG_0_TX_PR_LEN_SHIFT; |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 358 | |
| 359 | /* enable flow control frames */ |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 360 | ge_mac_cfg_0_value |= NPS_ENET_ENABLE << CFG_0_TX_FC_EN_SHIFT; |
| 361 | ge_mac_cfg_0_value |= NPS_ENET_ENABLE << CFG_0_RX_FC_EN_SHIFT; |
| 362 | ge_mac_cfg_0_value |= |
| 363 | NPS_ENET_GE_MAC_CFG_0_TX_FC_RETR << CFG_0_TX_FC_RETR_SHIFT; |
| 364 | *ge_mac_cfg_3_value = (*ge_mac_cfg_3_value & ~CFG_3_CF_DROP_MASK) |
| 365 | | NPS_ENET_ENABLE << CFG_3_CF_DROP_SHIFT; |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 366 | |
| 367 | /* Enable Rx and Tx */ |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 368 | ge_mac_cfg_0_value |= NPS_ENET_ENABLE << CFG_0_RX_EN_SHIFT; |
| 369 | ge_mac_cfg_0_value |= NPS_ENET_ENABLE << CFG_0_TX_EN_SHIFT; |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 370 | |
Noam Camus | de67156 | 2015-08-20 08:00:03 +0300 | [diff] [blame] | 371 | nps_enet_reg_set(priv, NPS_ENET_REG_GE_MAC_CFG_3, |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 372 | *ge_mac_cfg_3_value); |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 373 | nps_enet_reg_set(priv, NPS_ENET_REG_GE_MAC_CFG_0, |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 374 | ge_mac_cfg_0_value); |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | static void nps_enet_hw_disable_control(struct net_device *ndev) |
| 378 | { |
| 379 | struct nps_enet_priv *priv = netdev_priv(ndev); |
| 380 | |
| 381 | /* Disable interrupts */ |
| 382 | nps_enet_reg_set(priv, NPS_ENET_REG_BUF_INT_ENABLE, 0); |
| 383 | |
| 384 | /* Disable Rx and Tx */ |
| 385 | nps_enet_reg_set(priv, NPS_ENET_REG_GE_MAC_CFG_0, 0); |
| 386 | } |
| 387 | |
| 388 | static void nps_enet_send_frame(struct net_device *ndev, |
| 389 | struct sk_buff *skb) |
| 390 | { |
| 391 | struct nps_enet_priv *priv = netdev_priv(ndev); |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 392 | u32 tx_ctrl_value = 0; |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 393 | short length = skb->len; |
| 394 | u32 i, len = DIV_ROUND_UP(length, sizeof(u32)); |
Arnd Bergmann | b0a8d1a | 2015-12-08 16:28:59 +0100 | [diff] [blame] | 395 | u32 *src = (void *)skb->data; |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 396 | bool src_is_aligned = IS_ALIGNED((unsigned long)src, sizeof(u32)); |
| 397 | |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 398 | /* In case src is not aligned we need an intermediate buffer */ |
| 399 | if (src_is_aligned) |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 400 | iowrite32_rep(priv->regs_base + NPS_ENET_REG_TX_BUF, src, len); |
Arnd Bergmann | b0a8d1a | 2015-12-08 16:28:59 +0100 | [diff] [blame] | 401 | else /* !src_is_aligned */ |
| 402 | for (i = 0; i < len; i++, src++) |
| 403 | nps_enet_reg_set(priv, NPS_ENET_REG_TX_BUF, |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 404 | get_unaligned_be32(src)); |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 405 | |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 406 | /* Write the length of the Frame */ |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 407 | tx_ctrl_value |= length << TX_CTL_NT_SHIFT; |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 408 | |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 409 | tx_ctrl_value |= NPS_ENET_ENABLE << TX_CTL_CT_SHIFT; |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 410 | /* Send Frame */ |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 411 | nps_enet_reg_set(priv, NPS_ENET_REG_TX_CTL, tx_ctrl_value); |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | /** |
| 415 | * nps_enet_set_mac_address - Set the MAC address for this device. |
| 416 | * @ndev: Pointer to net_device structure. |
| 417 | * @p: 6 byte Address to be written as MAC address. |
| 418 | * |
| 419 | * This function copies the HW address from the sockaddr structure to the |
| 420 | * net_device structure and updates the address in HW. |
| 421 | * |
| 422 | * returns: -EBUSY if the net device is busy or 0 if the address is set |
| 423 | * successfully. |
| 424 | */ |
| 425 | static s32 nps_enet_set_mac_address(struct net_device *ndev, void *p) |
| 426 | { |
| 427 | struct sockaddr *addr = p; |
| 428 | s32 res; |
| 429 | |
| 430 | if (netif_running(ndev)) |
| 431 | return -EBUSY; |
| 432 | |
| 433 | res = eth_mac_addr(ndev, p); |
| 434 | if (!res) { |
| 435 | ether_addr_copy(ndev->dev_addr, addr->sa_data); |
| 436 | nps_enet_set_hw_mac_address(ndev); |
| 437 | } |
| 438 | |
| 439 | return res; |
| 440 | } |
| 441 | |
| 442 | /** |
| 443 | * nps_enet_set_rx_mode - Change the receive filtering mode. |
| 444 | * @ndev: Pointer to the network device. |
| 445 | * |
| 446 | * This function enables/disables promiscuous mode |
| 447 | */ |
| 448 | static void nps_enet_set_rx_mode(struct net_device *ndev) |
| 449 | { |
| 450 | struct nps_enet_priv *priv = netdev_priv(ndev); |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 451 | u32 ge_mac_cfg_2_value = priv->ge_mac_cfg_2_value; |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 452 | |
| 453 | if (ndev->flags & IFF_PROMISC) { |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 454 | ge_mac_cfg_2_value = (ge_mac_cfg_2_value & ~CFG_2_DISK_DA_MASK) |
| 455 | | NPS_ENET_DISABLE << CFG_2_DISK_DA_SHIFT; |
| 456 | ge_mac_cfg_2_value = (ge_mac_cfg_2_value & ~CFG_2_DISK_MC_MASK) |
| 457 | | NPS_ENET_DISABLE << CFG_2_DISK_MC_SHIFT; |
| 458 | |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 459 | } else { |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 460 | ge_mac_cfg_2_value = (ge_mac_cfg_2_value & ~CFG_2_DISK_DA_MASK) |
| 461 | | NPS_ENET_ENABLE << CFG_2_DISK_DA_SHIFT; |
| 462 | ge_mac_cfg_2_value = (ge_mac_cfg_2_value & ~CFG_2_DISK_MC_MASK) |
| 463 | | NPS_ENET_ENABLE << CFG_2_DISK_MC_SHIFT; |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 464 | } |
| 465 | |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 466 | nps_enet_reg_set(priv, NPS_ENET_REG_GE_MAC_CFG_2, ge_mac_cfg_2_value); |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | /** |
| 470 | * nps_enet_open - Open the network device. |
| 471 | * @ndev: Pointer to the network device. |
| 472 | * |
| 473 | * returns: 0, on success or non-zero error value on failure. |
| 474 | * |
| 475 | * This function sets the MAC address, requests and enables an IRQ |
| 476 | * for the ENET device and starts the Tx queue. |
| 477 | */ |
| 478 | static s32 nps_enet_open(struct net_device *ndev) |
| 479 | { |
| 480 | struct nps_enet_priv *priv = netdev_priv(ndev); |
| 481 | s32 err; |
| 482 | |
| 483 | /* Reset private variables */ |
Elad Kanfi | e5df49d | 2016-05-09 20:13:19 +0300 | [diff] [blame] | 484 | priv->tx_skb = NULL; |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 485 | priv->ge_mac_cfg_2_value = 0; |
| 486 | priv->ge_mac_cfg_3_value = 0; |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 487 | |
| 488 | /* ge_mac_cfg_3 default values */ |
Lada Trimasova | b54b8c2 | 2016-03-03 17:07:46 +0300 | [diff] [blame] | 489 | priv->ge_mac_cfg_3_value |= |
| 490 | NPS_ENET_GE_MAC_CFG_3_RX_IFG_TH << CFG_3_RX_IFG_TH_SHIFT; |
| 491 | |
| 492 | priv->ge_mac_cfg_3_value |= |
| 493 | NPS_ENET_GE_MAC_CFG_3_MAX_LEN << CFG_3_MAX_LEN_SHIFT; |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 494 | |
| 495 | /* Disable HW device */ |
| 496 | nps_enet_hw_disable_control(ndev); |
| 497 | |
| 498 | /* irq Rx allocation */ |
| 499 | err = request_irq(priv->irq, nps_enet_irq_handler, |
| 500 | 0, "enet-rx-tx", ndev); |
| 501 | if (err) |
| 502 | return err; |
| 503 | |
| 504 | napi_enable(&priv->napi); |
| 505 | |
| 506 | /* Enable HW device */ |
| 507 | nps_enet_hw_reset(ndev); |
| 508 | nps_enet_hw_enable_control(ndev); |
| 509 | |
| 510 | netif_start_queue(ndev); |
| 511 | |
| 512 | return 0; |
| 513 | } |
| 514 | |
| 515 | /** |
| 516 | * nps_enet_stop - Close the network device. |
| 517 | * @ndev: Pointer to the network device. |
| 518 | * |
| 519 | * This function stops the Tx queue, disables interrupts for the ENET device. |
| 520 | */ |
| 521 | static s32 nps_enet_stop(struct net_device *ndev) |
| 522 | { |
| 523 | struct nps_enet_priv *priv = netdev_priv(ndev); |
| 524 | |
| 525 | napi_disable(&priv->napi); |
| 526 | netif_stop_queue(ndev); |
| 527 | nps_enet_hw_disable_control(ndev); |
| 528 | free_irq(priv->irq, ndev); |
| 529 | |
| 530 | return 0; |
| 531 | } |
| 532 | |
| 533 | /** |
| 534 | * nps_enet_start_xmit - Starts the data transmission. |
| 535 | * @skb: sk_buff pointer that contains data to be Transmitted. |
| 536 | * @ndev: Pointer to net_device structure. |
| 537 | * |
| 538 | * returns: NETDEV_TX_OK, on success |
| 539 | * NETDEV_TX_BUSY, if any of the descriptors are not free. |
| 540 | * |
| 541 | * This function is invoked from upper layers to initiate transmission. |
| 542 | */ |
| 543 | static netdev_tx_t nps_enet_start_xmit(struct sk_buff *skb, |
| 544 | struct net_device *ndev) |
| 545 | { |
| 546 | struct nps_enet_priv *priv = netdev_priv(ndev); |
| 547 | |
| 548 | /* This driver handles one frame at a time */ |
| 549 | netif_stop_queue(ndev); |
| 550 | |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 551 | priv->tx_skb = skb; |
| 552 | |
Elad Kanfi | e5df49d | 2016-05-09 20:13:19 +0300 | [diff] [blame] | 553 | /* make sure tx_skb is actually written to the memory |
| 554 | * before the HW is informed and the IRQ is fired. |
| 555 | */ |
| 556 | wmb(); |
| 557 | |
Noam Camus | 93fcf83 | 2015-08-20 08:00:02 +0300 | [diff] [blame] | 558 | nps_enet_send_frame(ndev, skb); |
| 559 | |
Noam Camus | 0dd0770 | 2015-06-23 11:43:53 +0300 | [diff] [blame] | 560 | return NETDEV_TX_OK; |
| 561 | } |
| 562 | |
| 563 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 564 | static void nps_enet_poll_controller(struct net_device *ndev) |
| 565 | { |
| 566 | disable_irq(ndev->irq); |
| 567 | nps_enet_irq_handler(ndev->irq, ndev); |
| 568 | enable_irq(ndev->irq); |
| 569 | } |
| 570 | #endif |
| 571 | |
| 572 | static const struct net_device_ops nps_netdev_ops = { |
| 573 | .ndo_open = nps_enet_open, |
| 574 | .ndo_stop = nps_enet_stop, |
| 575 | .ndo_start_xmit = nps_enet_start_xmit, |
| 576 | .ndo_set_mac_address = nps_enet_set_mac_address, |
| 577 | .ndo_set_rx_mode = nps_enet_set_rx_mode, |
| 578 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 579 | .ndo_poll_controller = nps_enet_poll_controller, |
| 580 | #endif |
| 581 | }; |
| 582 | |
| 583 | static s32 nps_enet_probe(struct platform_device *pdev) |
| 584 | { |
| 585 | struct device *dev = &pdev->dev; |
| 586 | struct net_device *ndev; |
| 587 | struct nps_enet_priv *priv; |
| 588 | s32 err = 0; |
| 589 | const char *mac_addr; |
| 590 | struct resource *res_regs; |
| 591 | |
| 592 | if (!dev->of_node) |
| 593 | return -ENODEV; |
| 594 | |
| 595 | ndev = alloc_etherdev(sizeof(struct nps_enet_priv)); |
| 596 | if (!ndev) |
| 597 | return -ENOMEM; |
| 598 | |
| 599 | platform_set_drvdata(pdev, ndev); |
| 600 | SET_NETDEV_DEV(ndev, dev); |
| 601 | priv = netdev_priv(ndev); |
| 602 | |
| 603 | /* The EZ NET specific entries in the device structure. */ |
| 604 | ndev->netdev_ops = &nps_netdev_ops; |
| 605 | ndev->watchdog_timeo = (400 * HZ / 1000); |
| 606 | /* FIXME :: no multicast support yet */ |
| 607 | ndev->flags &= ~IFF_MULTICAST; |
| 608 | |
| 609 | res_regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 610 | priv->regs_base = devm_ioremap_resource(dev, res_regs); |
| 611 | if (IS_ERR(priv->regs_base)) { |
| 612 | err = PTR_ERR(priv->regs_base); |
| 613 | goto out_netdev; |
| 614 | } |
| 615 | dev_dbg(dev, "Registers base address is 0x%p\n", priv->regs_base); |
| 616 | |
| 617 | /* set kernel MAC address to dev */ |
| 618 | mac_addr = of_get_mac_address(dev->of_node); |
| 619 | if (mac_addr) |
| 620 | ether_addr_copy(ndev->dev_addr, mac_addr); |
| 621 | else |
| 622 | eth_hw_addr_random(ndev); |
| 623 | |
| 624 | /* Get IRQ number */ |
| 625 | priv->irq = platform_get_irq(pdev, 0); |
| 626 | if (!priv->irq) { |
| 627 | dev_err(dev, "failed to retrieve <irq Rx-Tx> value from device tree\n"); |
| 628 | err = -ENODEV; |
| 629 | goto out_netdev; |
| 630 | } |
| 631 | |
| 632 | netif_napi_add(ndev, &priv->napi, nps_enet_poll, |
| 633 | NPS_ENET_NAPI_POLL_WEIGHT); |
| 634 | |
| 635 | /* Register the driver. Should be the last thing in probe */ |
| 636 | err = register_netdev(ndev); |
| 637 | if (err) { |
| 638 | dev_err(dev, "Failed to register ndev for %s, err = 0x%08x\n", |
| 639 | ndev->name, (s32)err); |
| 640 | goto out_netif_api; |
| 641 | } |
| 642 | |
| 643 | dev_info(dev, "(rx/tx=%d)\n", priv->irq); |
| 644 | return 0; |
| 645 | |
| 646 | out_netif_api: |
| 647 | netif_napi_del(&priv->napi); |
| 648 | out_netdev: |
| 649 | if (err) |
| 650 | free_netdev(ndev); |
| 651 | |
| 652 | return err; |
| 653 | } |
| 654 | |
| 655 | static s32 nps_enet_remove(struct platform_device *pdev) |
| 656 | { |
| 657 | struct net_device *ndev = platform_get_drvdata(pdev); |
| 658 | struct nps_enet_priv *priv = netdev_priv(ndev); |
| 659 | |
| 660 | unregister_netdev(ndev); |
| 661 | free_netdev(ndev); |
| 662 | netif_napi_del(&priv->napi); |
| 663 | |
| 664 | return 0; |
| 665 | } |
| 666 | |
| 667 | static const struct of_device_id nps_enet_dt_ids[] = { |
| 668 | { .compatible = "ezchip,nps-mgt-enet" }, |
| 669 | { /* Sentinel */ } |
| 670 | }; |
| 671 | |
| 672 | static struct platform_driver nps_enet_driver = { |
| 673 | .probe = nps_enet_probe, |
| 674 | .remove = nps_enet_remove, |
| 675 | .driver = { |
| 676 | .name = DRV_NAME, |
| 677 | .of_match_table = nps_enet_dt_ids, |
| 678 | }, |
| 679 | }; |
| 680 | |
| 681 | module_platform_driver(nps_enet_driver); |
| 682 | |
| 683 | MODULE_AUTHOR("EZchip Semiconductor"); |
| 684 | MODULE_LICENSE("GPL v2"); |