iPXE
phantom.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2008 Michael Brown <mbrown@fensystems.co.uk>.
3 * Copyright (C) 2008 NetXen, Inc.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA.
19 *
20 * You can also choose to distribute this program under the terms of
21 * the Unmodified Binary Distribution Licence (as given in the file
22 * COPYING.UBDL), provided that you have satisfied its requirements.
23 */
24
25FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
26
27#include <stdint.h>
28#include <stdlib.h>
29#include <string.h>
30#include <unistd.h>
31#include <errno.h>
32#include <assert.h>
33#include <byteswap.h>
34#include <ipxe/pci.h>
35#include <ipxe/io.h>
36#include <ipxe/malloc.h>
37#include <ipxe/iobuf.h>
38#include <ipxe/netdevice.h>
39#include <ipxe/if_ether.h>
40#include <ipxe/ethernet.h>
41#include <ipxe/spi.h>
42#include <ipxe/settings.h>
43#include "phantom.h"
44
45/**
46 * @file
47 *
48 * NetXen Phantom NICs
49 *
50 */
51
52/** Maximum number of ports */
53#define PHN_MAX_NUM_PORTS 8
54
55/** Maximum time to wait for command PEG to initialise
56 *
57 * BUGxxxx
58 *
59 * The command PEG will currently report initialisation complete only
60 * when at least one PHY has detected a link (so that the global PHY
61 * clock can be set to 10G/1G as appropriate). This can take a very,
62 * very long time.
63 *
64 * A future firmware revision should decouple PHY initialisation from
65 * firmware initialisation, at which point the command PEG will report
66 * initialisation complete much earlier, and this timeout can be
67 * reduced.
68 */
69#define PHN_CMDPEG_INIT_TIMEOUT_SEC 50
70
71/** Maximum time to wait for receive PEG to initialise */
72#define PHN_RCVPEG_INIT_TIMEOUT_SEC 2
73
74/** Maximum time to wait for firmware to accept a command */
75#define PHN_ISSUE_CMD_TIMEOUT_MS 2000
76
77/** Maximum time to wait for test memory */
78#define PHN_TEST_MEM_TIMEOUT_MS 100
79
80/** Maximum time to wait for CLP command to be issued */
81#define PHN_CLP_CMD_TIMEOUT_MS 500
82
83/** Link state poll frequency
84 *
85 * The link state will be checked once in every N calls to poll().
86 */
87#define PHN_LINK_POLL_FREQUENCY 4096
88
89/** Number of RX descriptors */
90#define PHN_NUM_RDS 32
91
92/** RX maximum fill level. Must be strictly less than PHN_NUM_RDS. */
93#define PHN_RDS_MAX_FILL 16
94
95/** RX buffer size */
96#define PHN_RX_BUFSIZE ( 32 /* max LL padding added by card */ + \
97 ETH_FRAME_LEN )
98
99/** Number of RX status descriptors */
100#define PHN_NUM_SDS 32
101
102/** Number of TX descriptors */
103#define PHN_NUM_CDS 8
104
105/** A Phantom descriptor ring set */
107 /** RX descriptors */
109 /** RX status descriptors */
111 /** TX descriptors */
113 /** TX consumer index */
115};
116
117/** RX context creation request and response buffers */
130
131/** TX context creation request and response buffers */
140
141/** A Phantom NIC */
143 /** BAR 0 */
144 void *bar0;
145 /** Current CRB window */
146 unsigned long crb_window;
147 /** CRB window access method */
148 unsigned long ( *crb_access ) ( struct phantom_nic *phantom,
149 unsigned long reg );
150
151
152 /** Port number */
153 unsigned int port;
154
155
156 /** RX context ID */
158 /** RX descriptor producer CRB offset */
159 unsigned long rds_producer_crb;
160 /** RX status descriptor consumer CRB offset */
161 unsigned long sds_consumer_crb;
162 /** RX interrupt mask CRB offset */
163 unsigned long sds_irq_mask_crb;
164 /** RX interrupts enabled */
165 unsigned int sds_irq_enabled;
166
167 /** RX producer index */
168 unsigned int rds_producer_idx;
169 /** RX consumer index */
170 unsigned int rds_consumer_idx;
171 /** RX status consumer index */
172 unsigned int sds_consumer_idx;
173 /** RX I/O buffers */
175
176
177 /** TX context ID */
179 /** TX descriptor producer CRB offset */
180 unsigned long cds_producer_crb;
181
182 /** TX producer index */
183 unsigned int cds_producer_idx;
184 /** TX consumer index */
185 unsigned int cds_consumer_idx;
186 /** TX I/O buffers */
188
189
190 /** Descriptor rings */
192
193
194 /** Last known link state */
196 /** Link state poll timer */
197 unsigned long link_poll_timer;
198
199
200 /** Non-volatile settings */
202};
203
204/** Interrupt mask registers */
215
216/** Interrupt status registers */
227
228/***************************************************************************
229 *
230 * CRB register access
231 *
232 */
233
234/**
235 * Prepare for access to CRB register via 128MB BAR
236 *
237 * @v phantom Phantom NIC
238 * @v reg Register offset within abstract address space
239 * @ret offset Register offset within PCI BAR0
240 */
241static unsigned long phantom_crb_access_128m ( struct phantom_nic *phantom,
242 unsigned long reg ) {
243 unsigned long offset = ( 0x6000000 + ( reg & 0x1ffffff ) );
244 uint32_t window = ( reg & 0x2000000 );
245 uint32_t verify_window;
246
247 if ( phantom->crb_window != window ) {
248
249 /* Write to the CRB window register */
250 writel ( window, phantom->bar0 + UNM_128M_CRB_WINDOW );
251
252 /* Ensure that the write has reached the card */
253 verify_window = readl ( phantom->bar0 + UNM_128M_CRB_WINDOW );
254 assert ( verify_window == window );
255
256 /* Record new window */
257 phantom->crb_window = window;
258 }
259
260 return offset;
261}
262
263/**
264 * Prepare for access to CRB register via 32MB BAR
265 *
266 * @v phantom Phantom NIC
267 * @v reg Register offset within abstract address space
268 * @ret offset Register offset within PCI BAR0
269 */
270static unsigned long phantom_crb_access_32m ( struct phantom_nic *phantom,
271 unsigned long reg ) {
272 unsigned long offset = ( reg & 0x1ffffff );
273 uint32_t window = ( reg & 0x2000000 );
274 uint32_t verify_window;
275
276 if ( phantom->crb_window != window ) {
277
278 /* Write to the CRB window register */
279 writel ( window, phantom->bar0 + UNM_32M_CRB_WINDOW );
280
281 /* Ensure that the write has reached the card */
282 verify_window = readl ( phantom->bar0 + UNM_32M_CRB_WINDOW );
283 assert ( verify_window == window );
284
285 /* Record new window */
286 phantom->crb_window = window;
287 }
288
289 return offset;
290}
291
292/**
293 * Prepare for access to CRB register via 2MB BAR
294 *
295 * @v phantom Phantom NIC
296 * @v reg Register offset within abstract address space
297 * @ret offset Register offset within PCI BAR0
298 */
299static unsigned long phantom_crb_access_2m ( struct phantom_nic *phantom,
300 unsigned long reg ) {
301 static const struct {
303 uint16_t window_hi;
304 } reg_window_hi[] = {
305 { UNM_CRB_BLK_PCIE, 0x773 },
306 { UNM_CRB_BLK_CAM, 0x416 },
307 { UNM_CRB_BLK_ROMUSB, 0x421 },
308 { UNM_CRB_BLK_TEST, 0x295 },
309 { UNM_CRB_BLK_PEG_0, 0x340 },
310 { UNM_CRB_BLK_PEG_1, 0x341 },
311 { UNM_CRB_BLK_PEG_2, 0x342 },
312 { UNM_CRB_BLK_PEG_3, 0x343 },
313 { UNM_CRB_BLK_PEG_4, 0x34b },
314 };
315 unsigned int block = UNM_CRB_BLK ( reg );
316 unsigned long offset = UNM_CRB_OFFSET ( reg );
317 uint32_t window;
318 uint32_t verify_window;
319 unsigned int i;
320
321 for ( i = 0 ; i < ( sizeof ( reg_window_hi ) /
322 sizeof ( reg_window_hi[0] ) ) ; i++ ) {
323
324 if ( reg_window_hi[i].block != block )
325 continue;
326
327 window = ( ( reg_window_hi[i].window_hi << 20 ) |
328 ( offset & 0x000f0000 ) );
329
330 if ( phantom->crb_window != window ) {
331
332 /* Write to the CRB window register */
333 writel ( window, phantom->bar0 + UNM_2M_CRB_WINDOW );
334
335 /* Ensure that the write has reached the card */
336 verify_window = readl ( phantom->bar0 +
338 assert ( verify_window == window );
339
340 /* Record new window */
341 phantom->crb_window = window;
342 }
343
344 return ( 0x1e0000 + ( offset & 0xffff ) );
345 }
346
347 assert ( 0 );
348 return 0;
349}
350
351/**
352 * Read from Phantom CRB register
353 *
354 * @v phantom Phantom NIC
355 * @v reg Register offset within abstract address space
356 * @ret value Register value
357 */
358static uint32_t phantom_readl ( struct phantom_nic *phantom,
359 unsigned long reg ) {
360 unsigned long offset;
361
362 offset = phantom->crb_access ( phantom, reg );
363 return readl ( phantom->bar0 + offset );
364}
365
366/**
367 * Write to Phantom CRB register
368 *
369 * @v phantom Phantom NIC
370 * @v value Register value
371 * @v reg Register offset within abstract address space
372 */
373static void phantom_writel ( struct phantom_nic *phantom, uint32_t value,
374 unsigned long reg ) {
375 unsigned long offset;
376
377 offset = phantom->crb_access ( phantom, reg );
378 writel ( value, phantom->bar0 + offset );
379}
380
381/**
382 * Write to Phantom CRB HI/LO register pair
383 *
384 * @v phantom Phantom NIC
385 * @v value Register value
386 * @v lo_offset LO register offset within CRB
387 * @v hi_offset HI register offset within CRB
388 */
389static inline void phantom_write_hilo ( struct phantom_nic *phantom,
391 unsigned long lo_offset,
392 unsigned long hi_offset ) {
393 uint32_t lo = ( value & 0xffffffffUL );
394 uint32_t hi = ( value >> 32 );
395
396 phantom_writel ( phantom, lo, lo_offset );
397 phantom_writel ( phantom, hi, hi_offset );
398}
399
400/***************************************************************************
401 *
402 * Firmware message buffer access (for debug)
403 *
404 */
405
406/**
407 * Read from Phantom test memory
408 *
409 * @v phantom Phantom NIC
410 * @v offset Offset within test memory
411 * @v buf 8-byte buffer to fill
412 * @ret rc Return status code
413 */
414static int phantom_read_test_mem_block ( struct phantom_nic *phantom,
415 unsigned long offset,
416 uint32_t buf[2] ) {
417 unsigned int retries;
418 uint32_t test_control;
419
423 phantom_writel ( phantom,
426
427 for ( retries = 0 ; retries < PHN_TEST_MEM_TIMEOUT_MS ; retries++ ) {
428 test_control = phantom_readl ( phantom, UNM_TEST_CONTROL );
429 if ( ( test_control & UNM_TEST_CONTROL_BUSY ) == 0 ) {
430 buf[0] = phantom_readl ( phantom, UNM_TEST_RDDATA_LO );
431 buf[1] = phantom_readl ( phantom, UNM_TEST_RDDATA_HI );
432 return 0;
433 }
434 mdelay ( 1 );
435 }
436
437 DBGC ( phantom, "Phantom %p timed out waiting for test memory\n",
438 phantom );
439 return -ETIMEDOUT;
440}
441
442/**
443 * Read single byte from Phantom test memory
444 *
445 * @v phantom Phantom NIC
446 * @v offset Offset within test memory
447 * @ret byte Byte read, or negative error
448 */
449static int phantom_read_test_mem ( struct phantom_nic *phantom,
450 unsigned long offset ) {
451 static union {
452 uint8_t bytes[8];
453 uint32_t dwords[2];
454 } cache;
455 static unsigned long cache_offset = -1UL;
456 unsigned long sub_offset;
457 int rc;
458
459 sub_offset = ( offset & ( sizeof ( cache ) - 1 ) );
460 offset = ( offset & ~( sizeof ( cache ) - 1 ) );
461
462 if ( cache_offset != offset ) {
463 if ( ( rc = phantom_read_test_mem_block ( phantom, offset,
464 cache.dwords )) !=0 )
465 return rc;
466 cache_offset = offset;
467 }
468
469 return cache.bytes[sub_offset];
470}
471
472/**
473 * Dump Phantom firmware dmesg log
474 *
475 * @v phantom Phantom NIC
476 * @v log Log number
477 * @v max_lines Maximum number of lines to show, or -1 to show all
478 * @ret rc Return status code
479 */
480static int phantom_dmesg ( struct phantom_nic *phantom, unsigned int log,
481 unsigned int max_lines ) {
483 uint32_t tail;
486 int byte;
487
488 /* Optimise out for non-debug builds */
489 if ( ! DBG_LOG )
490 return 0;
491
492 /* Locate log */
493 head = phantom_readl ( phantom, UNM_CAM_RAM_DMESG_HEAD ( log ) );
494 tail = phantom_readl ( phantom, UNM_CAM_RAM_DMESG_TAIL ( log ) );
495 sig = phantom_readl ( phantom, UNM_CAM_RAM_DMESG_SIG ( log ) );
496 DBGC ( phantom, "Phantom %p firmware dmesg buffer %d (%08x-%08x)\n",
497 phantom, log, head, tail );
498 assert ( ( head & 0x07 ) == 0 );
500 DBGC ( phantom, "Warning: bad signature %08x (want %08lx)\n",
502 }
503
504 /* Locate start of last (max_lines) lines */
505 for ( offset = tail ; offset > head ; offset-- ) {
506 if ( ( byte = phantom_read_test_mem ( phantom,
507 ( offset - 1 ) ) ) < 0 )
508 return byte;
509 if ( ( byte == '\n' ) && ( max_lines-- == 0 ) )
510 break;
511 }
512
513 /* Print lines */
514 for ( ; offset < tail ; offset++ ) {
515 if ( ( byte = phantom_read_test_mem ( phantom, offset ) ) < 0 )
516 return byte;
517 DBG ( "%c", byte );
518 }
519 DBG ( "\n" );
520 return 0;
521}
522
523/**
524 * Dump Phantom firmware dmesg logs
525 *
526 * @v phantom Phantom NIC
527 * @v max_lines Maximum number of lines to show, or -1 to show all
528 */
529static void __attribute__ (( unused ))
530phantom_dmesg_all ( struct phantom_nic *phantom, unsigned int max_lines ) {
531 unsigned int i;
532
533 for ( i = 0 ; i < UNM_CAM_RAM_NUM_DMESG_BUFFERS ; i++ )
534 phantom_dmesg ( phantom, i, max_lines );
535}
536
537/***************************************************************************
538 *
539 * Firmware interface
540 *
541 */
542
543/**
544 * Wait for firmware to accept command
545 *
546 * @v phantom Phantom NIC
547 * @ret rc Return status code
548 */
549static int phantom_wait_for_cmd ( struct phantom_nic *phantom ) {
550 unsigned int retries;
551 uint32_t cdrp;
552
553 for ( retries = 0 ; retries < PHN_ISSUE_CMD_TIMEOUT_MS ; retries++ ) {
554 mdelay ( 1 );
555 cdrp = phantom_readl ( phantom, UNM_NIC_REG_NX_CDRP );
556 if ( NX_CDRP_IS_RSP ( cdrp ) ) {
557 switch ( NX_CDRP_FORM_RSP ( cdrp ) ) {
558 case NX_CDRP_RSP_OK:
559 return 0;
560 case NX_CDRP_RSP_FAIL:
561 return -EIO;
563 return -ETIMEDOUT;
564 default:
565 return -EPROTO;
566 }
567 }
568 }
569
570 DBGC ( phantom, "Phantom %p timed out waiting for firmware to accept "
571 "command\n", phantom );
572 return -ETIMEDOUT;
573}
574
575/**
576 * Issue command to firmware
577 *
578 * @v phantom Phantom NIC
579 * @v command Firmware command
580 * @v arg1 Argument 1
581 * @v arg2 Argument 2
582 * @v arg3 Argument 3
583 * @ret rc Return status code
584 */
585static int phantom_issue_cmd ( struct phantom_nic *phantom,
587 uint32_t arg3 ) {
589 int rc;
590
591 /* Issue command */
594 DBGC2 ( phantom, "Phantom %p issuing command %08x (%08x, %08x, "
595 "%08x)\n", phantom, command, arg1, arg2, arg3 );
602
603 /* Wait for command to be accepted */
604 if ( ( rc = phantom_wait_for_cmd ( phantom ) ) != 0 ) {
605 DBGC ( phantom, "Phantom %p could not issue command: %s\n",
606 phantom, strerror ( rc ) );
607 return rc;
608 }
609
610 return 0;
611}
612
613/**
614 * Issue buffer-format command to firmware
615 *
616 * @v phantom Phantom NIC
617 * @v command Firmware command
618 * @v buffer Buffer to pass to firmware
619 * @v len Length of buffer
620 * @ret rc Return status code
621 */
622static int phantom_issue_buf_cmd ( struct phantom_nic *phantom,
623 uint32_t command, void *buffer,
624 size_t len ) {
625 uint64_t physaddr;
626
627 physaddr = virt_to_bus ( buffer );
628 return phantom_issue_cmd ( phantom, command, ( physaddr >> 32 ),
629 ( physaddr & 0xffffffffUL ), len );
630}
631
632/**
633 * Create Phantom RX context
634 *
635 * @v phantom Phantom NIC
636 * @ret rc Return status code
637 */
638static int phantom_create_rx_ctx ( struct phantom_nic *phantom ) {
639 struct phantom_create_rx_ctx_rqrsp *buf;
640 int rc;
641
642 /* Allocate context creation buffer */
643 buf = malloc_phys ( sizeof ( *buf ), UNM_DMA_BUFFER_ALIGN );
644 if ( ! buf ) {
645 rc = -ENOMEM;
646 goto out;
647 }
648 memset ( buf, 0, sizeof ( *buf ) );
649
650 /* Prepare request */
652 cpu_to_le64 ( virt_to_bus ( &buf->cardrsp ) );
653 buf->hostrq.rx_ctx.capabilities[0] =
661 cpu_to_le32 ( sizeof ( buf->hostrq.rds ) );
665 cpu_to_le64 ( virt_to_bus ( phantom->desc->rds ) );
670 cpu_to_le64 ( virt_to_bus ( phantom->desc->sds ) );
672
673 DBGC ( phantom, "Phantom %p creating RX context\n", phantom );
674 DBGC2_HDA ( phantom, virt_to_bus ( &buf->hostrq ),
675 &buf->hostrq, sizeof ( buf->hostrq ) );
676
677 /* Issue request */
678 if ( ( rc = phantom_issue_buf_cmd ( phantom,
680 &buf->hostrq,
681 sizeof ( buf->hostrq ) ) ) != 0 ) {
682 DBGC ( phantom, "Phantom %p could not create RX context: "
683 "%s\n", phantom, strerror ( rc ) );
684 DBGC ( phantom, "Request:\n" );
685 DBGC_HDA ( phantom, virt_to_bus ( &buf->hostrq ),
686 &buf->hostrq, sizeof ( buf->hostrq ) );
687 DBGC ( phantom, "Response:\n" );
688 DBGC_HDA ( phantom, virt_to_bus ( &buf->cardrsp ),
689 &buf->cardrsp, sizeof ( buf->cardrsp ) );
690 goto out;
691 }
692
693 /* Retrieve context parameters */
694 phantom->rx_context_id =
695 le16_to_cpu ( buf->cardrsp.rx_ctx.context_id );
696 phantom->rds_producer_crb =
697 ( UNM_CAM_RAM +
698 le32_to_cpu ( buf->cardrsp.rds.host_producer_crb ) );
699 phantom->sds_consumer_crb =
700 ( UNM_CAM_RAM +
701 le32_to_cpu ( buf->cardrsp.sds.host_consumer_crb ) );
702 phantom->sds_irq_mask_crb =
703 ( UNM_CAM_RAM +
704 le32_to_cpu ( buf->cardrsp.sds.interrupt_crb ) );
705
706 DBGC ( phantom, "Phantom %p created RX context (id %04x, port phys "
707 "%02x virt %02x)\n", phantom, phantom->rx_context_id,
708 buf->cardrsp.rx_ctx.phys_port, buf->cardrsp.rx_ctx.virt_port );
709 DBGC2_HDA ( phantom, virt_to_bus ( &buf->cardrsp ),
710 &buf->cardrsp, sizeof ( buf->cardrsp ) );
711 DBGC ( phantom, "Phantom %p RDS producer CRB is %08lx\n",
712 phantom, phantom->rds_producer_crb );
713 DBGC ( phantom, "Phantom %p SDS consumer CRB is %08lx\n",
714 phantom, phantom->sds_consumer_crb );
715 DBGC ( phantom, "Phantom %p SDS interrupt mask CRB is %08lx\n",
716 phantom, phantom->sds_irq_mask_crb );
717
718 out:
719 free_phys ( buf, sizeof ( *buf ) );
720 return rc;
721}
722
723/**
724 * Destroy Phantom RX context
725 *
726 * @v phantom Phantom NIC
727 * @ret rc Return status code
728 */
729static void phantom_destroy_rx_ctx ( struct phantom_nic *phantom ) {
730 int rc;
731
732 DBGC ( phantom, "Phantom %p destroying RX context (id %04x)\n",
733 phantom, phantom->rx_context_id );
734
735 /* Issue request */
736 if ( ( rc = phantom_issue_cmd ( phantom,
738 phantom->rx_context_id,
739 NX_DESTROY_CTX_RESET, 0 ) ) != 0 ) {
740 DBGC ( phantom, "Phantom %p could not destroy RX context: "
741 "%s\n", phantom, strerror ( rc ) );
742 /* We're probably screwed */
743 return;
744 }
745
746 /* Clear context parameters */
747 phantom->rx_context_id = 0;
748 phantom->rds_producer_crb = 0;
749 phantom->sds_consumer_crb = 0;
750
751 /* Reset software counters */
752 phantom->rds_producer_idx = 0;
753 phantom->rds_consumer_idx = 0;
754 phantom->sds_consumer_idx = 0;
755}
756
757/**
758 * Create Phantom TX context
759 *
760 * @v phantom Phantom NIC
761 * @ret rc Return status code
762 */
763static int phantom_create_tx_ctx ( struct phantom_nic *phantom ) {
764 struct phantom_create_tx_ctx_rqrsp *buf;
765 int rc;
766
767 /* Allocate context creation buffer */
768 buf = malloc_phys ( sizeof ( *buf ), UNM_DMA_BUFFER_ALIGN );
769 if ( ! buf ) {
770 rc = -ENOMEM;
771 goto out;
772 }
773 memset ( buf, 0, sizeof ( *buf ) );
774
775 /* Prepare request */
777 cpu_to_le64 ( virt_to_bus ( &buf->cardrsp ) );
779 cpu_to_le64 ( virt_to_bus ( &phantom->desc->cmd_cons ) );
780 buf->hostrq.tx_ctx.capabilities[0] =
785 cpu_to_le64 ( virt_to_bus ( phantom->desc->cds ) );
787
788 DBGC ( phantom, "Phantom %p creating TX context\n", phantom );
789 DBGC2_HDA ( phantom, virt_to_bus ( &buf->hostrq ),
790 &buf->hostrq, sizeof ( buf->hostrq ) );
791
792 /* Issue request */
793 if ( ( rc = phantom_issue_buf_cmd ( phantom,
795 &buf->hostrq,
796 sizeof ( buf->hostrq ) ) ) != 0 ) {
797 DBGC ( phantom, "Phantom %p could not create TX context: "
798 "%s\n", phantom, strerror ( rc ) );
799 DBGC ( phantom, "Request:\n" );
800 DBGC_HDA ( phantom, virt_to_bus ( &buf->hostrq ),
801 &buf->hostrq, sizeof ( buf->hostrq ) );
802 DBGC ( phantom, "Response:\n" );
803 DBGC_HDA ( phantom, virt_to_bus ( &buf->cardrsp ),
804 &buf->cardrsp, sizeof ( buf->cardrsp ) );
805 goto out;
806 }
807
808 /* Retrieve context parameters */
809 phantom->tx_context_id =
810 le16_to_cpu ( buf->cardrsp.tx_ctx.context_id );
811 phantom->cds_producer_crb =
812 ( UNM_CAM_RAM +
813 le32_to_cpu(buf->cardrsp.tx_ctx.cds_ring.host_producer_crb));
814
815 DBGC ( phantom, "Phantom %p created TX context (id %04x, port phys "
816 "%02x virt %02x)\n", phantom, phantom->tx_context_id,
817 buf->cardrsp.tx_ctx.phys_port, buf->cardrsp.tx_ctx.virt_port );
818 DBGC2_HDA ( phantom, virt_to_bus ( &buf->cardrsp ),
819 &buf->cardrsp, sizeof ( buf->cardrsp ) );
820 DBGC ( phantom, "Phantom %p CDS producer CRB is %08lx\n",
821 phantom, phantom->cds_producer_crb );
822
823 out:
824 free_phys ( buf, sizeof ( *buf ) );
825 return rc;
826}
827
828/**
829 * Destroy Phantom TX context
830 *
831 * @v phantom Phantom NIC
832 * @ret rc Return status code
833 */
834static void phantom_destroy_tx_ctx ( struct phantom_nic *phantom ) {
835 int rc;
836
837 DBGC ( phantom, "Phantom %p destroying TX context (id %04x)\n",
838 phantom, phantom->tx_context_id );
839
840 /* Issue request */
841 if ( ( rc = phantom_issue_cmd ( phantom,
843 phantom->tx_context_id,
844 NX_DESTROY_CTX_RESET, 0 ) ) != 0 ) {
845 DBGC ( phantom, "Phantom %p could not destroy TX context: "
846 "%s\n", phantom, strerror ( rc ) );
847 /* We're probably screwed */
848 return;
849 }
850
851 /* Clear context parameters */
852 phantom->tx_context_id = 0;
853 phantom->cds_producer_crb = 0;
854
855 /* Reset software counters */
856 phantom->cds_producer_idx = 0;
857 phantom->cds_consumer_idx = 0;
858}
859
860/***************************************************************************
861 *
862 * Descriptor ring management
863 *
864 */
865
866/**
867 * Allocate Phantom RX descriptor
868 *
869 * @v phantom Phantom NIC
870 * @ret index RX descriptor index, or negative error
871 */
872static int phantom_alloc_rds ( struct phantom_nic *phantom ) {
873 unsigned int rds_producer_idx;
874 unsigned int next_rds_producer_idx;
875
876 /* Check for space in the ring. RX descriptors are consumed
877 * out of order, but they are *read* by the hardware in strict
878 * order. We maintain a pessimistic consumer index, which is
879 * guaranteed never to be an overestimate of the number of
880 * descriptors read by the hardware.
881 */
882 rds_producer_idx = phantom->rds_producer_idx;
883 next_rds_producer_idx = ( ( rds_producer_idx + 1 ) % PHN_NUM_RDS );
884 if ( next_rds_producer_idx == phantom->rds_consumer_idx ) {
885 DBGC ( phantom, "Phantom %p RDS ring full (index %d not "
886 "consumed)\n", phantom, next_rds_producer_idx );
887 return -ENOBUFS;
888 }
889
890 return rds_producer_idx;
891}
892
893/**
894 * Post Phantom RX descriptor
895 *
896 * @v phantom Phantom NIC
897 * @v rds RX descriptor
898 */
899static void phantom_post_rds ( struct phantom_nic *phantom,
900 struct phantom_rds *rds ) {
901 unsigned int rds_producer_idx;
902 unsigned int next_rds_producer_idx;
903 struct phantom_rds *entry;
904
905 /* Copy descriptor to ring */
906 rds_producer_idx = phantom->rds_producer_idx;
907 entry = &phantom->desc->rds[rds_producer_idx];
908 memcpy ( entry, rds, sizeof ( *entry ) );
909 DBGC2 ( phantom, "Phantom %p posting RDS %ld (slot %d):\n",
910 phantom, NX_GET ( rds, handle ), rds_producer_idx );
911 DBGC2_HDA ( phantom, virt_to_bus ( entry ), entry, sizeof ( *entry ) );
912
913 /* Update producer index */
914 next_rds_producer_idx = ( ( rds_producer_idx + 1 ) % PHN_NUM_RDS );
915 phantom->rds_producer_idx = next_rds_producer_idx;
916 wmb();
917 phantom_writel ( phantom, phantom->rds_producer_idx,
918 phantom->rds_producer_crb );
919}
920
921/**
922 * Allocate Phantom TX descriptor
923 *
924 * @v phantom Phantom NIC
925 * @ret index TX descriptor index, or negative error
926 */
927static int phantom_alloc_cds ( struct phantom_nic *phantom ) {
928 unsigned int cds_producer_idx;
929 unsigned int next_cds_producer_idx;
930
931 /* Check for space in the ring. TX descriptors are consumed
932 * in strict order, so we just check for a collision against
933 * the consumer index.
934 */
935 cds_producer_idx = phantom->cds_producer_idx;
936 next_cds_producer_idx = ( ( cds_producer_idx + 1 ) % PHN_NUM_CDS );
937 if ( next_cds_producer_idx == phantom->cds_consumer_idx ) {
938 DBGC ( phantom, "Phantom %p CDS ring full (index %d not "
939 "consumed)\n", phantom, next_cds_producer_idx );
940 return -ENOBUFS;
941 }
942
943 return cds_producer_idx;
944}
945
946/**
947 * Post Phantom TX descriptor
948 *
949 * @v phantom Phantom NIC
950 * @v cds TX descriptor
951 */
952static void phantom_post_cds ( struct phantom_nic *phantom,
953 union phantom_cds *cds ) {
954 unsigned int cds_producer_idx;
955 unsigned int next_cds_producer_idx;
956 union phantom_cds *entry;
957
958 /* Copy descriptor to ring */
959 cds_producer_idx = phantom->cds_producer_idx;
960 entry = &phantom->desc->cds[cds_producer_idx];
961 memcpy ( entry, cds, sizeof ( *entry ) );
962 DBGC2 ( phantom, "Phantom %p posting CDS %d:\n",
963 phantom, cds_producer_idx );
964 DBGC2_HDA ( phantom, virt_to_bus ( entry ), entry, sizeof ( *entry ) );
965
966 /* Update producer index */
967 next_cds_producer_idx = ( ( cds_producer_idx + 1 ) % PHN_NUM_CDS );
968 phantom->cds_producer_idx = next_cds_producer_idx;
969 wmb();
970 phantom_writel ( phantom, phantom->cds_producer_idx,
971 phantom->cds_producer_crb );
972}
973
974/***************************************************************************
975 *
976 * MAC address management
977 *
978 */
979
980/**
981 * Add/remove MAC address
982 *
983 * @v phantom Phantom NIC
984 * @v ll_addr MAC address to add or remove
985 * @v opcode MAC request opcode
986 * @ret rc Return status code
987 */
988static int phantom_update_macaddr ( struct phantom_nic *phantom,
989 const uint8_t *ll_addr,
990 unsigned int opcode ) {
991 union phantom_cds cds;
992 int index;
993
994 /* Get descriptor ring entry */
995 index = phantom_alloc_cds ( phantom );
996 if ( index < 0 )
997 return index;
998
999 /* Fill descriptor ring entry */
1000 memset ( &cds, 0, sizeof ( cds ) );
1001 NX_FILL_1 ( &cds, 0,
1002 nic_request.common.opcode, UNM_NIC_REQUEST );
1003 NX_FILL_2 ( &cds, 1,
1004 nic_request.header.opcode, UNM_MAC_EVENT,
1005 nic_request.header.context_id, phantom->port );
1006 NX_FILL_7 ( &cds, 2,
1007 nic_request.body.mac_request.opcode, opcode,
1008 nic_request.body.mac_request.mac_addr_0, ll_addr[0],
1009 nic_request.body.mac_request.mac_addr_1, ll_addr[1],
1010 nic_request.body.mac_request.mac_addr_2, ll_addr[2],
1011 nic_request.body.mac_request.mac_addr_3, ll_addr[3],
1012 nic_request.body.mac_request.mac_addr_4, ll_addr[4],
1013 nic_request.body.mac_request.mac_addr_5, ll_addr[5] );
1014
1015 /* Post descriptor */
1016 phantom_post_cds ( phantom, &cds );
1017
1018 return 0;
1019}
1020
1021/**
1022 * Add MAC address
1023 *
1024 * @v phantom Phantom NIC
1025 * @v ll_addr MAC address to add or remove
1026 * @ret rc Return status code
1027 */
1028static inline int phantom_add_macaddr ( struct phantom_nic *phantom,
1029 const uint8_t *ll_addr ) {
1030
1031 DBGC ( phantom, "Phantom %p adding MAC address %s\n",
1032 phantom, eth_ntoa ( ll_addr ) );
1033
1034 return phantom_update_macaddr ( phantom, ll_addr, UNM_MAC_ADD );
1035}
1036
1037/**
1038 * Remove MAC address
1039 *
1040 * @v phantom Phantom NIC
1041 * @v ll_addr MAC address to add or remove
1042 * @ret rc Return status code
1043 */
1044static inline int phantom_del_macaddr ( struct phantom_nic *phantom,
1045 const uint8_t *ll_addr ) {
1046
1047 DBGC ( phantom, "Phantom %p removing MAC address %s\n",
1048 phantom, eth_ntoa ( ll_addr ) );
1049
1050 return phantom_update_macaddr ( phantom, ll_addr, UNM_MAC_DEL );
1051}
1052
1053/***************************************************************************
1054 *
1055 * Link state detection
1056 *
1057 */
1058
1059/**
1060 * Poll link state
1061 *
1062 * @v netdev Network device
1063 */
1065 struct phantom_nic *phantom = netdev->priv;
1066 uint32_t xg_state_p3;
1067 unsigned int link;
1068
1069 /* Read link state */
1070 xg_state_p3 = phantom_readl ( phantom, UNM_NIC_REG_XG_STATE_P3 );
1071
1072 /* If there is no change, do nothing */
1073 if ( phantom->link_state == xg_state_p3 )
1074 return;
1075
1076 /* Record new link state */
1077 DBGC ( phantom, "Phantom %p new link state %08x (was %08x)\n",
1078 phantom, xg_state_p3, phantom->link_state );
1079 phantom->link_state = xg_state_p3;
1080
1081 /* Indicate link state to iPXE */
1083 phantom->link_state );
1084 switch ( link ) {
1086 DBGC ( phantom, "Phantom %p link is up\n", phantom );
1088 break;
1090 DBGC ( phantom, "Phantom %p link is down\n", phantom );
1092 break;
1093 default:
1094 DBGC ( phantom, "Phantom %p bad link state %d\n",
1095 phantom, link );
1096 break;
1097 }
1098}
1099
1100/***************************************************************************
1101 *
1102 * Main driver body
1103 *
1104 */
1105
1106/**
1107 * Refill descriptor ring
1108 *
1109 * @v netdev Net device
1110 */
1112 struct phantom_nic *phantom = netdev->priv;
1113 struct io_buffer *iobuf;
1114 struct phantom_rds rds;
1115 unsigned int handle;
1116 int index;
1117
1118 for ( handle = 0 ; handle < PHN_RDS_MAX_FILL ; handle++ ) {
1119
1120 /* Skip this index if the descriptor has not yet been
1121 * consumed.
1122 */
1123 if ( phantom->rds_iobuf[handle] != NULL )
1124 continue;
1125
1126 /* Allocate descriptor ring entry */
1127 index = phantom_alloc_rds ( phantom );
1129 assert ( index >= 0 ); /* Guaranteed by MAX_FILL < NUM_RDS ) */
1130
1131 /* Try to allocate an I/O buffer */
1132 iobuf = alloc_iob ( PHN_RX_BUFSIZE );
1133 if ( ! iobuf ) {
1134 /* Failure is non-fatal; we will retry later */
1136 break;
1137 }
1138
1139 /* Fill descriptor ring entry */
1140 memset ( &rds, 0, sizeof ( rds ) );
1141 NX_FILL_2 ( &rds, 0,
1142 handle, handle,
1143 length, iob_len ( iobuf ) );
1144 NX_FILL_1 ( &rds, 1,
1145 dma_addr, virt_to_bus ( iobuf->data ) );
1146
1147 /* Record I/O buffer */
1148 assert ( phantom->rds_iobuf[handle] == NULL );
1149 phantom->rds_iobuf[handle] = iobuf;
1150
1151 /* Post descriptor */
1152 phantom_post_rds ( phantom, &rds );
1153 }
1154}
1155
1156/**
1157 * Open NIC
1158 *
1159 * @v netdev Net device
1160 * @ret rc Return status code
1161 */
1162static int phantom_open ( struct net_device *netdev ) {
1163 struct phantom_nic *phantom = netdev->priv;
1164 int rc;
1165
1166 /* Allocate and zero descriptor rings */
1167 phantom->desc = malloc_phys ( sizeof ( *(phantom->desc) ),
1169 if ( ! phantom->desc ) {
1170 rc = -ENOMEM;
1171 goto err_alloc_desc;
1172 }
1173 memset ( phantom->desc, 0, sizeof ( *(phantom->desc) ) );
1174
1175 /* Create RX context */
1176 if ( ( rc = phantom_create_rx_ctx ( phantom ) ) != 0 )
1177 goto err_create_rx_ctx;
1178
1179 /* Create TX context */
1180 if ( ( rc = phantom_create_tx_ctx ( phantom ) ) != 0 )
1181 goto err_create_tx_ctx;
1182
1183 /* Fill the RX descriptor ring */
1185
1186 /* Add MAC addresses
1187 *
1188 * BUG5583
1189 *
1190 * We would like to be able to enable receiving all multicast
1191 * packets (or, failing that, promiscuous mode), but the
1192 * firmware doesn't currently support this.
1193 */
1194 if ( ( rc = phantom_add_macaddr ( phantom,
1195 netdev->ll_broadcast ) ) != 0 )
1196 goto err_add_macaddr_broadcast;
1197 if ( ( rc = phantom_add_macaddr ( phantom,
1198 netdev->ll_addr ) ) != 0 )
1199 goto err_add_macaddr_unicast;
1200
1201 return 0;
1202
1203 phantom_del_macaddr ( phantom, netdev->ll_addr );
1204 err_add_macaddr_unicast:
1205 phantom_del_macaddr ( phantom, netdev->ll_broadcast );
1206 err_add_macaddr_broadcast:
1207 phantom_destroy_tx_ctx ( phantom );
1208 err_create_tx_ctx:
1209 phantom_destroy_rx_ctx ( phantom );
1210 err_create_rx_ctx:
1211 free_phys ( phantom->desc, sizeof ( *(phantom->desc) ) );
1212 phantom->desc = NULL;
1213 err_alloc_desc:
1214 return rc;
1215}
1216
1217/**
1218 * Close NIC
1219 *
1220 * @v netdev Net device
1221 */
1222static void phantom_close ( struct net_device *netdev ) {
1223 struct phantom_nic *phantom = netdev->priv;
1224 struct io_buffer *iobuf;
1225 unsigned int i;
1226
1227 /* Shut down the port */
1228 phantom_del_macaddr ( phantom, netdev->ll_addr );
1229 phantom_del_macaddr ( phantom, netdev->ll_broadcast );
1230 phantom_destroy_tx_ctx ( phantom );
1231 phantom_destroy_rx_ctx ( phantom );
1232 free_phys ( phantom->desc, sizeof ( *(phantom->desc) ) );
1233 phantom->desc = NULL;
1234
1235 /* Flush any uncompleted descriptors */
1236 for ( i = 0 ; i < PHN_RDS_MAX_FILL ; i++ ) {
1237 iobuf = phantom->rds_iobuf[i];
1238 if ( iobuf ) {
1239 free_iob ( iobuf );
1240 phantom->rds_iobuf[i] = NULL;
1241 }
1242 }
1243 for ( i = 0 ; i < PHN_NUM_CDS ; i++ ) {
1244 iobuf = phantom->cds_iobuf[i];
1245 if ( iobuf ) {
1247 phantom->cds_iobuf[i] = NULL;
1248 }
1249 }
1250}
1251
1252/**
1253 * Transmit packet
1254 *
1255 * @v netdev Network device
1256 * @v iobuf I/O buffer
1257 * @ret rc Return status code
1258 */
1260 struct io_buffer *iobuf ) {
1261 struct phantom_nic *phantom = netdev->priv;
1262 union phantom_cds cds;
1263 int index;
1264
1265 /* Get descriptor ring entry */
1266 index = phantom_alloc_cds ( phantom );
1267 if ( index < 0 )
1268 return index;
1269
1270 /* Fill descriptor ring entry */
1271 memset ( &cds, 0, sizeof ( cds ) );
1272 NX_FILL_3 ( &cds, 0,
1273 tx.opcode, UNM_TX_ETHER_PKT,
1274 tx.num_buffers, 1,
1275 tx.length, iob_len ( iobuf ) );
1276 NX_FILL_2 ( &cds, 2,
1277 tx.port, phantom->port,
1278 tx.context_id, phantom->port );
1279 NX_FILL_1 ( &cds, 4,
1280 tx.buffer1_dma_addr, virt_to_bus ( iobuf->data ) );
1281 NX_FILL_1 ( &cds, 5,
1282 tx.buffer1_length, iob_len ( iobuf ) );
1283
1284 /* Record I/O buffer */
1285 assert ( phantom->cds_iobuf[index] == NULL );
1286 phantom->cds_iobuf[index] = iobuf;
1287
1288 /* Post descriptor */
1289 phantom_post_cds ( phantom, &cds );
1290
1291 return 0;
1292}
1293
1294/**
1295 * Poll for received packets
1296 *
1297 * @v netdev Network device
1298 */
1299static void phantom_poll ( struct net_device *netdev ) {
1300 struct phantom_nic *phantom = netdev->priv;
1301 struct io_buffer *iobuf;
1302 unsigned int irq_vector;
1303 unsigned int irq_state;
1304 unsigned int cds_consumer_idx;
1305 unsigned int raw_new_cds_consumer_idx;
1306 unsigned int new_cds_consumer_idx;
1307 unsigned int rds_consumer_idx;
1308 unsigned int sds_consumer_idx;
1309 struct phantom_sds *sds;
1310 unsigned int sds_handle;
1311 unsigned int sds_opcode;
1312
1313 /* Occasionally poll the link state */
1314 if ( phantom->link_poll_timer-- == 0 ) {
1316 /* Reset the link poll timer */
1318 }
1319
1320 /* Check for interrupts */
1321 if ( phantom->sds_irq_enabled ) {
1322
1323 /* Do nothing unless an interrupt is asserted */
1324 irq_vector = phantom_readl ( phantom, UNM_PCIE_IRQ_VECTOR );
1325 if ( ! ( irq_vector & UNM_PCIE_IRQ_VECTOR_BIT( phantom->port )))
1326 return;
1327
1328 /* Do nothing unless interrupt state machine has stabilised */
1329 irq_state = phantom_readl ( phantom, UNM_PCIE_IRQ_STATE );
1330 if ( ! UNM_PCIE_IRQ_STATE_TRIGGERED ( irq_state ) )
1331 return;
1332
1333 /* Acknowledge interrupt */
1335 phantom_irq_status_reg[phantom->port] );
1337 }
1338
1339 /* Check for TX completions */
1340 cds_consumer_idx = phantom->cds_consumer_idx;
1341 raw_new_cds_consumer_idx = phantom->desc->cmd_cons;
1342 new_cds_consumer_idx = le32_to_cpu ( raw_new_cds_consumer_idx );
1343 while ( cds_consumer_idx != new_cds_consumer_idx ) {
1344 DBGC2 ( phantom, "Phantom %p CDS %d complete\n",
1345 phantom, cds_consumer_idx );
1346 /* Completions may be for commands other than TX, so
1347 * there may not always be an associated I/O buffer.
1348 */
1349 if ( ( iobuf = phantom->cds_iobuf[cds_consumer_idx] ) ) {
1350 netdev_tx_complete ( netdev, iobuf );
1351 phantom->cds_iobuf[cds_consumer_idx] = NULL;
1352 }
1353 cds_consumer_idx = ( ( cds_consumer_idx + 1 ) % PHN_NUM_CDS );
1354 phantom->cds_consumer_idx = cds_consumer_idx;
1355 }
1356
1357 /* Check for received packets */
1358 rds_consumer_idx = phantom->rds_consumer_idx;
1359 sds_consumer_idx = phantom->sds_consumer_idx;
1360 while ( 1 ) {
1361 sds = &phantom->desc->sds[sds_consumer_idx];
1362 if ( NX_GET ( sds, owner ) == 0 )
1363 break;
1364
1365 DBGC2 ( phantom, "Phantom %p SDS %d status:\n",
1366 phantom, sds_consumer_idx );
1367 DBGC2_HDA ( phantom, virt_to_bus ( sds ), sds, sizeof (*sds) );
1368
1369 /* Check received opcode */
1370 sds_opcode = NX_GET ( sds, opcode );
1371 if ( ( sds_opcode == UNM_RXPKT_DESC ) ||
1372 ( sds_opcode == UNM_SYN_OFFLOAD ) ) {
1373
1374 /* Sanity check: ensure that all of the SDS
1375 * descriptor has been written.
1376 */
1377 if ( NX_GET ( sds, total_length ) == 0 ) {
1378 DBGC ( phantom, "Phantom %p SDS %d "
1379 "incomplete; deferring\n",
1380 phantom, sds_consumer_idx );
1381 /* Leave for next poll() */
1382 break;
1383 }
1384
1385 /* Process received packet */
1386 sds_handle = NX_GET ( sds, handle );
1387 iobuf = phantom->rds_iobuf[sds_handle];
1388 assert ( iobuf != NULL );
1389 iob_put ( iobuf, NX_GET ( sds, total_length ) );
1390 iob_pull ( iobuf, NX_GET ( sds, pkt_offset ) );
1391 DBGC2 ( phantom, "Phantom %p RDS %d complete\n",
1392 phantom, sds_handle );
1393 netdev_rx ( netdev, iobuf );
1394 phantom->rds_iobuf[sds_handle] = NULL;
1395
1396 /* Update RDS consumer counter. This is a
1397 * lower bound for the number of descriptors
1398 * that have been read by the hardware, since
1399 * the hardware must have read at least one
1400 * descriptor for each completion that we
1401 * receive.
1402 */
1403 rds_consumer_idx =
1404 ( ( rds_consumer_idx + 1 ) % PHN_NUM_RDS );
1405 phantom->rds_consumer_idx = rds_consumer_idx;
1406
1407 } else {
1408
1409 DBGC ( phantom, "Phantom %p unexpected SDS opcode "
1410 "%02x\n", phantom, sds_opcode );
1411 DBGC_HDA ( phantom, virt_to_bus ( sds ),
1412 sds, sizeof ( *sds ) );
1413 }
1414
1415 /* Clear status descriptor */
1416 memset ( sds, 0, sizeof ( *sds ) );
1417
1418 /* Update SDS consumer index */
1419 sds_consumer_idx = ( ( sds_consumer_idx + 1 ) % PHN_NUM_SDS );
1420 phantom->sds_consumer_idx = sds_consumer_idx;
1421 wmb();
1422 phantom_writel ( phantom, phantom->sds_consumer_idx,
1423 phantom->sds_consumer_crb );
1424 }
1425
1426 /* Refill the RX descriptor ring */
1428}
1429
1430/**
1431 * Enable/disable interrupts
1432 *
1433 * @v netdev Network device
1434 * @v enable Interrupts should be enabled
1435 */
1436static void phantom_irq ( struct net_device *netdev, int enable ) {
1437 struct phantom_nic *phantom = netdev->priv;
1438
1439 phantom_writel ( phantom, ( enable ? 1 : 0 ),
1440 phantom->sds_irq_mask_crb );
1442 phantom_irq_mask_reg[phantom->port] );
1443 phantom->sds_irq_enabled = enable;
1444}
1445
1446/** Phantom net device operations */
1448 .open = phantom_open,
1449 .close = phantom_close,
1450 .transmit = phantom_transmit,
1451 .poll = phantom_poll,
1452 .irq = phantom_irq,
1453};
1454
1455/***************************************************************************
1456 *
1457 * CLP settings
1458 *
1459 */
1460
1461/** Phantom CLP settings scope */
1463
1464/** Phantom CLP data
1465 *
1466 */
1468 /** Data bytes
1469 *
1470 * This field is right-aligned; if only N bytes are present
1471 * then bytes[0]..bytes[7-N] should be zero, and the data
1472 * should be in bytes[7-N+1] to bytes[7];
1473 */
1475 /** Dwords for the CLP interface */
1476 struct {
1477 /** High dword, in network byte order */
1479 /** Low dword, in network byte order */
1482};
1483#define PHN_CLP_BLKSIZE ( sizeof ( union phantom_clp_data ) )
1484
1485/**
1486 * Wait for Phantom CLP command to complete
1487 *
1488 * @v phantom Phantom NIC
1489 * @ret rc Return status code
1490 */
1491static int phantom_clp_wait ( struct phantom_nic *phantom ) {
1492 unsigned int retries;
1494
1495 for ( retries = 0 ; retries < PHN_CLP_CMD_TIMEOUT_MS ; retries++ ) {
1498 return 0;
1499 mdelay ( 1 );
1500 }
1501
1502 DBGC ( phantom, "Phantom %p timed out waiting for CLP command\n",
1503 phantom );
1504 return -ETIMEDOUT;
1505}
1506
1507/**
1508 * Issue Phantom CLP command
1509 *
1510 * @v phantom Phantom NIC
1511 * @v port Virtual port number
1512 * @v opcode Opcode
1513 * @v data_in Data in, or NULL
1514 * @v data_out Data out, or NULL
1515 * @v offset Offset within data
1516 * @v len Data buffer length
1517 * @ret len Total transfer length (for reads), or negative error
1518 */
1519static int phantom_clp_cmd ( struct phantom_nic *phantom, unsigned int port,
1520 unsigned int opcode, const void *data_in,
1521 void *data_out, size_t offset, size_t len ) {
1522 union phantom_clp_data data;
1523 unsigned int index = ( offset / sizeof ( data ) );
1524 unsigned int last = 0;
1525 size_t in_frag_len;
1526 uint8_t *in_frag;
1529 size_t read_len;
1530 unsigned int error;
1531 size_t out_frag_len;
1532 uint8_t *out_frag;
1533 int rc;
1534
1535 /* Sanity checks */
1536 assert ( ( offset % sizeof ( data ) ) == 0 );
1537 if ( len > 255 ) {
1538 DBGC ( phantom, "Phantom %p invalid CLP length %zd\n",
1539 phantom, len );
1540 return -EINVAL;
1541 }
1542
1543 /* Check that CLP interface is ready */
1544 if ( ( rc = phantom_clp_wait ( phantom ) ) != 0 )
1545 return rc;
1546
1547 /* Copy data in */
1548 memset ( &data, 0, sizeof ( data ) );
1549 if ( data_in ) {
1550 assert ( offset < len );
1551 in_frag_len = ( len - offset );
1552 if ( in_frag_len > sizeof ( data ) ) {
1553 in_frag_len = sizeof ( data );
1554 } else {
1555 last = 1;
1556 }
1557 in_frag = &data.bytes[ sizeof ( data ) - in_frag_len ];
1558 memcpy ( in_frag, ( data_in + offset ), in_frag_len );
1559 phantom_writel ( phantom, be32_to_cpu ( data.dwords.lo ),
1561 phantom_writel ( phantom, be32_to_cpu ( data.dwords.hi ),
1563 }
1564
1565 /* Issue CLP command */
1566 command = ( ( index << 24 ) | ( ( data_in ? len : 0 ) << 16 ) |
1567 ( port << 8 ) | ( last << 7 ) | ( opcode << 0 ) );
1569 mb();
1572
1573 /* Wait for command to complete */
1574 if ( ( rc = phantom_clp_wait ( phantom ) ) != 0 )
1575 return rc;
1576
1577 /* Get command status */
1579 read_len = ( ( status >> 16 ) & 0xff );
1580 error = ( ( status >> 8 ) & 0xff );
1581 if ( error ) {
1582 DBGC ( phantom, "Phantom %p CLP command error %02x\n",
1583 phantom, error );
1584 return -EIO;
1585 }
1586
1587 /* Copy data out */
1588 if ( data_out ) {
1589 data.dwords.lo = cpu_to_be32 ( phantom_readl ( phantom,
1591 data.dwords.hi = cpu_to_be32 ( phantom_readl ( phantom,
1593 out_frag_len = ( read_len - offset );
1594 if ( out_frag_len > sizeof ( data ) )
1595 out_frag_len = sizeof ( data );
1596 out_frag = &data.bytes[ sizeof ( data ) - out_frag_len ];
1597 if ( out_frag_len > ( len - offset ) )
1598 out_frag_len = ( len - offset );
1599 memcpy ( ( data_out + offset ), out_frag, out_frag_len );
1600 }
1601
1602 return read_len;
1603}
1604
1605/**
1606 * Store Phantom CLP setting
1607 *
1608 * @v phantom Phantom NIC
1609 * @v port Virtual port number
1610 * @v setting Setting number
1611 * @v data Data buffer
1612 * @v len Length of data buffer
1613 * @ret rc Return status code
1614 */
1615static int phantom_clp_store ( struct phantom_nic *phantom, unsigned int port,
1616 unsigned int setting, const void *data,
1617 size_t len ) {
1618 unsigned int opcode = setting;
1619 size_t offset;
1620 int rc;
1621
1622 for ( offset = 0 ; offset < len ; offset += PHN_CLP_BLKSIZE ) {
1623 if ( ( rc = phantom_clp_cmd ( phantom, port, opcode, data,
1624 NULL, offset, len ) ) < 0 )
1625 return rc;
1626 }
1627 return 0;
1628}
1629
1630/**
1631 * Fetch Phantom CLP setting
1632 *
1633 * @v phantom Phantom NIC
1634 * @v port Virtual port number
1635 * @v setting Setting number
1636 * @v data Data buffer
1637 * @v len Length of data buffer
1638 * @ret len Length of setting, or negative error
1639 */
1640static int phantom_clp_fetch ( struct phantom_nic *phantom, unsigned int port,
1641 unsigned int setting, void *data, size_t len ) {
1642 unsigned int opcode = ( setting + 1 );
1643 size_t offset = 0;
1644 int read_len;
1645
1646 while ( 1 ) {
1647 read_len = phantom_clp_cmd ( phantom, port, opcode, NULL,
1648 data, offset, len );
1649 if ( read_len < 0 )
1650 return read_len;
1652 if ( offset >= ( unsigned ) read_len )
1653 break;
1654 if ( offset >= len )
1655 break;
1656 }
1657 return read_len;
1658}
1659
1660/** A Phantom CLP setting */
1662 /** iPXE setting */
1663 const struct setting *setting;
1664 /** Setting number */
1665 unsigned int clp_setting;
1666};
1667
1668/** Phantom CLP settings */
1670 { &mac_setting, 0x01 },
1671};
1672
1673/**
1674 * Find Phantom CLP setting
1675 *
1676 * @v setting iPXE setting
1677 * @v clp_setting Setting number, or 0 if not found
1678 */
1679static unsigned int
1681 const struct setting *setting ) {
1683 unsigned int i;
1684
1685 /* Search the list of explicitly-defined settings */
1686 for ( i = 0 ; i < ( sizeof ( clp_settings ) /
1687 sizeof ( clp_settings[0] ) ) ; i++ ) {
1689 if ( setting_cmp ( setting, clp_setting->setting ) == 0 )
1690 return clp_setting->clp_setting;
1691 }
1692
1693 /* Allow for use of numbered settings */
1695 return setting->tag;
1696
1697 DBGC2 ( phantom, "Phantom %p has no \"%s\" setting\n",
1698 phantom, setting->name );
1699
1700 return 0;
1701}
1702
1703/**
1704 * Check applicability of Phantom CLP setting
1705 *
1706 * @v settings Settings block
1707 * @v setting Setting
1708 * @ret applies Setting applies within this settings block
1709 */
1711 const struct setting *setting ) {
1712 struct phantom_nic *phantom =
1714 unsigned int clp_setting;
1715
1716 /* Find Phantom setting equivalent to iPXE setting */
1717 clp_setting = phantom_clp_setting ( phantom, setting );
1718 return ( clp_setting != 0 );
1719}
1720
1721/**
1722 * Store Phantom CLP setting
1723 *
1724 * @v settings Settings block
1725 * @v setting Setting to store
1726 * @v data Setting data, or NULL to clear setting
1727 * @v len Length of setting data
1728 * @ret rc Return status code
1729 */
1731 const struct setting *setting,
1732 const void *data, size_t len ) {
1733 struct phantom_nic *phantom =
1735 unsigned int clp_setting;
1736 int rc;
1737
1738 /* Find Phantom setting equivalent to iPXE setting */
1739 clp_setting = phantom_clp_setting ( phantom, setting );
1740 assert ( clp_setting != 0 );
1741
1742 /* Store setting */
1743 if ( ( rc = phantom_clp_store ( phantom, phantom->port,
1744 clp_setting, data, len ) ) != 0 ) {
1745 DBGC ( phantom, "Phantom %p could not store setting \"%s\": "
1746 "%s\n", phantom, setting->name, strerror ( rc ) );
1747 return rc;
1748 }
1749
1750 return 0;
1751}
1752
1753/**
1754 * Fetch Phantom CLP setting
1755 *
1756 * @v settings Settings block
1757 * @v setting Setting to fetch
1758 * @v data Buffer to fill with setting data
1759 * @v len Length of buffer
1760 * @ret len Length of setting data, or negative error
1761 */
1763 struct setting *setting,
1764 void *data, size_t len ) {
1765 struct phantom_nic *phantom =
1767 unsigned int clp_setting;
1768 int read_len;
1769 int rc;
1770
1771 /* Find Phantom setting equivalent to iPXE setting */
1772 clp_setting = phantom_clp_setting ( phantom, setting );
1773 assert ( clp_setting != 0 );
1774
1775 /* Fetch setting */
1776 if ( ( read_len = phantom_clp_fetch ( phantom, phantom->port,
1777 clp_setting, data, len ) ) < 0 ){
1778 rc = read_len;
1779 DBGC ( phantom, "Phantom %p could not fetch setting \"%s\": "
1780 "%s\n", phantom, setting->name, strerror ( rc ) );
1781 return rc;
1782 }
1783
1784 return read_len;
1785}
1786
1787/** Phantom CLP settings operations */
1793
1794/***************************************************************************
1795 *
1796 * Initialisation
1797 *
1798 */
1799
1800/**
1801 * Map Phantom CRB window
1802 *
1803 * @v phantom Phantom NIC
1804 * @ret rc Return status code
1805 */
1806static int phantom_map_crb ( struct phantom_nic *phantom,
1807 struct pci_device *pci ) {
1808 unsigned long bar0_start;
1809 unsigned long bar0_size;
1810
1811 bar0_start = pci_bar_start ( pci, PCI_BASE_ADDRESS_0 );
1812 bar0_size = pci_bar_size ( pci, PCI_BASE_ADDRESS_0 );
1813 DBGC ( phantom, "Phantom %p is " PCI_FMT " with BAR0 at %08lx+%lx\n",
1814 phantom, PCI_ARGS ( pci ), bar0_start, bar0_size );
1815
1816 if ( ! bar0_start ) {
1817 DBGC ( phantom, "Phantom %p BAR not assigned; ignoring\n",
1818 phantom );
1819 return -EINVAL;
1820 }
1821
1822 switch ( bar0_size ) {
1823 case ( 128 * 1024 * 1024 ) :
1824 DBGC ( phantom, "Phantom %p has 128MB BAR\n", phantom );
1826 break;
1827 case ( 32 * 1024 * 1024 ) :
1828 DBGC ( phantom, "Phantom %p has 32MB BAR\n", phantom );
1830 break;
1831 case ( 2 * 1024 * 1024 ) :
1832 DBGC ( phantom, "Phantom %p has 2MB BAR\n", phantom );
1834 break;
1835 default:
1836 DBGC ( phantom, "Phantom %p has bad BAR size\n", phantom );
1837 return -EINVAL;
1838 }
1839
1840 phantom->bar0 = pci_ioremap ( pci, bar0_start, bar0_size );
1841 if ( ! phantom->bar0 ) {
1842 DBGC ( phantom, "Phantom %p could not map BAR0\n", phantom );
1843 return -EIO;
1844 }
1845
1846 /* Mark current CRB window as invalid, so that the first
1847 * read/write will set the current window.
1848 */
1849 phantom->crb_window = -1UL;
1850
1851 return 0;
1852}
1853
1854/**
1855 * Unhalt all PEGs
1856 *
1857 * @v phantom Phantom NIC
1858 */
1859static void phantom_unhalt_pegs ( struct phantom_nic *phantom ) {
1860 uint32_t halt_status;
1861
1862 halt_status = phantom_readl ( phantom, UNM_PEG_0_HALT_STATUS );
1863 phantom_writel ( phantom, halt_status, UNM_PEG_0_HALT_STATUS );
1864 halt_status = phantom_readl ( phantom, UNM_PEG_1_HALT_STATUS );
1865 phantom_writel ( phantom, halt_status, UNM_PEG_1_HALT_STATUS );
1866 halt_status = phantom_readl ( phantom, UNM_PEG_2_HALT_STATUS );
1867 phantom_writel ( phantom, halt_status, UNM_PEG_2_HALT_STATUS );
1868 halt_status = phantom_readl ( phantom, UNM_PEG_3_HALT_STATUS );
1869 phantom_writel ( phantom, halt_status, UNM_PEG_3_HALT_STATUS );
1870 halt_status = phantom_readl ( phantom, UNM_PEG_4_HALT_STATUS );
1871 phantom_writel ( phantom, halt_status, UNM_PEG_4_HALT_STATUS );
1872}
1873
1874/**
1875 * Initialise the Phantom command PEG
1876 *
1877 * @v phantom Phantom NIC
1878 * @ret rc Return status code
1879 */
1880static int phantom_init_cmdpeg ( struct phantom_nic *phantom ) {
1881 uint32_t cold_boot;
1882 uint32_t sw_reset;
1883 unsigned int retries;
1884 uint32_t cmdpeg_state;
1885 uint32_t last_cmdpeg_state = 0;
1886
1887 /* Check for a previous initialisation. This could have
1888 * happened if, for example, the BIOS used the UNDI API to
1889 * drive the NIC prior to a full PXE boot.
1890 */
1891 cmdpeg_state = phantom_readl ( phantom, UNM_NIC_REG_CMDPEG_STATE );
1892 if ( cmdpeg_state == UNM_NIC_REG_CMDPEG_STATE_INITIALIZE_ACK ) {
1893 DBGC ( phantom, "Phantom %p command PEG already initialized\n",
1894 phantom );
1895 /* Unhalt the PEGs. Previous firmware (e.g. BOFM) may
1896 * have halted the PEGs to prevent internal bus
1897 * collisions when the BIOS re-reads the expansion ROM.
1898 */
1899 phantom_unhalt_pegs ( phantom );
1900 return 0;
1901 }
1902
1903 /* If this was a cold boot, check that the hardware came up ok */
1904 cold_boot = phantom_readl ( phantom, UNM_CAM_RAM_COLD_BOOT );
1905 if ( cold_boot == UNM_CAM_RAM_COLD_BOOT_MAGIC ) {
1906 DBGC ( phantom, "Phantom %p coming up from cold boot\n",
1907 phantom );
1908 sw_reset = phantom_readl ( phantom, UNM_ROMUSB_GLB_SW_RESET );
1909 if ( sw_reset != UNM_ROMUSB_GLB_SW_RESET_MAGIC ) {
1910 DBGC ( phantom, "Phantom %p reset failed: %08x\n",
1911 phantom, sw_reset );
1912 return -EIO;
1913 }
1914 } else {
1915 DBGC ( phantom, "Phantom %p coming up from warm boot "
1916 "(%08x)\n", phantom, cold_boot );
1917 }
1918 /* Clear cold-boot flag */
1919 phantom_writel ( phantom, 0, UNM_CAM_RAM_COLD_BOOT );
1920
1921 /* Set port modes */
1924
1925 /* Pass dummy DMA area to card */
1926 phantom_write_hilo ( phantom, 0,
1931
1932 /* Tell the hardware that tuning is complete */
1935
1936 /* Wait for command PEG to finish initialising */
1937 DBGC ( phantom, "Phantom %p initialising command PEG (will take up to "
1938 "%d seconds)...\n", phantom, PHN_CMDPEG_INIT_TIMEOUT_SEC );
1939 for ( retries = 0; retries < PHN_CMDPEG_INIT_TIMEOUT_SEC; retries++ ) {
1940 cmdpeg_state = phantom_readl ( phantom,
1942 if ( cmdpeg_state != last_cmdpeg_state ) {
1943 DBGC ( phantom, "Phantom %p command PEG state is "
1944 "%08x after %d seconds...\n",
1945 phantom, cmdpeg_state, retries );
1946 last_cmdpeg_state = cmdpeg_state;
1947 }
1948 if ( cmdpeg_state == UNM_NIC_REG_CMDPEG_STATE_INITIALIZED ) {
1949 /* Acknowledge the PEG initialisation */
1950 phantom_writel ( phantom,
1953 return 0;
1954 }
1955 mdelay ( 1000 );
1956 }
1957
1958 DBGC ( phantom, "Phantom %p timed out waiting for command PEG to "
1959 "initialise (status %08x)\n", phantom, cmdpeg_state );
1960 return -ETIMEDOUT;
1961}
1962
1963/**
1964 * Read Phantom MAC address
1965 *
1966 * @v phanton_port Phantom NIC
1967 * @v hw_addr Buffer to fill with MAC address
1968 */
1969static void phantom_get_macaddr ( struct phantom_nic *phantom,
1970 uint8_t *hw_addr ) {
1971 union {
1972 uint8_t mac_addr[2][ETH_ALEN];
1973 uint32_t dwords[3];
1974 } u;
1975 unsigned long offset;
1976 int i;
1977
1978 /* Read the three dwords that include this MAC address and one other */
1980 ( 12 * ( phantom->port / 2 ) ) );
1981 for ( i = 0 ; i < 3 ; i++, offset += 4 ) {
1982 u.dwords[i] = phantom_readl ( phantom, offset );
1983 }
1984
1985 /* Copy out the relevant MAC address */
1986 for ( i = 0 ; i < ETH_ALEN ; i++ ) {
1987 hw_addr[ ETH_ALEN - i - 1 ] =
1988 u.mac_addr[ phantom->port & 1 ][i];
1989 }
1990 DBGC ( phantom, "Phantom %p MAC address is %s\n",
1991 phantom, eth_ntoa ( hw_addr ) );
1992}
1993
1994/**
1995 * Check Phantom is enabled for boot
1996 *
1997 * @v phanton_port Phantom NIC
1998 * @ret rc Return status code
1999 *
2000 * This is something of an ugly hack to accommodate an OEM
2001 * requirement. The NIC has only one expansion ROM BAR, rather than
2002 * one per port. To allow individual ports to be selectively
2003 * enabled/disabled for PXE boot (as required), we must therefore
2004 * leave the expansion ROM always enabled, and place the per-port
2005 * enable/disable logic within the iPXE driver.
2006 */
2007static int phantom_check_boot_enable ( struct phantom_nic *phantom ) {
2008 unsigned long boot_enable;
2009
2010 boot_enable = phantom_readl ( phantom, UNM_CAM_RAM_BOOT_ENABLE );
2011 if ( ! ( boot_enable & ( 1 << phantom->port ) ) ) {
2012 DBGC ( phantom, "Phantom %p PXE boot is disabled\n",
2013 phantom );
2014 return -ENOTSUP;
2015 }
2016
2017 return 0;
2018}
2019
2020/**
2021 * Initialise Phantom receive PEG
2022 *
2023 * @v phantom Phantom NIC
2024 * @ret rc Return status code
2025 */
2026static int phantom_init_rcvpeg ( struct phantom_nic *phantom ) {
2027 unsigned int retries;
2028 uint32_t rcvpeg_state;
2029 uint32_t last_rcvpeg_state = 0;
2030
2031 DBGC ( phantom, "Phantom %p initialising receive PEG (will take up to "
2032 "%d seconds)...\n", phantom, PHN_RCVPEG_INIT_TIMEOUT_SEC );
2033 for ( retries = 0; retries < PHN_RCVPEG_INIT_TIMEOUT_SEC; retries++ ) {
2034 rcvpeg_state = phantom_readl ( phantom,
2036 if ( rcvpeg_state != last_rcvpeg_state ) {
2037 DBGC ( phantom, "Phantom %p receive PEG state is "
2038 "%08x after %d seconds...\n",
2039 phantom, rcvpeg_state, retries );
2040 last_rcvpeg_state = rcvpeg_state;
2041 }
2042 if ( rcvpeg_state == UNM_NIC_REG_RCVPEG_STATE_INITIALIZED )
2043 return 0;
2044 mdelay ( 1000 );
2045 }
2046
2047 DBGC ( phantom, "Phantom %p timed out waiting for receive PEG to "
2048 "initialise (status %08x)\n", phantom, rcvpeg_state );
2049 return -ETIMEDOUT;
2050}
2051
2052/**
2053 * Probe PCI device
2054 *
2055 * @v pci PCI device
2056 * @v id PCI ID
2057 * @ret rc Return status code
2058 */
2059static int phantom_probe ( struct pci_device *pci ) {
2060 struct net_device *netdev;
2061 struct phantom_nic *phantom;
2062 struct settings *parent_settings;
2063 unsigned int busdevfn;
2064 int rc;
2065
2066 /* Allocate Phantom device */
2067 netdev = alloc_etherdev ( sizeof ( *phantom ) );
2068 if ( ! netdev ) {
2069 rc = -ENOMEM;
2070 goto err_alloc_etherdev;
2071 }
2073 phantom = netdev->priv;
2074 pci_set_drvdata ( pci, netdev );
2075 netdev->dev = &pci->dev;
2076 memset ( phantom, 0, sizeof ( *phantom ) );
2077 phantom->port = PCI_FUNC ( pci->busdevfn );
2078 assert ( phantom->port < PHN_MAX_NUM_PORTS );
2079 settings_init ( &phantom->settings,
2081 &netdev->refcnt, &phantom_settings_scope );
2082
2083 /* Fix up PCI device */
2084 adjust_pci_device ( pci );
2085
2086 /* Map CRB */
2087 if ( ( rc = phantom_map_crb ( phantom, pci ) ) != 0 )
2088 goto err_map_crb;
2089
2090 /* BUG5945 - need to hack PCI config space on P3 B1 silicon.
2091 * B2 will have this fixed; remove this hack when B1 is no
2092 * longer in use.
2093 */
2094 busdevfn = pci->busdevfn;
2095 if ( PCI_FUNC ( busdevfn ) == 0 ) {
2096 unsigned int i;
2097 for ( i = 0 ; i < 8 ; i++ ) {
2098 uint32_t temp;
2099 pci->busdevfn =
2101 PCI_BUS ( busdevfn ),
2102 PCI_SLOT ( busdevfn ), i );
2103 pci_read_config_dword ( pci, 0xc8, &temp );
2104 pci_read_config_dword ( pci, 0xc8, &temp );
2105 pci_write_config_dword ( pci, 0xc8, 0xf1000 );
2106 }
2107 pci->busdevfn = busdevfn;
2108 }
2109
2110 /* Initialise the command PEG */
2111 if ( ( rc = phantom_init_cmdpeg ( phantom ) ) != 0 )
2112 goto err_init_cmdpeg;
2113
2114 /* Initialise the receive PEG */
2115 if ( ( rc = phantom_init_rcvpeg ( phantom ) ) != 0 )
2116 goto err_init_rcvpeg;
2117
2118 /* Read MAC addresses */
2119 phantom_get_macaddr ( phantom, netdev->hw_addr );
2120
2121 /* Skip if boot disabled on NIC */
2122 if ( ( rc = phantom_check_boot_enable ( phantom ) ) != 0 )
2123 goto err_check_boot_enable;
2124
2125 /* Register network devices */
2126 if ( ( rc = register_netdev ( netdev ) ) != 0 ) {
2127 DBGC ( phantom, "Phantom %p could not register net device: "
2128 "%s\n", phantom, strerror ( rc ) );
2129 goto err_register_netdev;
2130 }
2131
2132 /* Register settings blocks */
2133 parent_settings = netdev_settings ( netdev );
2134 if ( ( rc = register_settings ( &phantom->settings,
2135 parent_settings, "clp" ) ) != 0 ) {
2136 DBGC ( phantom, "Phantom %p could not register settings: "
2137 "%s\n", phantom, strerror ( rc ) );
2138 goto err_register_settings;
2139 }
2140
2141 return 0;
2142
2143 unregister_settings ( &phantom->settings );
2144 err_register_settings:
2146 err_register_netdev:
2147 err_check_boot_enable:
2148 err_init_rcvpeg:
2149 err_init_cmdpeg:
2150 err_map_crb:
2152 netdev_put ( netdev );
2153 err_alloc_etherdev:
2154 return rc;
2155}
2156
2157/**
2158 * Remove PCI device
2159 *
2160 * @v pci PCI device
2161 */
2162static void phantom_remove ( struct pci_device *pci ) {
2163 struct net_device *netdev = pci_get_drvdata ( pci );
2164 struct phantom_nic *phantom = netdev->priv;
2165
2166 unregister_settings ( &phantom->settings );
2169 netdev_put ( netdev );
2170}
2171
2172/** Phantom PCI IDs */
2173static struct pci_device_id phantom_nics[] = {
2174 PCI_ROM ( 0x4040, 0x0100, "nx", "NX", 0 ),
2175};
2176
2177/** Phantom PCI driver */
2178struct pci_driver phantom_driver __pci_driver = {
2179 .ids = phantom_nics,
2180 .id_count = ( sizeof ( phantom_nics ) / sizeof ( phantom_nics[0] ) ),
2183};
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
u8 owner
Definition CIB_PRM.h:8
u8 port
Port number.
Definition CIB_PRM.h:3
u8 sig
Definition CIB_PRM.h:15
u8 signature
CPU signature.
Definition CIB_PRM.h:7
__be32 out[4]
Definition CIB_PRM.h:8
u32 link
Link to next descriptor.
Definition ar9003_mac.h:1
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
pseudo_bit_t value[0x00020]
Definition arbel.h:2
struct arbelprm_completion_with_error error
Definition arbel.h:1
unsigned short uint16_t
Definition stdint.h:11
unsigned int uint32_t
Definition stdint.h:12
unsigned long long uint64_t
Definition stdint.h:13
unsigned char uint8_t
Definition stdint.h:10
long index
Definition bigint.h:65
static unsigned int unsigned long unsigned long arg2
Definition xen.h:67
static unsigned int unsigned long arg1
Definition xen.h:44
static unsigned int unsigned long unsigned long unsigned long arg3
Definition xen.h:91
Assertions.
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:50
uint16_t offset
Offset to command line.
Definition bzimage.h:3
union @104331263140136355135267063077374276003064103115 u
ring len
Length.
Definition dwmac.h:226
uint8_t data[48]
Additional event data.
Definition ena.h:11
uint8_t status
Status.
Definition ena.h:5
uint8_t opcode
Opcode.
Definition ena.h:5
uint16_t busdevfn
PCI bus:dev.fn address.
Definition ena.h:17
Error codes.
struct net_device * alloc_etherdev(size_t priv_size)
Allocate Ethernet device.
Definition ethernet.c:265
const char * eth_ntoa(const void *ll_addr)
Transcribe Ethernet address.
Definition ethernet.c:176
Ethernet protocol.
static struct net_device * netdev
Definition gdbudp.c:53
#define DBGC2(...)
Definition compiler.h:522
#define DBGC2_HDA(...)
Definition compiler.h:523
#define DBGC(...)
Definition compiler.h:505
#define DBG_LOG
Definition compiler.h:317
#define DBG(...)
Print a debugging message.
Definition compiler.h:498
#define DBGC_HDA(...)
Definition compiler.h:506
uint8_t head
Head number.
Definition int13.h:23
uint32_t buffer
Buffer index (or NETVSC_RNDIS_NO_BUFFER)
Definition netvsc.h:5
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define EINVAL
Invalid argument.
Definition errno.h:429
#define ETIMEDOUT
Connection timed out.
Definition errno.h:670
#define EPROTO
Protocol error.
Definition errno.h:625
#define ENOMEM
Not enough space.
Definition errno.h:535
#define EIO
Input/output error.
Definition errno.h:434
#define ENOTSUP
Operation not supported.
Definition errno.h:590
#define ECANCELED
Operation canceled.
Definition errno.h:344
#define ENOBUFS
No buffer space available.
Definition errno.h:499
uint8_t bytes[64]
Definition ib_mad.h:5
#define ETH_ALEN
Definition if_ether.h:9
#define be32_to_cpu(value)
Definition byteswap.h:117
#define cpu_to_le64(value)
Definition byteswap.h:109
#define le16_to_cpu(value)
Definition byteswap.h:113
#define le32_to_cpu(value)
Definition byteswap.h:114
#define cpu_to_le32(value)
Definition byteswap.h:108
#define cpu_to_be32(value)
Definition byteswap.h:111
#define cpu_to_le16(value)
Definition byteswap.h:107
#define __attribute__(x)
Definition compiler.h:10
iPXE I/O API
void mb(void)
Memory barrier.
#define wmb()
Definition io.h:546
static __always_inline unsigned long virt_to_bus(volatile const void *addr)
Convert virtual address to a bus address.
Definition io.h:184
int pci_read_config_dword(struct pci_device *pci, unsigned int where, uint32_t *value)
Read 32-bit dword from PCI configuration space.
void * pci_ioremap(struct pci_device *pci, unsigned long bus_addr, size_t len)
Map PCI bus address as an I/O address.
#define PCI_BUSDEVFN(segment, bus, slot, func)
Definition pci_io.h:30
int pci_write_config_dword(struct pci_device *pci, unsigned int where, uint32_t value)
Write 32-bit dword to PCI configuration space.
Configuration settings.
static void settings_init(struct settings *settings, struct settings_operations *op, struct refcnt *refcnt, const struct settings_scope *default_scope)
Initialise a settings block.
Definition settings.h:503
uint16_t handle
Handle.
Definition smbios.h:5
String functions.
void * memcpy(void *dest, const void *src, size_t len) __nonnull
void * memset(void *dest, int character, size_t len) __nonnull
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition iobuf.c:153
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition iobuf.c:131
I/O buffers.
#define iob_put(iobuf, len)
Definition iobuf.h:125
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition iobuf.h:160
#define iob_pull(iobuf, len)
Definition iobuf.h:107
uint8_t unused
Unused.
Definition librm.h:5
void * malloc_phys(size_t size, size_t phys_align)
Allocate memory with specified physical alignment.
Definition malloc.c:707
void free_phys(void *ptr, size_t size)
Free memory allocated with malloc_phys()
Definition malloc.c:723
Dynamic memory allocation.
uint8_t block[3][8]
DES-encrypted blocks.
Definition mschapv2.h:1
static unsigned int unsigned int reg
Definition myson.h:162
void netdev_link_down(struct net_device *netdev)
Mark network device as having link down.
Definition netdevice.c:231
void netdev_rx(struct net_device *netdev, struct io_buffer *iobuf)
Add packet to receive queue.
Definition netdevice.c:549
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition netdevice.c:942
void netdev_tx_complete_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Complete network transmission.
Definition netdevice.c:471
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition netdevice.c:587
int register_netdev(struct net_device *netdev)
Register network device.
Definition netdevice.c:760
Network device management.
static void netdev_link_up(struct net_device *netdev)
Mark network device as having link up.
Definition netdevice.h:789
static void netdev_init(struct net_device *netdev, struct net_device_operations *op)
Initialise a network device.
Definition netdevice.h:519
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition netdevice.h:532
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition netdevice.h:576
static void netdev_tx_complete(struct net_device *netdev, struct io_buffer *iobuf)
Complete network transmission.
Definition netdevice.h:767
static struct settings * netdev_settings(struct net_device *netdev)
Get per-netdevice configuration settings block.
Definition netdevice.h:587
#define NX_FILL_2(_ptr, _index,...)
Definition nx_bitops.h:165
#define NX_FILL_7(_ptr, _index,...)
Definition nx_bitops.h:180
#define NX_FILL_1(_ptr, _index,...)
Definition nx_bitops.h:162
#define NX_GET(_ptr, _field)
Extract value of named field (for fields up to the size of a long)
Definition nx_bitops.h:196
#define NX_FILL_3(_ptr, _index,...)
Definition nx_bitops.h:168
#define NX_CDRP_CMD_CREATE_TX_CTX
#define NX_CDRP_IS_RSP(rsp)
#define NX_CDRP_FORM_RSP(rsp)
#define NX_CDRP_CMD_DESTROY_TX_CTX
#define NX_CAP0_LEGACY_CONTEXT
#define NX_CAP0_LEGACY_MN
#define NX_CDRP_CMD_DESTROY_RX_CTX
#define NX_CDRP_RSP_OK
#define NX_HOST_RDS_CRB_MODE_UNIQUE
#define NX_HOST_INT_CRB_MODE_SHARED
#define NX_DESTROY_CTX_RESET
#define NX_CDRP_RSP_FAIL
#define NX_RDS_RING_TYPE_NORMAL
#define NX_CDRP_RSP_TIMEOUT
#define NX_CDRP_SIGNATURE_MAKE(pcifn, version)
#define NX_CDRP_CMD_CREATE_RX_CTX
#define NX_CDRP_FORM_CMD(cmd)
unsigned long pci_bar_size(struct pci_device *pci, unsigned int reg)
Get the size of a PCI BAR.
Definition pci.c:164
void adjust_pci_device(struct pci_device *pci)
Enable PCI device.
Definition pci.c:241
unsigned long pci_bar_start(struct pci_device *pci, unsigned int reg)
Find the start of a PCI BAR.
Definition pci.c:97
PCI bus.
#define PCI_FMT
PCI device debug message format.
Definition pci.h:312
#define PCI_SEG(busdevfn)
Definition pci.h:283
#define PCI_FUNC(busdevfn)
Definition pci.h:286
#define __pci_driver
Declare a PCI driver.
Definition pci.h:278
#define PCI_BUS(busdevfn)
Definition pci.h:284
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition pci.h:315
static void pci_set_drvdata(struct pci_device *pci, void *priv)
Set PCI driver-private data.
Definition pci.h:366
#define PCI_ROM(_vendor, _device, _name, _description, _data)
Definition pci.h:308
#define PCI_BASE_ADDRESS_0
Definition pci.h:63
static void * pci_get_drvdata(struct pci_device *pci)
Get PCI driver-private data.
Definition pci.h:376
#define PCI_SLOT(busdevfn)
Definition pci.h:285
static unsigned long phantom_crb_access_128m(struct phantom_nic *phantom, unsigned long reg)
Prepare for access to CRB register via 128MB BAR.
Definition phantom.c:241
static void phantom_post_rds(struct phantom_nic *phantom, struct phantom_rds *rds)
Post Phantom RX descriptor.
Definition phantom.c:899
#define PHN_RCVPEG_INIT_TIMEOUT_SEC
Maximum time to wait for receive PEG to initialise.
Definition phantom.c:72
static int phantom_init_cmdpeg(struct phantom_nic *phantom)
Initialise the Phantom command PEG.
Definition phantom.c:1880
#define PHN_CLP_BLKSIZE
Definition phantom.c:1483
static void phantom_poll_link_state(struct net_device *netdev)
Poll link state.
Definition phantom.c:1064
static int phantom_clp_wait(struct phantom_nic *phantom)
Wait for Phantom CLP command to complete.
Definition phantom.c:1491
static unsigned int phantom_clp_setting(struct phantom_nic *phantom, const struct setting *setting)
Find Phantom CLP setting.
Definition phantom.c:1680
#define PHN_MAX_NUM_PORTS
Maximum number of ports.
Definition phantom.c:53
static const unsigned long phantom_irq_status_reg[PHN_MAX_NUM_PORTS]
Interrupt status registers.
Definition phantom.c:217
static int phantom_create_tx_ctx(struct phantom_nic *phantom)
Create Phantom TX context.
Definition phantom.c:763
static int phantom_read_test_mem_block(struct phantom_nic *phantom, unsigned long offset, uint32_t buf[2])
Read from Phantom test memory.
Definition phantom.c:414
static int phantom_issue_buf_cmd(struct phantom_nic *phantom, uint32_t command, void *buffer, size_t len)
Issue buffer-format command to firmware.
Definition phantom.c:622
static int phantom_del_macaddr(struct phantom_nic *phantom, const uint8_t *ll_addr)
Remove MAC address.
Definition phantom.c:1044
static void phantom_get_macaddr(struct phantom_nic *phantom, uint8_t *hw_addr)
Read Phantom MAC address.
Definition phantom.c:1969
static int phantom_open(struct net_device *netdev)
Open NIC.
Definition phantom.c:1162
static void phantom_dmesg_all(struct phantom_nic *phantom, unsigned int max_lines)
Dump Phantom firmware dmesg logs.
Definition phantom.c:530
static int phantom_store_setting(struct settings *settings, const struct setting *setting, const void *data, size_t len)
Store Phantom CLP setting.
Definition phantom.c:1730
#define PHN_CMDPEG_INIT_TIMEOUT_SEC
Maximum time to wait for command PEG to initialise.
Definition phantom.c:69
static void phantom_poll(struct net_device *netdev)
Poll for received packets.
Definition phantom.c:1299
static int phantom_clp_store(struct phantom_nic *phantom, unsigned int port, unsigned int setting, const void *data, size_t len)
Store Phantom CLP setting.
Definition phantom.c:1615
static int phantom_dmesg(struct phantom_nic *phantom, unsigned int log, unsigned int max_lines)
Dump Phantom firmware dmesg log.
Definition phantom.c:480
static int phantom_update_macaddr(struct phantom_nic *phantom, const uint8_t *ll_addr, unsigned int opcode)
Add/remove MAC address.
Definition phantom.c:988
#define PHN_TEST_MEM_TIMEOUT_MS
Maximum time to wait for test memory.
Definition phantom.c:78
static int phantom_create_rx_ctx(struct phantom_nic *phantom)
Create Phantom RX context.
Definition phantom.c:638
static unsigned long phantom_crb_access_2m(struct phantom_nic *phantom, unsigned long reg)
Prepare for access to CRB register via 2MB BAR.
Definition phantom.c:299
#define PHN_RX_BUFSIZE
RX buffer size.
Definition phantom.c:96
static void phantom_write_hilo(struct phantom_nic *phantom, uint64_t value, unsigned long lo_offset, unsigned long hi_offset)
Write to Phantom CRB HI/LO register pair.
Definition phantom.c:389
static const struct settings_scope phantom_settings_scope
Phantom CLP settings scope.
Definition phantom.c:1462
static int phantom_wait_for_cmd(struct phantom_nic *phantom)
Wait for firmware to accept command.
Definition phantom.c:549
static struct settings_operations phantom_settings_operations
Phantom CLP settings operations.
Definition phantom.c:1788
static void phantom_destroy_tx_ctx(struct phantom_nic *phantom)
Destroy Phantom TX context.
Definition phantom.c:834
static int phantom_clp_cmd(struct phantom_nic *phantom, unsigned int port, unsigned int opcode, const void *data_in, void *data_out, size_t offset, size_t len)
Issue Phantom CLP command.
Definition phantom.c:1519
#define PHN_NUM_CDS
Number of TX descriptors.
Definition phantom.c:103
static void phantom_unhalt_pegs(struct phantom_nic *phantom)
Unhalt all PEGs.
Definition phantom.c:1859
static int phantom_add_macaddr(struct phantom_nic *phantom, const uint8_t *ll_addr)
Add MAC address.
Definition phantom.c:1028
#define PHN_ISSUE_CMD_TIMEOUT_MS
Maximum time to wait for firmware to accept a command.
Definition phantom.c:75
static struct pci_device_id phantom_nics[]
Phantom PCI IDs.
Definition phantom.c:2173
static void phantom_remove(struct pci_device *pci)
Remove PCI device.
Definition phantom.c:2162
static struct net_device_operations phantom_operations
Phantom net device operations.
Definition phantom.c:1447
static const unsigned long phantom_irq_mask_reg[PHN_MAX_NUM_PORTS]
Interrupt mask registers.
Definition phantom.c:205
static int phantom_init_rcvpeg(struct phantom_nic *phantom)
Initialise Phantom receive PEG.
Definition phantom.c:2026
static void phantom_writel(struct phantom_nic *phantom, uint32_t value, unsigned long reg)
Write to Phantom CRB register.
Definition phantom.c:373
static uint32_t phantom_readl(struct phantom_nic *phantom, unsigned long reg)
Read from Phantom CRB register.
Definition phantom.c:358
static void phantom_close(struct net_device *netdev)
Close NIC.
Definition phantom.c:1222
static int phantom_check_boot_enable(struct phantom_nic *phantom)
Check Phantom is enabled for boot.
Definition phantom.c:2007
static void phantom_irq(struct net_device *netdev, int enable)
Enable/disable interrupts.
Definition phantom.c:1436
static void phantom_refill_rx_ring(struct net_device *netdev)
Refill descriptor ring.
Definition phantom.c:1111
static unsigned long phantom_crb_access_32m(struct phantom_nic *phantom, unsigned long reg)
Prepare for access to CRB register via 32MB BAR.
Definition phantom.c:270
static int phantom_clp_fetch(struct phantom_nic *phantom, unsigned int port, unsigned int setting, void *data, size_t len)
Fetch Phantom CLP setting.
Definition phantom.c:1640
#define PHN_RDS_MAX_FILL
RX maximum fill level.
Definition phantom.c:93
static int phantom_fetch_setting(struct settings *settings, struct setting *setting, void *data, size_t len)
Fetch Phantom CLP setting.
Definition phantom.c:1762
#define PHN_CLP_CMD_TIMEOUT_MS
Maximum time to wait for CLP command to be issued.
Definition phantom.c:81
static int phantom_issue_cmd(struct phantom_nic *phantom, uint32_t command, uint32_t arg1, uint32_t arg2, uint32_t arg3)
Issue command to firmware.
Definition phantom.c:585
static void phantom_post_cds(struct phantom_nic *phantom, union phantom_cds *cds)
Post Phantom TX descriptor.
Definition phantom.c:952
static int phantom_map_crb(struct phantom_nic *phantom, struct pci_device *pci)
Map Phantom CRB window.
Definition phantom.c:1806
static int phantom_setting_applies(struct settings *settings, const struct setting *setting)
Check applicability of Phantom CLP setting.
Definition phantom.c:1710
static int phantom_read_test_mem(struct phantom_nic *phantom, unsigned long offset)
Read single byte from Phantom test memory.
Definition phantom.c:449
#define PHN_LINK_POLL_FREQUENCY
Link state poll frequency.
Definition phantom.c:87
#define PHN_NUM_RDS
Number of RX descriptors.
Definition phantom.c:90
static struct phantom_clp_setting clp_settings[]
Phantom CLP settings.
Definition phantom.c:1669
static int phantom_probe(struct pci_device *pci)
Probe PCI device.
Definition phantom.c:2059
static int phantom_alloc_cds(struct phantom_nic *phantom)
Allocate Phantom TX descriptor.
Definition phantom.c:927
static int phantom_transmit(struct net_device *netdev, struct io_buffer *iobuf)
Transmit packet.
Definition phantom.c:1259
static int phantom_alloc_rds(struct phantom_nic *phantom)
Allocate Phantom RX descriptor.
Definition phantom.c:872
#define PHN_NUM_SDS
Number of RX status descriptors.
Definition phantom.c:100
static void phantom_destroy_rx_ctx(struct phantom_nic *phantom)
Destroy Phantom RX context.
Definition phantom.c:729
NetXen Phantom NICs.
#define UNM_TEST_ADDR_LO
Definition phantom.h:192
#define UNM_PCIE_IRQ_STATUS_F1
Definition phantom.h:111
#define UNM_CAM_RAM_DMESG_HEAD(n)
Definition phantom.h:126
#define UNM_PCIE_IRQ_STATUS_F4
Definition phantom.h:114
#define UNM_PEG_3_HALT_STATUS
Definition phantom.h:210
#define UNM_128M_CRB_WINDOW
Definition phantom.h:67
#define UNM_PEG_2_HALT_STATUS
Definition phantom.h:206
#define UNM_NIC_REG_DUMMY_BUF_ADDR_LO
Definition phantom.h:154
#define UNM_PEG_1_HALT_STATUS
Definition phantom.h:202
#define UNM_ROMUSB_GLB_PEGTUNE_DONE
Definition phantom.h:175
#define UNM_TEST_ADDR_HI
Definition phantom.h:193
#define UNM_PCIE_IRQ_MASK_F0
Definition phantom.h:101
#define UNM_PEG_4_HALT_STATUS
Definition phantom.h:214
#define UNM_CAM_RAM_DMESG_TAIL(n)
Definition phantom.h:128
#define UNM_NIC_REG_NX_CDRP
Definition phantom.h:148
#define UNM_DMA_BUFFER_ALIGN
DMA buffer alignment.
Definition phantom.h:56
#define UNM_CAM_RAM_COLD_BOOT_MAGIC
Definition phantom.h:145
#define UNM_CAM_RAM
Definition phantom.h:122
#define UNM_NIC_REG_CMDPEG_STATE
Definition phantom.h:155
#define UNM_PCIE_IRQ_MASK_F4
Definition phantom.h:105
#define UNM_CAM_RAM_DMESG_SIG_MAGIC
Definition phantom.h:130
#define UNM_PCIE_IRQ_VECTOR
Definition phantom.h:97
#define UNM_TEST_CONTROL
Definition phantom.h:188
#define UNM_PCIE_IRQ_MASK_F3
Definition phantom.h:104
#define UNM_ROMUSB_GLB_PEGTUNE_DONE_MAGIC
Definition phantom.h:176
#define UNM_32M_CRB_WINDOW
Definition phantom.h:68
#define UNM_CAM_RAM_CLP_DATA_LO
Definition phantom.h:134
#define UNM_NIC_REG_CMDPEG_STATE_INITIALIZED
Definition phantom.h:156
#define UNM_NIC_REG_DUMMY_BUF
Definition phantom.h:158
#define UNM_NIC_REG_NX_ARG2
Definition phantom.h:150
#define UNM_CAM_RAM_BOOT_ENABLE
Definition phantom.h:141
#define UNM_NIC_REG_XG_STATE_P3
Definition phantom.h:160
#define UNM_PCIE_IRQ_STATUS_F7
Definition phantom.h:117
#define NXHAL_VERSION
Definition phantom.h:52
#define UNM_CRB_OFFSET(reg)
Definition phantom.h:92
#define UNM_NIC_REG_CMDPEG_STATE_INITIALIZE_ACK
Definition phantom.h:157
#define UNM_PCIE_IRQ_STATUS_F6
Definition phantom.h:116
#define UNM_TEST_CONTROL_ENABLE
Definition phantom.h:190
#define UNM_TEST_CONTROL_START
Definition phantom.h:189
#define UNM_ROMUSB_GLB_SW_RESET
Definition phantom.h:173
#define UNM_PCIE_IRQ_STATUS_F3
Definition phantom.h:113
#define UNM_2M_CRB_WINDOW
Definition phantom.h:69
#define __unm_dma_aligned
Mark structure as DMA-aligned.
Definition phantom.h:59
#define UNM_CAM_RAM_COLD_BOOT
Definition phantom.h:144
#define UNM_NIC_REG_DUMMY_BUF_INIT
Definition phantom.h:159
#define UNM_PCIE_IRQ_STATE_TRIGGERED(state)
Definition phantom.h:100
#define UNM_PCIE_IRQ_STATE
Definition phantom.h:99
#define UNM_PEG_0_HALT_STATUS
Definition phantom.h:198
#define UNM_PCIE_IRQ_STATUS_F0
Definition phantom.h:110
#define UNM_CAM_RAM_PORT_MODE_AUTO_NEG_1G
Definition phantom.h:125
#define UNM_TEST_RDDATA_HI
Definition phantom.h:195
#define UNM_PCIE_IRQ_VECTOR_BIT(n)
Definition phantom.h:98
#define UNM_NIC_REG_XG_STATE_P3_LINK(port, state_p3)
Definition phantom.h:161
#define UNM_ROMUSB_GLB_SW_RESET_MAGIC
Definition phantom.h:174
#define UNM_CAM_RAM_WOL_PORT_MODE
Definition phantom.h:142
#define UNM_NIC_REG_XG_STATE_P3_LINK_UP
Definition phantom.h:163
#define UNM_TEST_CONTROL_BUSY
Definition phantom.h:191
#define UNM_PCIE_IRQ_MASK_F2
Definition phantom.h:103
#define UNM_NIC_REG_RCVPEG_STATE_INITIALIZED
Definition phantom.h:166
#define UNM_NIC_REG_XG_STATE_P3_LINK_DOWN
Definition phantom.h:164
#define UNM_NIC_REG_NX_ARG1
Definition phantom.h:149
#define UNM_CRB_BLK(reg)
Definition phantom.h:91
#define UNM_PCIE_IRQ_MASK_MAGIC
Definition phantom.h:109
#define UNM_CAM_RAM_NUM_DMESG_BUFFERS
Definition phantom.h:131
#define UNM_NIC_REG_RCVPEG_STATE
Definition phantom.h:165
#define UNM_PCIE_IRQ_STATUS_F2
Definition phantom.h:112
#define UNM_PCIE_IRQ_STATUS_MAGIC
Definition phantom.h:118
#define UNM_CAM_RAM_CLP_STATUS_DONE
Definition phantom.h:138
#define UNM_CAM_RAM_CLP_STATUS_START
Definition phantom.h:137
#define UNM_PCIE_IRQ_MASK_F7
Definition phantom.h:108
#define UNM_CAM_RAM_CLP_COMMAND
Definition phantom.h:132
#define UNM_CAM_RAM_CLP_STATUS
Definition phantom.h:136
#define UNM_PCIE_IRQ_MASK_F5
Definition phantom.h:106
@ UNM_CRB_BLK_PCIE
Definition phantom.h:80
@ UNM_CRB_BLK_CAM
Definition phantom.h:81
@ UNM_CRB_BLK_PEG_1
Definition phantom.h:85
@ UNM_CRB_BLK_PEG_2
Definition phantom.h:86
@ UNM_CRB_BLK_ROMUSB
Definition phantom.h:82
@ UNM_CRB_BLK_PEG_0
Definition phantom.h:84
@ UNM_CRB_BLK_PEG_4
Definition phantom.h:88
@ UNM_CRB_BLK_TEST
Definition phantom.h:83
@ UNM_CRB_BLK_PEG_3
Definition phantom.h:87
#define UNM_CAM_RAM_CLP_DATA_HI
Definition phantom.h:135
#define UNM_NIC_REG_NX_ARG3
Definition phantom.h:151
#define UNM_CAM_RAM_MAC_ADDRS
Definition phantom.h:143
#define UNM_CAM_RAM_DMESG_SIG(n)
Definition phantom.h:129
#define UNM_NIC_REG_NX_SIGN
Definition phantom.h:152
#define UNM_PCIE_IRQ_MASK_F1
Definition phantom.h:102
#define UNM_PCIE_IRQ_MASK_F6
Definition phantom.h:107
#define UNM_PCIE_IRQ_STATUS_F5
Definition phantom.h:115
#define UNM_TEST_RDDATA_LO
Definition phantom.h:194
#define UNM_NIC_REG_DUMMY_BUF_ADDR_HI
Definition phantom.h:153
@ UNM_MAC_DEL
Delete MAC address.
Definition phantom_hw.h:137
@ UNM_MAC_ADD
Add MAC address.
Definition phantom_hw.h:136
@ UNM_NIC_REQUEST
NIC request.
Definition phantom_hw.h:186
@ UNM_TX_ETHER_PKT
Transmit raw Ethernet.
Definition phantom_hw.h:185
@ UNM_MAC_EVENT
Add/delete MAC address.
Definition phantom_hw.h:174
@ UNM_SYN_OFFLOAD
Definition phantom_hw.h:71
@ UNM_RXPKT_DESC
Definition phantom_hw.h:72
int register_settings(struct settings *settings, struct settings *parent, const char *name)
Register settings block.
Definition settings.c:476
void unregister_settings(struct settings *settings)
Unregister settings block.
Definition settings.c:515
int setting_cmp(const struct setting *a, const struct setting *b)
Compare two settings.
Definition settings.c:1121
u16 length
Definition sky2.h:1
unsigned char byte
Definition smc9000.h:38
SPI interface.
#define container_of(ptr, type, field)
Get containing structure.
Definition stddef.h:36
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
A command-line command.
Definition command.h:10
A persistent I/O buffer.
Definition iobuf.h:38
void * data
Start of data.
Definition iobuf.h:53
Network device operations.
Definition netdevice.h:214
A network device.
Definition netdevice.h:353
nx_hostrq_cds_ring_t cds_ring
A PCI device ID list entry.
Definition pci.h:175
A PCI device.
Definition pci.h:211
uint32_t busdevfn
Segment, bus, device, and function (bus:dev.fn) number.
Definition pci.h:238
struct device dev
Generic device.
Definition pci.h:213
A PCI driver.
Definition pci.h:252
int(* probe)(struct pci_device *pci)
Probe device.
Definition pci.h:265
A Phantom CLP setting.
Definition phantom.c:1661
unsigned int clp_setting
Setting number.
Definition phantom.c:1665
const struct setting * setting
iPXE setting
Definition phantom.c:1663
RX context creation request and response buffers.
Definition phantom.c:118
struct nx_hostrq_rx_ctx_s rx_ctx
Definition phantom.c:120
struct phantom_create_rx_ctx_rqrsp::@265042017201055275054063032263156076203065221067 hostrq
struct phantom_create_rx_ctx_rqrsp::@103126053352001171043311300325004331314037023173 cardrsp
struct nx_hostrq_rds_ring_s rds
Definition phantom.c:121
struct nx_hostrq_sds_ring_s sds
Definition phantom.c:122
TX context creation request and response buffers.
Definition phantom.c:132
struct phantom_create_tx_ctx_rqrsp::@172170073266135175304203367307023151120110017113 cardrsp
struct phantom_create_tx_ctx_rqrsp::@032124110163106347213265071271256070346141305365 hostrq
struct nx_hostrq_tx_ctx_s tx_ctx
Definition phantom.c:134
A Phantom descriptor ring set.
Definition phantom.c:106
struct phantom_sds sds[PHN_NUM_SDS]
RX status descriptors.
Definition phantom.c:110
volatile uint32_t cmd_cons
TX consumer index.
Definition phantom.c:114
struct phantom_rds rds[PHN_NUM_RDS]
RX descriptors.
Definition phantom.c:108
union phantom_cds cds[PHN_NUM_CDS]
TX descriptors.
Definition phantom.c:112
A Phantom NIC.
Definition phantom.c:142
unsigned int port
Port number.
Definition phantom.c:153
unsigned long rds_producer_crb
RX descriptor producer CRB offset.
Definition phantom.c:159
unsigned long(* crb_access)(struct phantom_nic *phantom, unsigned long reg)
CRB window access method.
Definition phantom.c:148
unsigned long crb_window
Current CRB window.
Definition phantom.c:146
uint32_t link_state
Last known link state.
Definition phantom.c:195
unsigned long link_poll_timer
Link state poll timer.
Definition phantom.c:197
struct settings settings
Non-volatile settings.
Definition phantom.c:201
unsigned long sds_irq_mask_crb
RX interrupt mask CRB offset.
Definition phantom.c:163
unsigned int sds_consumer_idx
RX status consumer index.
Definition phantom.c:172
void * bar0
BAR 0.
Definition phantom.c:144
uint16_t rx_context_id
RX context ID.
Definition phantom.c:157
struct io_buffer * cds_iobuf[PHN_NUM_CDS]
TX I/O buffers.
Definition phantom.c:187
unsigned int sds_irq_enabled
RX interrupts enabled.
Definition phantom.c:165
struct io_buffer * rds_iobuf[PHN_RDS_MAX_FILL]
RX I/O buffers.
Definition phantom.c:174
unsigned int rds_producer_idx
RX producer index.
Definition phantom.c:168
unsigned int rds_consumer_idx
RX consumer index.
Definition phantom.c:170
struct phantom_descriptor_rings * desc
Descriptor rings.
Definition phantom.c:191
unsigned long cds_producer_crb
TX descriptor producer CRB offset.
Definition phantom.c:180
unsigned int cds_producer_idx
TX producer index.
Definition phantom.c:183
unsigned long sds_consumer_crb
RX status descriptor consumer CRB offset.
Definition phantom.c:161
uint16_t tx_context_id
TX context ID.
Definition phantom.c:178
unsigned int cds_consumer_idx
TX consumer index.
Definition phantom.c:185
A setting.
Definition settings.h:24
const char * name
Name.
Definition settings.h:29
const struct settings_scope * scope
Setting scope (or NULL)
Definition settings.h:50
uint64_t tag
Setting tag, if applicable.
Definition settings.h:44
Settings block operations.
Definition settings.h:86
A setting scope.
Definition settings.h:177
A settings block.
Definition settings.h:133
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition timer.c:79
Phantom CLP data.
Definition phantom.c:1467
struct phantom_clp_data::@115367022245165311220105337241123151022175236317 dwords
Dwords for the CLP interface.
uint32_t hi
High dword, in network byte order.
Definition phantom.c:1478
uint8_t bytes[8]
Data bytes.
Definition phantom.c:1474
uint32_t lo
Low dword, in network byte order.
Definition phantom.c:1480
#define readl
Definition w89c840.c:157
#define writel
Definition w89c840.c:160
u8 tx[WPA_TKIP_MIC_KEY_LEN]
MIC key for packets to the AP.
Definition wpa.h:4
static struct xen_remove_from_physmap * remove
Definition xenmem.h:40