32 #include <linux/module.h>
33 #include <linux/kernel.h>
34 #include <linux/sched.h>
35 #include <linux/string.h>
37 #include <linux/errno.h>
40 #include <linux/slab.h>
44 #include <linux/netdevice.h>
47 #include <linux/ethtool.h>
50 #include <linux/ctype.h>
57 #include <linux/bitops.h>
72 static int debug_level;
77 #define DAVINCI_EMAC_DEBUG (NETIF_MSG_DRV | \
85 NETIF_MSG_TX_QUEUED | \
88 NETIF_MSG_RX_STATUS | \
94 #define EMAC_MAJOR_VERSION 6
95 #define EMAC_MINOR_VERSION 1
96 #define EMAC_MODULE_VERSION "6.1"
98 static const char emac_version_string[] =
"TI DaVinci EMAC Linux v6.1";
101 #define EMAC_DEF_PASS_CRC (0)
102 #define EMAC_DEF_QOS_EN (0)
103 #define EMAC_DEF_NO_BUFF_CHAIN (0)
104 #define EMAC_DEF_MACCTRL_FRAME_EN (0)
105 #define EMAC_DEF_SHORT_FRAME_EN (0)
106 #define EMAC_DEF_ERROR_FRAME_EN (0)
107 #define EMAC_DEF_PROM_EN (0)
108 #define EMAC_DEF_PROM_CH (0)
109 #define EMAC_DEF_BCAST_EN (1)
110 #define EMAC_DEF_BCAST_CH (0)
111 #define EMAC_DEF_MCAST_EN (1)
112 #define EMAC_DEF_MCAST_CH (0)
114 #define EMAC_DEF_TXPRIO_FIXED (1)
115 #define EMAC_DEF_TXPACING_EN (0)
117 #define EMAC_DEF_BUFFER_OFFSET (0)
118 #define EMAC_DEF_MIN_ETHPKTSIZE (60)
119 #define EMAC_DEF_MAX_FRAME_SIZE (1500 + 14 + 4 + 4)
120 #define EMAC_DEF_TX_CH (0)
121 #define EMAC_DEF_RX_CH (0)
122 #define EMAC_DEF_RX_NUM_DESC (128)
123 #define EMAC_DEF_TX_NUM_DESC (128)
124 #define EMAC_DEF_MAX_TX_CH (1)
125 #define EMAC_DEF_MAX_RX_CH (1)
126 #define EMAC_POLL_WEIGHT (64)
129 #define EMAC_DEF_TX_MAX_SERVICE (32)
130 #define EMAC_DEF_RX_MAX_SERVICE (64)
133 #define EMAC_ALL_MULTI_REG_VALUE (0xFFFFFFFF)
134 #define EMAC_NUM_MULTICAST_BITS (64)
135 #define EMAC_TX_CONTROL_TX_ENABLE_VAL (0x1)
136 #define EMAC_RX_CONTROL_RX_ENABLE_VAL (0x1)
137 #define EMAC_MAC_HOST_ERR_INTMASK_VAL (0x2)
138 #define EMAC_RX_UNICAST_CLEAR_ALL (0xFF)
139 #define EMAC_INT_MASK_CLEAR (0xFF)
142 #define EMAC_RXMBP_PASSCRC_MASK BIT(30)
143 #define EMAC_RXMBP_QOSEN_MASK BIT(29)
144 #define EMAC_RXMBP_NOCHAIN_MASK BIT(28)
145 #define EMAC_RXMBP_CMFEN_MASK BIT(24)
146 #define EMAC_RXMBP_CSFEN_MASK BIT(23)
147 #define EMAC_RXMBP_CEFEN_MASK BIT(22)
148 #define EMAC_RXMBP_CAFEN_MASK BIT(21)
149 #define EMAC_RXMBP_PROMCH_SHIFT (16)
150 #define EMAC_RXMBP_PROMCH_MASK (0x7 << 16)
151 #define EMAC_RXMBP_BROADEN_MASK BIT(13)
152 #define EMAC_RXMBP_BROADCH_SHIFT (8)
153 #define EMAC_RXMBP_BROADCH_MASK (0x7 << 8)
154 #define EMAC_RXMBP_MULTIEN_MASK BIT(5)
155 #define EMAC_RXMBP_MULTICH_SHIFT (0)
156 #define EMAC_RXMBP_MULTICH_MASK (0x7)
157 #define EMAC_RXMBP_CHMASK (0x7)
160 # define EMAC_MBP_RXPROMISC (0x00200000)
161 # define EMAC_MBP_PROMISCCH(ch) (((ch) & 0x7) << 16)
162 # define EMAC_MBP_RXBCAST (0x00002000)
163 # define EMAC_MBP_BCASTCHAN(ch) (((ch) & 0x7) << 8)
164 # define EMAC_MBP_RXMCAST (0x00000020)
165 # define EMAC_MBP_MCASTCHAN(ch) ((ch) & 0x7)
168 #define EMAC_MACCONTROL_TXPTYPE BIT(9)
169 #define EMAC_MACCONTROL_TXPACEEN BIT(6)
170 #define EMAC_MACCONTROL_GMIIEN BIT(5)
171 #define EMAC_MACCONTROL_GIGABITEN BIT(7)
172 #define EMAC_MACCONTROL_FULLDUPLEXEN BIT(0)
173 #define EMAC_MACCONTROL_RMIISPEED_MASK BIT(15)
176 #define EMAC_DM646X_MACCONTORL_GIG BIT(7)
177 #define EMAC_DM646X_MACCONTORL_GIGFORCE BIT(17)
180 #define EMAC_MACSTATUS_TXERRCODE_MASK (0xF00000)
181 #define EMAC_MACSTATUS_TXERRCODE_SHIFT (20)
182 #define EMAC_MACSTATUS_TXERRCH_MASK (0x7)
183 #define EMAC_MACSTATUS_TXERRCH_SHIFT (16)
184 #define EMAC_MACSTATUS_RXERRCODE_MASK (0xF000)
185 #define EMAC_MACSTATUS_RXERRCODE_SHIFT (12)
186 #define EMAC_MACSTATUS_RXERRCH_MASK (0x7)
187 #define EMAC_MACSTATUS_RXERRCH_SHIFT (8)
190 #define EMAC_RX_MAX_LEN_MASK (0xFFFF)
191 #define EMAC_RX_BUFFER_OFFSET_MASK (0xFFFF)
194 #define EMAC_DM644X_MAC_IN_VECTOR_HOST_INT BIT(17)
195 #define EMAC_DM644X_MAC_IN_VECTOR_STATPEND_INT BIT(16)
196 #define EMAC_DM644X_MAC_IN_VECTOR_RX_INT_VEC BIT(8)
197 #define EMAC_DM644X_MAC_IN_VECTOR_TX_INT_VEC BIT(0)
200 #define EMAC_DM646X_MAC_IN_VECTOR_RX_INT_VEC BIT(EMAC_DEF_RX_CH)
201 #define EMAC_DM646X_MAC_IN_VECTOR_TX_INT_VEC BIT(16 + EMAC_DEF_TX_CH)
202 #define EMAC_DM646X_MAC_IN_VECTOR_HOST_INT BIT(26)
203 #define EMAC_DM646X_MAC_IN_VECTOR_STATPEND_INT BIT(27)
206 #define EMAC_CPPI_SOP_BIT BIT(31)
207 #define EMAC_CPPI_EOP_BIT BIT(30)
208 #define EMAC_CPPI_OWNERSHIP_BIT BIT(29)
209 #define EMAC_CPPI_EOQ_BIT BIT(28)
210 #define EMAC_CPPI_TEARDOWN_COMPLETE_BIT BIT(27)
211 #define EMAC_CPPI_PASS_CRC_BIT BIT(26)
212 #define EMAC_RX_BD_BUF_SIZE (0xFFFF)
213 #define EMAC_BD_LENGTH_FOR_CACHE (16)
214 #define EMAC_RX_BD_PKT_LENGTH_MASK (0xFFFF)
217 #define EMAC_MAX_TXRX_CHANNELS (8)
218 #define EMAC_DEF_MAX_MULTICAST_ADDRESSES (64)
221 #define EMAC_MACINVECTOR 0x90
223 #define EMAC_DM646X_MACEOIVECTOR 0x94
225 #define EMAC_MACINTSTATRAW 0xB0
226 #define EMAC_MACINTSTATMASKED 0xB4
227 #define EMAC_MACINTMASKSET 0xB8
228 #define EMAC_MACINTMASKCLEAR 0xBC
230 #define EMAC_RXMBPENABLE 0x100
231 #define EMAC_RXUNICASTSET 0x104
232 #define EMAC_RXUNICASTCLEAR 0x108
233 #define EMAC_RXMAXLEN 0x10C
234 #define EMAC_RXBUFFEROFFSET 0x110
235 #define EMAC_RXFILTERLOWTHRESH 0x114
237 #define EMAC_MACCONTROL 0x160
238 #define EMAC_MACSTATUS 0x164
239 #define EMAC_EMCONTROL 0x168
240 #define EMAC_FIFOCONTROL 0x16C
241 #define EMAC_MACCONFIG 0x170
242 #define EMAC_SOFTRESET 0x174
243 #define EMAC_MACSRCADDRLO 0x1D0
244 #define EMAC_MACSRCADDRHI 0x1D4
245 #define EMAC_MACHASH1 0x1D8
246 #define EMAC_MACHASH2 0x1DC
247 #define EMAC_MACADDRLO 0x500
248 #define EMAC_MACADDRHI 0x504
249 #define EMAC_MACINDEX 0x508
252 #define EMAC_RXGOODFRAMES 0x200
253 #define EMAC_RXBCASTFRAMES 0x204
254 #define EMAC_RXMCASTFRAMES 0x208
255 #define EMAC_RXPAUSEFRAMES 0x20C
256 #define EMAC_RXCRCERRORS 0x210
257 #define EMAC_RXALIGNCODEERRORS 0x214
258 #define EMAC_RXOVERSIZED 0x218
259 #define EMAC_RXJABBER 0x21C
260 #define EMAC_RXUNDERSIZED 0x220
261 #define EMAC_RXFRAGMENTS 0x224
262 #define EMAC_RXFILTERED 0x228
263 #define EMAC_RXQOSFILTERED 0x22C
264 #define EMAC_RXOCTETS 0x230
265 #define EMAC_TXGOODFRAMES 0x234
266 #define EMAC_TXBCASTFRAMES 0x238
267 #define EMAC_TXMCASTFRAMES 0x23C
268 #define EMAC_TXPAUSEFRAMES 0x240
269 #define EMAC_TXDEFERRED 0x244
270 #define EMAC_TXCOLLISION 0x248
271 #define EMAC_TXSINGLECOLL 0x24C
272 #define EMAC_TXMULTICOLL 0x250
273 #define EMAC_TXEXCESSIVECOLL 0x254
274 #define EMAC_TXLATECOLL 0x258
275 #define EMAC_TXUNDERRUN 0x25C
276 #define EMAC_TXCARRIERSENSE 0x260
277 #define EMAC_TXOCTETS 0x264
278 #define EMAC_NETOCTETS 0x280
279 #define EMAC_RXSOFOVERRUNS 0x284
280 #define EMAC_RXMOFOVERRUNS 0x288
281 #define EMAC_RXDMAOVERRUNS 0x28C
284 #define EMAC_CTRL_EWCTL (0x4)
285 #define EMAC_CTRL_EWINTTCNT (0x8)
288 #define EMAC_DM644X_EWINTCNT_MASK 0x1FFFF
289 #define EMAC_DM644X_INTMIN_INTVL 0x1
290 #define EMAC_DM644X_INTMAX_INTVL (EMAC_DM644X_EWINTCNT_MASK)
293 #define EMAC_DM646X_CMINTCTRL 0x0C
294 #define EMAC_DM646X_CMRXINTEN 0x14
295 #define EMAC_DM646X_CMTXINTEN 0x18
296 #define EMAC_DM646X_CMRXINTMAX 0x70
297 #define EMAC_DM646X_CMTXINTMAX 0x74
300 #define EMAC_DM646X_INTPACEEN (0x3 << 16)
301 #define EMAC_DM646X_INTPRESCALE_MASK (0x7FF << 0)
302 #define EMAC_DM646X_CMINTMAX_CNT 63
303 #define EMAC_DM646X_CMINTMIN_CNT 2
304 #define EMAC_DM646X_CMINTMAX_INTVL (1000 / EMAC_DM646X_CMINTMIN_CNT)
305 #define EMAC_DM646X_CMINTMIN_INTVL ((1000 / EMAC_DM646X_CMINTMAX_CNT) + 1)
309 #define EMAC_DM646X_MAC_EOI_C0_RXEN (0x01)
310 #define EMAC_DM646X_MAC_EOI_C0_TXEN (0x02)
313 #define EMAC_STATS_CLR_MASK (0xFFFFFFFF)
358 static char *emac_txhost_errcodes[16] = {
359 "No error",
"SOP error",
"Ownership bit not set in SOP buffer",
360 "Zero Next Buffer Descriptor Pointer Without EOP",
361 "Zero Buffer Pointer",
"Zero Buffer Length",
"Packet Length Error",
362 "Reserved",
"Reserved",
"Reserved",
"Reserved",
"Reserved",
363 "Reserved",
"Reserved",
"Reserved",
"Reserved"
367 static char *emac_rxhost_errcodes[16] = {
368 "No error",
"Reserved",
"Ownership bit not set in input buffer",
369 "Reserved",
"Zero Buffer Pointer",
"Reserved",
"Reserved",
370 "Reserved",
"Reserved",
"Reserved",
"Reserved",
"Reserved",
371 "Reserved",
"Reserved",
"Reserved",
"Reserved"
375 #define emac_read(reg) ioread32(priv->emac_base + (reg))
376 #define emac_write(reg, val) iowrite32(val, priv->emac_base + (reg))
378 #define emac_ctrl_read(reg) ioread32((priv->ctrl_base + (reg)))
379 #define emac_ctrl_write(reg, val) iowrite32(val, (priv->ctrl_base + (reg)))
393 dev_info(emac_dev,
"EMAC Basic registers\n");
395 dev_info(emac_dev,
"EMAC: EWCTL: %08X, EWINTTCNT: %08X\n",
399 dev_info(emac_dev,
"EMAC: EmuControl:%08X, FifoControl: %08X\n",
401 dev_info(emac_dev,
"EMAC: MBPEnable:%08X, RXUnicastSet: %08X, "\
404 dev_info(emac_dev,
"EMAC: MacControl:%08X, MacStatus: %08X, "\
407 dev_info(emac_dev,
"EMAC Statistics\n");
408 dev_info(emac_dev,
"EMAC: rx_good_frames:%d\n",
410 dev_info(emac_dev,
"EMAC: rx_broadcast_frames:%d\n",
412 dev_info(emac_dev,
"EMAC: rx_multicast_frames:%d\n",
414 dev_info(emac_dev,
"EMAC: rx_pause_frames:%d\n",
416 dev_info(emac_dev,
"EMAC: rx_crcerrors:%d\n",
418 dev_info(emac_dev,
"EMAC: rx_align_code_errors:%d\n",
420 dev_info(emac_dev,
"EMAC: rx_oversized_frames:%d\n",
422 dev_info(emac_dev,
"EMAC: rx_jabber_frames:%d\n",
424 dev_info(emac_dev,
"EMAC: rx_undersized_frames:%d\n",
426 dev_info(emac_dev,
"EMAC: rx_fragments:%d\n",
428 dev_info(emac_dev,
"EMAC: rx_filtered_frames:%d\n",
430 dev_info(emac_dev,
"EMAC: rx_qos_filtered_frames:%d\n",
432 dev_info(emac_dev,
"EMAC: rx_octets:%d\n",
434 dev_info(emac_dev,
"EMAC: tx_goodframes:%d\n",
436 dev_info(emac_dev,
"EMAC: tx_bcastframes:%d\n",
438 dev_info(emac_dev,
"EMAC: tx_mcastframes:%d\n",
440 dev_info(emac_dev,
"EMAC: tx_pause_frames:%d\n",
442 dev_info(emac_dev,
"EMAC: tx_deferred_frames:%d\n",
444 dev_info(emac_dev,
"EMAC: tx_collision_frames:%d\n",
446 dev_info(emac_dev,
"EMAC: tx_single_coll_frames:%d\n",
448 dev_info(emac_dev,
"EMAC: tx_mult_coll_frames:%d\n",
450 dev_info(emac_dev,
"EMAC: tx_excessive_collisions:%d\n",
452 dev_info(emac_dev,
"EMAC: tx_late_collisions:%d\n",
454 dev_info(emac_dev,
"EMAC: tx_underrun:%d\n",
456 dev_info(emac_dev,
"EMAC: tx_carrier_sense_errors:%d\n",
458 dev_info(emac_dev,
"EMAC: tx_octets:%d\n",
460 dev_info(emac_dev,
"EMAC: net_octets:%d\n",
462 dev_info(emac_dev,
"EMAC: rx_sof_overruns:%d\n",
464 dev_info(emac_dev,
"EMAC: rx_mof_overruns:%d\n",
466 dev_info(emac_dev,
"EMAC: rx_dma_overruns:%d\n",
516 struct emac_priv *priv = netdev_priv(ndev);
532 static int emac_get_coalesce(
struct net_device *ndev,
535 struct emac_priv *priv = netdev_priv(ndev);
550 static int emac_set_coalesce(
struct net_device *ndev,
553 struct emac_priv *priv = netdev_priv(ndev);
577 if (addnl_dvdr > 1) {
578 prescale *= addnl_dvdr;
589 num_interrupts = (1000 * addnl_dvdr) /
coal_intvl;
627 .get_settings = emac_get_settings,
628 .set_settings = emac_set_settings,
630 .get_coalesce = emac_get_coalesce,
631 .set_coalesce = emac_set_coalesce,
643 static void emac_update_phystatus(
struct emac_priv *priv)
654 new_duplex = priv->
phydev->duplex;
659 if ((priv->
link) && (new_duplex != cur_duplex)) {
660 priv->
duplex = new_duplex;
687 if (!netif_carrier_ok(ndev))
690 if (netif_running(ndev) && netif_queue_stopped(ndev))
691 netif_wake_queue(ndev);
694 if (netif_carrier_ok(ndev))
696 if (!netif_queue_stopped(ndev))
697 netif_stop_queue(ndev);
715 for (cnt = 0; cnt < 2; cnt++) {
717 hash ^= (tmpval >> 2) ^ (tmpval << 4);
719 hash ^= (tmpval >> 4) ^ (tmpval << 2);
721 hash ^= (tmpval >> 6) ^ (tmpval);
740 u32 hash_value = hash_get(mac_addr);
744 dev_err(emac_dev,
"DaVinci EMAC: hash_add(): Invalid "\
745 "Hash %08x, should not be greater than %08x",
754 if (hash_value < 32) {
755 hash_bit =
BIT(hash_value);
758 hash_bit =
BIT((hash_value - 32));
777 static int hash_del(
struct emac_priv *priv,
u8 *mac_addr)
782 hash_value = hash_get(mac_addr);
793 if (hash_value < 32) {
794 hash_bit =
BIT(hash_value);
797 hash_bit =
BIT((hash_value - 32));
806 #define EMAC_MULTICAST_ADD 0
807 #define EMAC_MULTICAST_DEL 1
808 #define EMAC_ALL_MULTI_SET 2
809 #define EMAC_ALL_MULTI_CLR 3
830 update = hash_del(priv, mac_addr);
847 dev_err(emac_dev,
"DaVinci EMAC: add_mcast"\
848 ": bad operation %d", action);
866 static void emac_dev_mcast_set(
struct net_device *ndev)
869 struct emac_priv *priv = netdev_priv(ndev);
912 static void emac_int_disable(
struct emac_priv *priv)
942 static void emac_int_enable(
struct emac_priv *priv)
984 struct emac_priv *priv = netdev_priv(ndev);
988 emac_int_disable(priv);
989 napi_schedule(&priv->
napi);
1009 struct emac_priv *priv = netdev_priv(ndev);
1014 if (
unlikely(!netif_running(ndev))) {
1021 ndev->
stats.rx_errors++;
1029 ndev->
stats.rx_bytes += len;
1030 ndev->
stats.rx_packets++;
1033 skb = emac_rx_alloc(priv);
1036 dev_err(emac_dev,
"failed rx buffer alloc\n");
1049 static void emac_tx_handler(
void *token,
int len,
int status)
1053 struct emac_priv *priv = netdev_priv(ndev);
1057 if (
unlikely(netif_queue_stopped(ndev)))
1058 netif_start_queue(ndev);
1059 ndev->
stats.tx_packets++;
1060 ndev->
stats.tx_bytes += len;
1078 struct emac_priv *priv = netdev_priv(ndev);
1083 dev_err(emac_dev,
"DaVinci EMAC: No link to transmit");
1090 dev_err(emac_dev,
"DaVinci EMAC: packet pad failed");
1094 skb_tx_timestamp(skb);
1100 dev_err(emac_dev,
"DaVinci EMAC: desc submit failed");
1105 netif_stop_queue(ndev);
1110 ndev->
stats.tx_dropped++;
1111 netif_stop_queue(ndev);
1125 static void emac_dev_tx_timeout(
struct net_device *ndev)
1127 struct emac_priv *priv = netdev_priv(ndev);
1131 dev_err(emac_dev,
"DaVinci EMAC: xmit timeout, restarting TX");
1133 emac_dump_regs(priv);
1135 ndev->
stats.tx_errors++;
1136 emac_int_disable(priv);
1139 emac_int_enable(priv);
1152 static void emac_set_type0addr(
struct emac_priv *priv,
u32 ch,
char *mac_addr)
1155 val = ((mac_addr[5] << 8) | (mac_addr[4]));
1158 val = ((mac_addr[3] << 24) | (mac_addr[2] << 16) | \
1159 (mac_addr[1] << 8) | (mac_addr[0]));
1179 static void emac_set_type1addr(
struct emac_priv *priv,
u32 ch,
char *mac_addr)
1183 val = ((mac_addr[5] << 8) | mac_addr[4]);
1185 val = ((mac_addr[3] << 24) | (mac_addr[2] << 16) | \
1186 (mac_addr[1] << 8) | (mac_addr[0]));
1188 emac_set_type0addr(priv, ch, mac_addr);
1203 static void emac_set_type2addr(
struct emac_priv *priv,
u32 ch,
1208 val = ((mac_addr[3] << 24) | (mac_addr[2] << 16) | \
1209 (mac_addr[1] << 8) | (mac_addr[0]));
1211 val = ((mac_addr[5] << 8) | mac_addr[4] | ((ch & 0x7) << 16) | \
1212 (match << 19) |
BIT(20));
1214 emac_set_type0addr(priv, ch, mac_addr);
1227 static void emac_setmac(
struct emac_priv *priv,
u32 ch,
char *mac_addr)
1232 emac_set_type0addr(priv, ch, mac_addr);
1236 emac_set_type1addr(priv, ch, mac_addr);
1238 emac_set_type2addr(priv, ch, mac_addr, ch, 1);
1239 emac_set_type0addr(priv, ch, mac_addr);
1242 dev_err(emac_dev,
"DaVinci EMAC: Wrong addressing\n");
1255 static int emac_dev_setmac_addr(
struct net_device *ndev,
void *addr)
1257 struct emac_priv *priv = netdev_priv(ndev);
1261 if (!is_valid_ether_addr(sa->
sa_data))
1270 if (netif_running(ndev)) {
1275 dev_notice(emac_dev,
"DaVinci EMAC: emac_dev_setmac_addr %pM\n",
1290 static int emac_hw_enable(
struct emac_priv *priv)
1292 u32 val, mbp_enable, mac_control;
1300 emac_int_disable(priv);
1319 EMAC_RXMBP_PROMCH_SHIFT) |
1325 EMAC_RXMBP_MULTICH_SHIFT));
1345 napi_enable(&priv->
napi);
1346 emac_int_enable(priv);
1371 u32 num_tx_pkts = 0, num_rx_pkts = 0;
1381 if (status & mask) {
1391 if (status & mask) {
1401 dev_err(emac_dev,
"DaVinci EMAC: Fatal Hardware Error\n");
1402 netif_stop_queue(ndev);
1403 napi_disable(&priv->
napi);
1412 dev_err(emac_dev,
"TX Host error %s on ch=%d\n",
1413 &emac_txhost_errcodes[cause][0], ch);
1422 dev_err(emac_dev,
"RX Host error %s on ch=%d\n",
1423 &emac_rxhost_errcodes[cause][0], ch);
1425 }
else if (num_rx_pkts < budget) {
1427 emac_int_enable(priv);
1433 #ifdef CONFIG_NET_POLL_CONTROLLER
1441 void emac_poll_controller(
struct net_device *ndev)
1443 struct emac_priv *priv = netdev_priv(ndev);
1445 emac_int_disable(priv);
1446 emac_irq(ndev->
irq, ndev);
1447 emac_int_enable(priv);
1451 static void emac_adjust_link(
struct net_device *ndev)
1453 struct emac_priv *priv = netdev_priv(ndev);
1455 unsigned long flags;
1475 }
else if (priv->
link) {
1482 emac_update_phystatus(priv);
1486 spin_unlock_irqrestore(&priv->
lock, flags);
1505 struct emac_priv *priv = netdev_priv(ndev);
1507 if (!(netif_running(ndev)))
1515 static int match_first_device(
struct device *
dev,
void *
data)
1517 return !
strncmp(dev_name(dev),
"davinci_mdio", 12);
1530 static int emac_dev_open(
struct net_device *ndev)
1538 struct emac_priv *priv = netdev_priv(ndev);
1540 pm_runtime_get(&priv->
pdev->dev);
1543 for (cnt = 0; cnt <
ETH_ALEN; cnt++)
1555 struct sk_buff *skb = emac_rx_alloc(priv);
1569 for (i = res->
start; i <= res->
end; i++) {
1578 emac_hw_enable(priv);
1585 emac_set_coalesce(ndev, &coal);
1596 match_first_device);
1598 priv->
phy_id = dev_name(phy);
1603 &emac_adjust_link, 0,
1606 if (IS_ERR(priv->
phydev)) {
1607 dev_err(emac_dev,
"could not connect to phy %s\n",
1609 ret = PTR_ERR(priv->
phydev);
1618 dev_info(emac_dev,
"attached PHY driver [%s] "
1619 "(mii_bus:phy_addr=%s, id=%x)\n",
1624 dev_notice(emac_dev,
"no phy, defaulting to 100/full\n");
1628 emac_update_phystatus(priv);
1631 if (!netif_running(ndev))
1632 emac_dump_regs(priv);
1635 dev_notice(emac_dev,
"DaVinci EMAC: Opened %s\n", ndev->
name);
1644 dev_err(emac_dev,
"DaVinci EMAC: request_irq() failed");
1646 for (q = k; k >= 0; k--) {
1647 for (m = i; m >= res->
start; m--)
1655 pm_runtime_put(&priv->
pdev->dev);
1668 static int emac_dev_stop(
struct net_device *ndev)
1673 struct emac_priv *priv = netdev_priv(ndev);
1677 netif_stop_queue(ndev);
1678 napi_disable(&priv->
napi);
1681 emac_int_disable(priv);
1690 for (irq_num = res->
start; irq_num <= res->
end; irq_num++)
1696 dev_notice(emac_dev,
"DaVinci EMAC: %s stopped\n", ndev->
name);
1698 pm_runtime_put(&priv->
pdev->dev);
1712 struct emac_priv *priv = netdev_priv(ndev);
1714 u32 stats_clear_mask;
1723 stats_clear_mask = 0;
1750 ndev->
stats.tx_carrier_errors +=
1757 return &ndev->
stats;
1761 .ndo_open = emac_dev_open,
1762 .ndo_stop = emac_dev_stop,
1763 .ndo_start_xmit = emac_dev_xmit,
1764 .ndo_set_rx_mode = emac_dev_mcast_set,
1765 .ndo_set_mac_address = emac_dev_setmac_addr,
1766 .ndo_do_ioctl = emac_devioctl,
1767 .ndo_tx_timeout = emac_dev_tx_timeout,
1768 .ndo_get_stats = emac_dev_getnetstats,
1769 #ifdef CONFIG_NET_POLL_CONTROLLER
1770 .ndo_poll_controller = emac_poll_controller,
1785 pdata = pdev->
dev.platform_data;
1792 np = pdev->
dev.of_node;
1798 if (!is_valid_ether_addr(pdata->
mac_addr)) {
1804 ret = of_property_read_u32(np,
"ti,davinci-ctrl-reg-offset", &data);
1808 ret = of_property_read_u32(np,
"ti,davinci-ctrl-mod-reg-offset",
1813 ret = of_property_read_u32(np,
"ti,davinci-ctrl-ram-offset", &data);
1817 ret = of_property_read_u32(np,
"ti,davinci-ctrl-ram-size", &data);
1821 ret = of_property_read_u32(np,
"ti,davinci-rmii-en", &data);
1825 ret = of_property_read_u32(np,
"ti,davinci-no-bd-ram", &data);
1830 if (!priv->phy_node)
1842 return pdev->
dev.platform_data;
1859 unsigned long size, hw_ram_addr;
1863 struct clk *emac_clk;
1864 unsigned long emac_bus_frequency;
1869 if (IS_ERR(emac_clk)) {
1870 dev_err(&pdev->
dev,
"failed to get EMAC clock\n");
1878 ndev = alloc_etherdev(
sizeof(
struct emac_priv));
1884 platform_set_drvdata(pdev, ndev);
1885 priv = netdev_priv(ndev);
1892 pdata = davinci_emac_of_get_pdata(pdev, priv);
1910 emac_dev = &ndev->
dev;
1920 size = resource_size(res);
1922 dev_err(&pdev->
dev,
"failed request_mem_region() for regs\n");
1943 memset(&dma_params, 0,
sizeof(dma_params));
1944 dma_params.dev = emac_dev;
1946 dma_params.rxthresh = priv->
emac_base + 0x120;
1947 dma_params.rxfree = priv->
emac_base + 0x140;
1948 dma_params.txhdp = priv->
emac_base + 0x600;
1949 dma_params.rxhdp = priv->
emac_base + 0x620;
1950 dma_params.txcp = priv->
emac_base + 0x640;
1951 dma_params.rxcp = priv->
emac_base + 0x660;
1954 dma_params.desc_hw_addr = hw_ram_addr;
1956 dma_params.desc_align = 16;
1958 dma_params.desc_mem_phys = pdata->
no_bd_ram ? 0 :
1963 dev_err(&pdev->
dev,
"error initializing DMA\n");
1979 dev_err(&pdev->
dev,
"error getting irq res\n");
1985 if (!is_valid_ether_addr(priv->
mac_addr)) {
1987 eth_hw_addr_random(ndev);
1989 dev_warn(&pdev->
dev,
"using random MAC addr: %pM\n",
2001 dev_err(&pdev->
dev,
"error in register_netdev\n");
2008 dev_notice(emac_dev,
"DaVinci EMAC Probe found device "\
2009 "(regs: %p, irq: %d)\n",
2014 pm_runtime_resume(&pdev->
dev);
2045 struct net_device *ndev = platform_get_drvdata(pdev);
2046 struct emac_priv *priv = netdev_priv(ndev);
2048 dev_notice(&ndev->
dev,
"DaVinci EMAC: davinci_emac_remove()\n");
2050 platform_set_drvdata(pdev,
NULL);
2068 static int davinci_emac_suspend(
struct device *dev)
2071 struct net_device *ndev = platform_get_drvdata(pdev);
2073 if (netif_running(ndev))
2074 emac_dev_stop(ndev);
2079 static int davinci_emac_resume(
struct device *dev)
2082 struct net_device *ndev = platform_get_drvdata(pdev);
2084 if (netif_running(ndev))
2085 emac_dev_open(ndev);
2090 static const struct dev_pm_ops davinci_emac_pm_ops = {
2091 .suspend = davinci_emac_suspend,
2092 .resume = davinci_emac_resume,
2095 static const struct of_device_id davinci_emac_of_match[] = {
2096 {.compatible =
"ti,davinci-dm6467-emac", },
2104 .name =
"davinci_emac",
2106 .pm = &davinci_emac_pm_ops,
2109 .probe = davinci_emac_probe,
2119 static int __init davinci_emac_init(
void)
2131 static void __exit davinci_emac_exit(
void)