OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [orpmon/] [cmds/] [eth.c] - Blame information for rev 1774

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 809 simons
#include "common.h"
2
#include "uart.h"
3
#include "eth.h"
4 855 markom
#include "support.h"
5 809 simons
#include "spr_defs.h"
6 1312 jurem
#include "net.h"
7 809 simons
 
8 855 markom
#if 0
9 809 simons
extern int tx_pointer_index;
10
unsigned long dest_mac_addr[6];
11
 
12
void show_tx_bd(int start, int max)
13
{
14 855 markom
  int i;
15 809 simons
 
16
  for(i = start; i <= max; i++) {
17
    /* Read Tx BD */
18 855 markom
    printf ("LEN:%04lx", REG32(ETH_BD_BASE + (i << 3)) >> 16);
19
    printf (" RD:%04lx", (REG32(ETH_BD_BASE + (i << 3)) >> 15) & 0x1);
20
    printf (" IRQ:%04lx", (REG32(ETH_BD_BASE + (i << 3)) >> 14) & 0x1);
21
    printf (" WR:%04lx", (REG32(ETH_BD_BASE + (i << 3)) >> 13) & 0x1);
22
    printf (" PAD:%04lx", (REG32(ETH_BD_BASE + (i << 3)) >> 12) & 0x1);
23
    printf (" CRC:%04lx", (REG32(ETH_BD_BASE + (i << 3)) >> 11) & 0x1);
24
    printf (" UR:%04lx", (REG32(ETH_BD_BASE + (i << 3)) >> 8) & 0x1);
25
    printf (" RTRY:%04lx", (REG32(ETH_BD_BASE + (i << 3)) >> 4) & 0xf);
26
    printf (" RL:%04lx", (REG32(ETH_BD_BASE + (i << 3)) >> 3) & 0x1);
27
    printf (" LC:%04lx", (REG32(ETH_BD_BASE + (i << 3)) >> 2) & 0x1);
28
    printf (" DF:%04lx", (REG32(ETH_BD_BASE + (i << 3)) >> 1) & 0x1);
29
    printf (" CS:%04lx", (REG32(ETH_BD_BASE + (i << 3)) >> 0) & 0x1);
30
    printf ("\nTx Buffer Pointer: %08lx\n", REG32(ETH_BD_BASE + (i << 3) + 4));
31 809 simons
  }
32
}
33
 
34
void show_rx_bd (int start, int max)
35
{
36 855 markom
  int i;
37 809 simons
  unsigned long rx_bd_base, rx_bd_num;
38
 
39
  rx_bd_num =  REG32(ETH_REG_BASE + ETH_RXBD_NUM);
40
  rx_bd_base = ETH_BD_BASE + (rx_bd_num << 2);
41
 
42
  for(i = start; i <= max; i++){
43
    /* Read Rx BD */
44 855 markom
    printf ("LEN:%04lx", REG32(rx_bd_base + (i << 3)) >> 16);
45
    printf (" E:%04lx", (REG32(rx_bd_base + (i << 3)) >> 15) & 0x1);
46
    printf (" IRQ:%04lx", (REG32(rx_bd_base + (i << 3)) >> 14) & 0x1);
47
    printf (" WR:%04lx", (REG32(rx_bd_base + (i << 3)) >> 13) & 0x1);
48
    printf (" M:%04lx", (REG32(rx_bd_base + (i << 3)) >> 7) & 0x1);
49
    printf (" OR:%04lx", (REG32(rx_bd_base + (i << 3)) >> 6) & 0x1);
50
    printf (" IS:%04lx", (REG32(rx_bd_base + (i << 3)) >> 5) & 0x1);
51
    printf (" DN:%04lx", (REG32(rx_bd_base + (i << 3)) >> 4) & 0x1);
52
    printf (" TL:%04lx", (REG32(rx_bd_base + (i << 3)) >> 3) & 0x1);
53
    printf (" SF:%04lx", (REG32(rx_bd_base + (i << 3)) >> 2) & 0x1);
54
    printf (" CRC:%04lx", (REG32(rx_bd_base + (i << 3)) >> 1) & 0x1);
55
    printf (" LC:%04lx", (REG32(rx_bd_base + (i << 3)) >> 0) & 0x1);
56
    printf ("\nRx Buffer Pointer: %08lx\n", REG32(rx_bd_base + (i << 3) + 4));
57 809 simons
  }
58
}
59
 
60
void show_buffer(unsigned long start_addr, unsigned long len)
61
{
62
  show_mem(start_addr, start_addr + len - 1);
63
}
64
 
65
void show_rx_buffs(int max, int show_all)
66
{
67
 
68
  int i;
69
  unsigned long rx_bd_base, rx_bd_num;
70
 
71
  rx_bd_num =  REG32(ETH_REG_BASE + ETH_RXBD_NUM);
72
  rx_bd_base = ETH_BD_BASE + (rx_bd_num << 2);
73
 
74
  for(i=0; i<=max; i++)
75
  {
76
    if (!(REG32(rx_bd_base + (i << 3)) & ETH_RX_BD_EMPTY) || show_all)
77
    {
78 855 markom
      printf ("Rx BD No. %04x located at %08lx\n", i, rx_bd_base + (i << 3));
79 809 simons
      show_rx_bd(i, i);
80
      show_buffer(REG32(rx_bd_base + (i << 3) + 4), REG32(rx_bd_base + (i << 3)) >> 16);
81
      printf ("\n");
82
    }
83
    if (REG32(rx_bd_base + (i << 3)) & ETH_RX_BD_WRAP)
84
      return;
85
  }
86
}
87
 
88
void show_tx_buffs(int max)
89
{
90
  int i;
91
 
92
  for(i=0; i<=max; i++)
93
  {
94
    if (1)
95
    {
96
      printf ("Tx BD No. %04x located at %08x\n", i, ETH_BD_BASE + (i << 3));
97
      show_tx_bd(i, i);
98
      show_buffer(REG32(ETH_BD_BASE + (i << 3) + 4), REG32(ETH_BD_BASE + (i << 3)) >> 16);
99
      printf ("\n");
100
    }
101
    if (REG32(ETH_BD_BASE + (i << 3)) & ETH_TX_BD_WRAP)
102
      return;
103
  }
104
}
105
 
106
void show_phy_reg (unsigned long start_addr, unsigned long stop_addr)
107
{
108
 
109
  unsigned long addr;
110
 
111
  if (start_addr == stop_addr)
112
  {
113 855 markom
    printf ("\nSet MII RGAD ADDRESS to %08lx", start_addr);
114 809 simons
    printf ("\nMII Command = Read Status\n");
115
  }
116
 
117
  for (addr = start_addr; addr <= stop_addr; addr++)
118
  {
119
    REG32(ETH_REG_BASE + ETH_MIIADDRESS) = addr<<8;
120
    REG32(ETH_REG_BASE + ETH_MIICOMMAND) = ETH_MIICOMMAND_RSTAT;
121
 
122 855 markom
    printf ("PHY %04lx", REG32(ETH_REG_BASE + ETH_MIIADDRESS) & 0x1f);
123
    printf (", addr %04lx", REG32(ETH_REG_BASE + ETH_MIIADDRESS) >> 8);
124
    printf (": %08lx\n", REG32(ETH_REG_BASE + ETH_MIIRX_DATA));
125 809 simons
  }
126
}
127
 
128
void set_phy_reg (unsigned long addr, unsigned long val)
129
{
130 855 markom
  printf ("\nSet MII RGAD ADDRESS to %08lx", addr);
131 809 simons
 
132
  REG32(ETH_REG_BASE + ETH_MIIADDRESS) = addr<<8;
133
 
134
  printf ("\nMII Command = Write Control Data\n");
135
  REG32(ETH_REG_BASE + ETH_MIICOMMAND) = ETH_MIICOMMAND_WCTRLDATA;
136
 
137
  REG32(ETH_REG_BASE + ETH_MIITX_DATA) = val;
138
 
139
  show_phy_reg(addr, addr);
140
}
141
 
142
void send_packet (unsigned long len, unsigned long start_data, int num_of_packets)
143
{
144
  unsigned long i, TxBD;
145
 
146
  while (num_of_packets--) {
147
    unsigned long *data = (unsigned long *)eth_get_tx_buf ();
148
 
149
    /* Set dest & src address */
150
    *data++ = dest_mac_addr[0] << 24 |
151
              dest_mac_addr[1] << 16 |
152
              dest_mac_addr[2] << 8  |
153
              dest_mac_addr[3] << 0;
154
 
155
    *data++ = dest_mac_addr[4] << 24 |
156
              dest_mac_addr[5] << 16 |
157
              ETH_MACADDR0     << 8  |
158
              ETH_MACADDR1     << 0;
159
 
160
    *data++ = ETH_MACADDR2     << 24 |
161
              ETH_MACADDR3     << 16 |
162
              ETH_MACADDR4     << 8  |
163
              ETH_MACADDR5     << 0;
164
 
165
    /* Write data to buffer */
166
    for(i = 12; i < len; i += 4)
167
      *data++ = (i + start_data - 12) << 24 | (i + start_data + 1 - 12) << 16 |
168
                (i + start_data + 2 - 12) << 8 | (i + start_data + 3 - 12);
169
 
170
    eth_send (data, len);
171
    printf (".");
172
  }
173
}
174
 
175
int eth_init_cmd (int argc, char *argv[])
176
{
177
  if (argc) return -1;
178
  eth_init (0);
179
  return 0;
180
}
181
 
182
int show_txbd_cmd (int argc, char *argv[])
183
{
184 855 markom
  int i;
185 809 simons
  int start, max;
186
 
187 855 markom
  if (argc == 1) show_tx_bd (strtoul (argv[0], NULL, 0), strtoul (argv[0], NULL, 0));
188
  else if (argc == 2) show_tx_bd (strtoul (argv[0], NULL, 0), strtoul (argv[1], NULL, 0));
189 809 simons
  else show_tx_bd (0, 63);
190
  return 0;
191
}
192
 
193
int show_rxbd_cmd (int argc, char *argv[])
194
{
195 855 markom
  if (argc == 1) show_rx_bd (strtoul (argv[0], NULL, 0), strtoul (argv[0], NULL, 0));
196
  else if (argc == 2) show_rx_bd (strtoul (argv[0], NULL, 0), strtoul (argv[1], NULL, 0));
197 809 simons
  else show_rx_bd (0, 63);
198
  return 0;
199
}
200
 
201
int send_packet_cmd (int argc, char *argv[])
202
{
203 855 markom
  if (argc == 1) send_packet(strtoul (argv[0], NULL, 0), 31, 1);
204
  else if (argc == 2) send_packet(strtoul (argv[0], NULL, 0), strtoul (argv[1], NULL, 0), 1);
205
  else if (argc == 3) send_packet(strtoul (argv[0], NULL, 0), strtoul (argv[1], NULL, 0), strtoul (argv[2], NULL, 0));
206 809 simons
  else return -1;
207
  return 0;
208
}
209
 
210
int set_dest_addr_cmd (int argc, char *argv[])
211
{
212
  if (argc == 3) {
213 855 markom
    dest_mac_addr[0] = (strtoul (argv[0], NULL, 0) >> 8) & 0xff;
214
    dest_mac_addr[1] = (strtoul (argv[0], NULL, 0) >> 0) & 0xff;
215
    dest_mac_addr[2] = (strtoul (argv[1], NULL, 0) >> 8) & 0xff;
216
    dest_mac_addr[3] = (strtoul (argv[1], NULL, 0) >> 0) & 0xff;
217
    dest_mac_addr[4] = (strtoul (argv[2], NULL, 0) >> 8) & 0xff;
218
    dest_mac_addr[5] = (strtoul (argv[2], NULL, 0) >> 0) & 0xff;
219 809 simons
  } else return -1;
220
  return 0;
221
}
222
 
223
int init_txbd_pool_cmd (int argc, char *argv[])
224
{
225 855 markom
#if 0
226
  if (argc == 1) init_tx_bd_pool(strtoul (argv[0], NULL, 0));
227 809 simons
  else return -1;
228 855 markom
#endif
229 809 simons
  return 0;
230
}
231
 
232
int init_rxbd_pool_cmd (int argc, char *argv[])
233
{
234 855 markom
  if (argc == 1) init_rx_bd_pool(strtoul (argv[0], NULL, 0));
235 809 simons
  else return -1;
236
  return 0;
237
}
238
 
239
int show_phy_reg_cmd (int argc, char *argv[])
240
{
241 855 markom
  if (argc == 1) show_phy_reg(strtoul (argv[0], NULL, 0), strtoul (argv[0], NULL, 0));
242
  else if (argc == 2) show_phy_reg(strtoul (argv[0], NULL, 0), strtoul (argv[1], NULL, 0));
243 809 simons
  else show_phy_reg(0, 30);
244
  return 0;
245
}
246
 
247
int set_phy_reg_cmd (int argc, char *argv[])
248
{
249 855 markom
  if (argc == 2) set_phy_reg(strtoul (argv[0], NULL, 0), strtoul (argv[1], NULL, 0));
250 809 simons
  else return -1;
251
  return 0;
252
}
253
 
254
int show_mac_regs_cmd (int argc, char *argv[])
255
{
256
  if (argc) return -1;
257
  printf ("\n %08x", ETH_REG_BASE + ETH_MODER);
258 855 markom
  printf (" MODER: %08lx",REG32(ETH_REG_BASE + ETH_MODER));
259 809 simons
 
260
  printf ("\n %08x", ETH_REG_BASE + ETH_INT);
261 855 markom
  printf (" INT: %08lx", REG32(ETH_REG_BASE + ETH_INT));
262 809 simons
 
263
  printf ("\n %08x", ETH_REG_BASE + ETH_INT_MASK);
264 855 markom
  printf (" INT_MASK: %08lx", REG32(ETH_REG_BASE + ETH_INT_MASK));
265 809 simons
 
266
  printf ("\n %08x", ETH_REG_BASE + ETH_IPGT);
267 855 markom
  printf (" IPGT: %08lx", REG32(ETH_REG_BASE + ETH_IPGT));
268 809 simons
 
269
  printf ("\n %08x", ETH_REG_BASE + ETH_IPGR1);
270 855 markom
  printf (" IPGR1: %08lx", REG32(ETH_REG_BASE + ETH_IPGR1));
271 809 simons
 
272
  printf ("\n %08x", ETH_REG_BASE + ETH_IPGR2);
273 855 markom
  printf (" IPGR2: %08lx", REG32(ETH_REG_BASE + ETH_IPGR2));
274 809 simons
 
275
  printf ("\n %08x", ETH_REG_BASE + ETH_PACKETLEN);
276 855 markom
  printf (" PACKETLEN: %08lx", REG32(ETH_REG_BASE + ETH_PACKETLEN));
277 809 simons
 
278
  printf ("\n %08x", ETH_REG_BASE + ETH_COLLCONF);
279 855 markom
  printf (" COLLCONF: %08lx", REG32(ETH_REG_BASE + ETH_COLLCONF));
280 809 simons
 
281
  printf ("\n %08x", ETH_REG_BASE + ETH_RXBD_NUM);
282 855 markom
  printf (" RX_BD_NUM: %08lx", REG32(ETH_REG_BASE + ETH_RXBD_NUM));
283 809 simons
 
284
  printf ("\n %08x", ETH_REG_BASE + ETH_CTRLMODER);
285 855 markom
  printf (" CTRLMODER: %08lx", REG32(ETH_REG_BASE + ETH_CTRLMODER));
286 809 simons
 
287
  printf ("\n %08x", ETH_REG_BASE + ETH_MIIMODER);
288 855 markom
  printf (" MIIMODER: %08lx", REG32(ETH_REG_BASE + ETH_MIIMODER));
289 809 simons
 
290
  printf ("\n %08x", ETH_REG_BASE + ETH_MIICOMMAND);
291 855 markom
  printf (" MIICOMMAND: %08lx", REG32(ETH_REG_BASE + ETH_MIICOMMAND));
292 809 simons
 
293
  printf ("\n %08x", ETH_REG_BASE + ETH_MIIADDRESS);
294 855 markom
  printf (" MIIADDRESS: %08lx", REG32(ETH_REG_BASE + ETH_MIIADDRESS));
295 809 simons
 
296
  printf ("\n %08x", ETH_REG_BASE + ETH_MIITX_DATA);
297 855 markom
  printf (" MIITX_DATA: %08lx", REG32(ETH_REG_BASE + ETH_MIITX_DATA));
298 809 simons
 
299
  printf ("\n %08x", ETH_REG_BASE + ETH_MIIRX_DATA);
300 855 markom
  printf (" MIIRX_DATA: %08lx", REG32(ETH_REG_BASE + ETH_MIIRX_DATA));
301 809 simons
 
302
  printf ("\n %08x", ETH_REG_BASE + ETH_MIISTATUS);
303 855 markom
  printf (" MIISTATUS: %08lx", REG32(ETH_REG_BASE + ETH_MIISTATUS));
304 809 simons
 
305
  printf ("\n %08x", ETH_REG_BASE + ETH_MAC_ADDR0);
306 855 markom
  printf (" MAC_ADDR0: %08lx", REG32(ETH_REG_BASE + ETH_MAC_ADDR0));
307 809 simons
 
308
  printf ("\n %08x", ETH_REG_BASE + ETH_MAC_ADDR1);
309 855 markom
  printf (" MAC_ADDR1: %08lx", REG32(ETH_REG_BASE + ETH_MAC_ADDR1));
310 809 simons
 
311
  printf ("\n %08x", ETH_REG_BASE + ETH_HASH_ADDR0);
312 855 markom
  printf (" ETH_HASH_ADDR0: %08lx", REG32(ETH_REG_BASE + ETH_HASH_ADDR0));
313 809 simons
 
314
  printf ("\n %08x", ETH_REG_BASE + ETH_HASH_ADDR1);
315 855 markom
  printf (" ETH_HASH_ADDR1: %08lx", REG32(ETH_REG_BASE + ETH_HASH_ADDR1));
316 809 simons
 
317
  printf ("\n");
318
  return 0;
319
}
320
 
321
int eth_int_enable_cmd (int argc, char *argv[])
322
{
323
  if (argc) return -1;
324
  eth_int_enable ();
325
  return 0;
326
}
327
int show_rx_buffs_cmd (int argc, char *argv[])
328
{
329
  if (argc == 0) show_rx_buffs(63, 0);
330
  else if (argc == 1) show_rx_buffs(63, 1);
331
  else return -1;
332
  return 0;
333
}
334
 
335
int show_tx_buffs_cmd (int argc, char *argv[])
336
{
337
  if (argc == 0) show_tx_buffs(63);
338
  else return -1;
339
  return 0;
340
}
341 855 markom
#endif
342 809 simons
 
343 1312 jurem
int eth_conf_cmd(int argc, char *argv[])
344
{
345
  switch(argc) {
346
  case 0:
347
    printf("IP: %s", inet_ntoa(global.ip));
348
    printf("\nmask: %s", inet_ntoa(global.mask));
349
    printf("\nGW: %s", inet_ntoa(global.gw_ip));
350
    return 0;
351
  case 3:
352
    global.gw_ip = inet_aton(argv[2]);
353
  case 2:
354
    global.mask = inet_aton(argv[1]);
355
  case 1:
356
    global.ip = inet_aton(argv[0]);
357
    break;
358
  }
359
  printf("Restarting network with new parameters...");
360
  NetStartAgain();
361
 
362
  return 0;
363
}
364
 
365 828 markom
void module_eth_init (void)
366 809 simons
{
367
#if 0
368
  register_command ("eth_init", "",  "init ethernet", eth_init_cmd);
369
  register_command ("show_txbd", "[<start BD>] [<max>]", "show Tx buffer desc", show_txbd_cmd);
370
  register_command ("show_rxbd", "[<start BD>] [<max>]", "show Rx buffer desc", show_rxbd_cmd);
371
  register_command ("send_packet", "<length> [<start data>] [<num_of_packets>]", "create & send packet(s)", send_packet_cmd);
372
  register_command ("set_dest_addr", "<addrhi> <addrmid> <addrlo>", "set destination address (for send_packet)", set_dest_addr_cmd);
373
  register_command ("init_txbd_pool", "<max>", "initialize Tx buffer descriptors", init_txbd_pool_cmd);
374
  register_command ("init_rxbd_pool", "<max>", "initialize Rx buffer descriptors", init_rxbd_pool_cmd);
375
  register_command ("show_phy_reg", "[<start_addr>] [<end addr>]", "show PHY registers", show_phy_reg_cmd);
376
  register_command ("set_phy_reg", "<addr> <value>", "set PHY register", set_phy_reg_cmd);
377
  register_command ("show_mac_regs", "", "show all MAC registers", show_mac_regs_cmd);
378
  register_command ("eth_int_enable", "", "enable ethernet interrupt", eth_int_enable_cmd);
379
  register_command ("show_rx_buffs", "[<show_all>]", "show receive buffers (optional arg will also show empty buffers)", show_rx_buffs_cmd);
380
  register_command ("show_tx_buffs", "", "show transmit buffers", show_rx_buffs_cmd);
381 1312 jurem
#endif
382 809 simons
  /* Initialize controller */
383 1312 jurem
  register_command ("eth_conf", "[<ip> [<mask> [<gw>]]]", "Get/set ethernet configuration", eth_conf_cmd);
384
#if 0
385 855 markom
  eth_init();
386
  printf ("Ethernet not initialized (run eth_init command)\n");
387
  init_rx_bd_pool(0);
388
  init_tx_bd_pool(3);
389 809 simons
#endif
390
}
391 855 markom
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.