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 
25 FILE_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 */
114  volatile uint32_t cmd_cons;
115 };
116 
117 /** RX context creation request and response buffers */
119  struct {
124  struct {
129 };
130 
131 /** TX context creation request and response buffers */
133  struct {
136  struct {
139 };
140 
141 /** A Phantom NIC */
142 struct 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 */
205 static const unsigned long phantom_irq_mask_reg[PHN_MAX_NUM_PORTS] = {
214 };
215 
216 /** Interrupt status registers */
217 static const unsigned long phantom_irq_status_reg[PHN_MAX_NUM_PORTS] = {
226 };
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  */
241 static 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  */
270 static 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  */
299 static unsigned long phantom_crb_access_2m ( struct phantom_nic *phantom,
300  unsigned long reg ) {
301  static const struct {
302  uint8_t block;
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  */
358 static 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  */
373 static 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  */
389 static inline void phantom_write_hilo ( struct phantom_nic *phantom,
390  uint64_t value,
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  */
414 static 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  */
449 static 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  */
480 static int phantom_dmesg ( struct phantom_nic *phantom, unsigned int log,
481  unsigned int max_lines ) {
482  uint32_t head;
483  uint32_t tail;
484  uint32_t sig;
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 );
499  if ( sig != UNM_CAM_RAM_DMESG_SIG_MAGIC ) {
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  */
529 static void __attribute__ (( unused ))
530 phantom_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  */
549 static 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;
562  case NX_CDRP_RSP_TIMEOUT:
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  */
585 static int phantom_issue_cmd ( struct phantom_nic *phantom,
587  uint32_t arg3 ) {
589  int rc;
590 
591  /* Issue command */
593  NXHAL_VERSION );
594  DBGC2 ( phantom, "Phantom %p issuing command %08x (%08x, %08x, "
595  "%08x)\n", phantom, command, arg1, arg2, arg3 );
600  phantom_writel ( phantom, NX_CDRP_FORM_CMD ( command ),
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  */
622 static 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  */
638 static 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 ) );
662  buf->hostrq.rx_ctx.num_rds_rings = cpu_to_le16 ( 1 );
663  buf->hostrq.rx_ctx.num_sds_rings = cpu_to_le16 ( 1 );
664  buf->hostrq.rds.host_phys_addr =
665  cpu_to_le64 ( virt_to_bus ( phantom->desc->rds ) );
669  buf->hostrq.sds.host_phys_addr =
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  */
729 static 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  */
763 static 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  */
834 static 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  */
872 static 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  */
899 static 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  */
927 static 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  */
952 static 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  */
988 static 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  */
1028 static 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  */
1044 static 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  */
1064 static void phantom_poll_link_state ( struct net_device *netdev ) {
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 */
1082  link = UNM_NIC_REG_XG_STATE_P3_LINK ( phantom->port,
1083  phantom->link_state );
1084  switch ( link ) {
1086  DBGC ( phantom, "Phantom %p link is up\n", phantom );
1087  netdev_link_up ( netdev );
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  */
1111 static void phantom_refill_rx_ring ( struct net_device *netdev ) {
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  */
1162 static 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  */
1222 static 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  */
1259 static int phantom_transmit ( struct net_device *netdev,
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  */
1299 static 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] );
1336  phantom_readl ( phantom, UNM_PCIE_IRQ_VECTOR );
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  */
1436 static 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 */
1481  } dwords;
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  */
1491 static int phantom_clp_wait ( struct phantom_nic *phantom ) {
1492  unsigned int retries;
1493  uint32_t status;
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  */
1519 static 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;
1527  uint32_t command;
1528  uint32_t status;
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  */
1615 static 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  */
1640 static 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  */
1679 static 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++ ) {
1688  clp_setting = &clp_settings[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 */
1790  .store = phantom_store_setting,
1791  .fetch = phantom_fetch_setting,
1792 };
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  */
1806 static 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 );
1833  phantom->crb_access = phantom_crb_access_2m;
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  */
1859 static 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  */
1880 static 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  */
1969 static 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  */
2007 static 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  */
2026 static 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  */
2059 static 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,
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:
2151  netdev_nullify ( netdev );
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  */
2162 static 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 );
2168  netdev_nullify ( netdev );
2169  netdev_put ( netdev );
2170 }
2171 
2172 /** Phantom PCI IDs */
2173 static struct pci_device_id phantom_nics[] = {
2174  PCI_ROM ( 0x4040, 0x0100, "nx", "NX", 0 ),
2175 };
2176 
2177 /** Phantom PCI driver */
2178 struct pci_driver phantom_driver __pci_driver = {
2179  .ids = phantom_nics,
2180  .id_count = ( sizeof ( phantom_nics ) / sizeof ( phantom_nics[0] ) ),
2181  .probe = phantom_probe,
2183 };
A Phantom CLP setting.
Definition: phantom.c:1661
static int phantom_check_boot_enable(struct phantom_nic *phantom)
Check Phantom is enabled for boot.
Definition: phantom.c:2007
#define UNM_CAM_RAM_WOL_PORT_MODE
Definition: phantom.h:142
static struct settings_operations phantom_settings_operations
Phantom CLP settings operations.
Definition: phantom.c:1788
#define PCI_FUNC(busdevfn)
Definition: pci.h:281
#define UNM_PCIE_IRQ_MASK_F1
Definition: phantom.h:102
#define UNM_TEST_RDDATA_LO
Definition: phantom.h:194
#define iob_pull(iobuf, len)
Definition: iobuf.h:102
#define __attribute__(x)
Definition: compiler.h:10
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 EINVAL
Invalid argument.
Definition: errno.h:428
unsigned long crb_window
Current CRB window.
Definition: phantom.c:146
u16 length
Definition: sky2.h:9
#define UNM_PCIE_IRQ_STATUS_MAGIC
Definition: phantom.h:118
#define PCI_BUS(busdevfn)
Definition: pci.h:279
unsigned long cds_producer_crb
TX descriptor producer CRB offset.
Definition: phantom.c:180
iPXE I/O API
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
unsigned int sds_irq_enabled
RX interrupts enabled.
Definition: phantom.c:165
unsigned short uint16_t
Definition: stdint.h:11
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
Phantom CLP data.
Definition: phantom.c:1467
#define UNM_TEST_ADDR_HI
Definition: phantom.h:193
static void netdev_tx_complete(struct net_device *netdev, struct io_buffer *iobuf)
Complete network transmission.
Definition: netdevice.h:752
wmb()
Transmit raw Ethernet.
Definition: phantom_hw.h:185
#define UNM_NIC_REG_XG_STATE_P3
Definition: phantom.h:160
struct phantom_rds rds[PHN_NUM_RDS]
RX descriptors.
Definition: phantom.c:108
#define PHN_RX_BUFSIZE
RX buffer size.
Definition: phantom.c:96
#define iob_put(iobuf, len)
Definition: iobuf.h:120
#define UNM_ROMUSB_GLB_SW_RESET
Definition: phantom.h:173
static int phantom_alloc_cds(struct phantom_nic *phantom)
Allocate Phantom TX descriptor.
Definition: phantom.c:927
#define UNM_ROMUSB_GLB_PEGTUNE_DONE
Definition: phantom.h:175
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition: netdevice.c:586
struct phantom_create_rx_ctx_rqrsp::@93 cardrsp
#define UNM_TEST_CONTROL_ENABLE
Definition: phantom.h:190
#define UNM_CAM_RAM_DMESG_SIG_MAGIC
Definition: phantom.h:130
static void phantom_post_cds(struct phantom_nic *phantom, union phantom_cds *cds)
Post Phantom TX descriptor.
Definition: phantom.c:952
struct nx_hostrq_rds_ring_s rds
Definition: phantom.c:121
A PCI driver.
Definition: pci.h:247
#define UNM_PEG_3_HALT_STATUS
Definition: phantom.h:210
static void phantom_get_macaddr(struct phantom_nic *phantom, uint8_t *hw_addr)
Read Phantom MAC address.
Definition: phantom.c:1969
#define UNM_PCIE_IRQ_STATUS_F6
Definition: phantom.h:116
static unsigned int unsigned int reg
Definition: myson.h:162
#define UNM_PCIE_IRQ_VECTOR_BIT(n)
Definition: phantom.h:98
#define PHN_CLP_BLKSIZE
Definition: phantom.c:1483
u8 sig
Definition: CIB_PRM.h:43
void unregister_settings(struct settings *settings)
Unregister settings block.
Definition: settings.c:514
#define le32_to_cpu(value)
Definition: byteswap.h:113
int(* open)(struct net_device *netdev)
Open network device.
Definition: netdevice.h:222
unsigned long link_poll_timer
Link state poll timer.
Definition: phantom.c:197
#define UNM_NIC_REG_RCVPEG_STATE_INITIALIZED
Definition: phantom.h:166
uint8_t opcode
Opcode.
Definition: ena.h:16
#define UNM_TEST_CONTROL_START
Definition: phantom.h:189
uint16_t tx_context_id
TX context ID.
Definition: phantom.c:178
#define NX_FILL_1(_ptr, _index,...)
Definition: nx_bitops.h:162
Error codes.
#define NX_FILL_7(_ptr, _index,...)
Definition: nx_bitops.h:180
#define UNM_CAM_RAM_NUM_DMESG_BUFFERS
Definition: phantom.h:131
u8 owner
Definition: CIB_PRM.h:36
TX context creation request and response buffers.
Definition: phantom.c:132
A command-line command.
Definition: command.h:9
I/O buffers.
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:146
#define PHN_NUM_SDS
Number of RX status descriptors.
Definition: phantom.c:100
struct pci_device_id * ids
PCI ID table.
Definition: pci.h:249
#define UNM_TEST_ADDR_LO
Definition: phantom.h:192
static int phantom_read_test_mem(struct phantom_nic *phantom, unsigned long offset)
Read single byte from Phantom test memory.
Definition: phantom.c:449
struct arbelprm_completion_with_error error
Definition: arbel.h:12
struct nx_hostrq_tx_ctx_s tx_ctx
Definition: phantom.c:134
#define PHN_CMDPEG_INIT_TIMEOUT_SEC
Maximum time to wait for command PEG to initialise.
Definition: phantom.c:69
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
NIC request.
Definition: phantom_hw.h:186
#define UNM_PCIE_IRQ_MASK_F6
Definition: phantom.h:107
#define PHN_RCVPEG_INIT_TIMEOUT_SEC
Maximum time to wait for receive PEG to initialise.
Definition: phantom.c:72
#define DBGC(...)
Definition: compiler.h:505
A Phantom descriptor ring set.
Definition: phantom.c:106
#define UNM_CAM_RAM_COLD_BOOT
Definition: phantom.h:144
#define UNM_NIC_REG_NX_ARG3
Definition: phantom.h:151
#define UNM_NIC_REG_DUMMY_BUF
Definition: phantom.h:158
const uint8_t * ll_broadcast
Link-layer broadcast address.
Definition: netdevice.h:389
#define UNM_PCIE_IRQ_MASK_MAGIC
Definition: phantom.h:109
#define __unm_dma_aligned
Mark structure as DMA-aligned.
Definition: phantom.h:59
unsigned long long uint64_t
Definition: stdint.h:13
static void *__malloc malloc_phys(size_t size, size_t phys_align)
Allocate memory with specified physical alignment.
Definition: malloc.h:62
#define PCI_BASE_ADDRESS_0
Definition: pci.h:62
static unsigned int phantom_clp_setting(struct phantom_nic *phantom, const struct setting *setting)
Find Phantom CLP setting.
Definition: phantom.c:1680
#define UNM_32M_CRB_WINDOW
Definition: phantom.h:68
#define cpu_to_le64(value)
Definition: byteswap.h:108
void netdev_link_down(struct net_device *netdev)
Mark network device as having link down.
Definition: netdevice.c:230
#define PHN_NUM_RDS
Number of RX descriptors.
Definition: phantom.c:90
#define UNM_CAM_RAM_CLP_STATUS_START
Definition: phantom.h:137
uint32_t buffer
Buffer index (or NETVSC_RNDIS_NO_BUFFER)
Definition: netvsc.h:16
uint8_t head
Head number.
Definition: int13.h:34
#define UNM_NIC_REG_CMDPEG_STATE_INITIALIZE_ACK
Definition: phantom.h:157
static int phantom_setting_applies(struct settings *settings, const struct setting *setting)
Check applicability of Phantom CLP setting.
Definition: phantom.c:1710
struct phantom_create_rx_ctx_rqrsp::@92 hostrq
static int phantom_add_macaddr(struct phantom_nic *phantom, const uint8_t *ll_addr)
Add MAC address.
Definition: phantom.c:1028
#define UNM_NIC_REG_CMDPEG_STATE_INITIALIZED
Definition: phantom.h:156
#define UNM_PCIE_IRQ_STATUS_F7
Definition: phantom.h:117
#define NX_CDRP_RSP_TIMEOUT
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
void adjust_pci_device(struct pci_device *pci)
Enable PCI device.
Definition: pci.c:154
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:129
struct device dev
Generic device.
Definition: pci.h:208
static struct settings * netdev_settings(struct net_device *netdev)
Get per-netdevice configuration settings block.
Definition: netdevice.h:583
#define NX_CDRP_CMD_CREATE_RX_CTX
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:496
__be32 out[4]
Definition: CIB_PRM.h:36
#define UNM_NIC_REG_CMDPEG_STATE
Definition: phantom.h:155
#define ECANCELED
Operation canceled.
Definition: errno.h:343
static int phantom_clp_wait(struct phantom_nic *phantom)
Wait for Phantom CLP command to complete.
Definition: phantom.c:1491
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
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 unsigned int unsigned long arg1
Definition: xen.h:43
#define NX_CDRP_IS_RSP(rsp)
Dynamic memory allocation.
struct phantom_descriptor_rings * desc
Descriptor rings.
Definition: phantom.c:191
#define UNM_PCIE_IRQ_MASK_F5
Definition: phantom.h:106
const char * name
Name.
Definition: settings.h:28
static int phantom_map_crb(struct phantom_nic *phantom, struct pci_device *pci)
Map Phantom CRB window.
Definition: phantom.c:1806
#define UNM_PCIE_IRQ_STATUS_F0
Definition: phantom.h:110
#define UNM_NIC_REG_DUMMY_BUF_INIT
Definition: phantom.h:159
uint8_t status
Status.
Definition: ena.h:16
uint64_t tag
Setting tag, if applicable.
Definition: settings.h:43
static void netdev_init(struct net_device *netdev, struct net_device_operations *op)
Initialise a network device.
Definition: netdevice.h:515
Add/delete MAC address.
Definition: phantom_hw.h:174
static void pci_set_drvdata(struct pci_device *pci, void *priv)
Set PCI driver-private data.
Definition: pci.h:359
uint16_t busdevfn
PCI bus:dev.fn address.
Definition: ena.h:28
#define ENOMEM
Not enough space.
Definition: errno.h:534
#define PHN_ISSUE_CMD_TIMEOUT_MS
Maximum time to wait for firmware to accept a command.
Definition: phantom.c:75
const struct setting * setting
iPXE setting
Definition: phantom.c:1663
#define UNM_TEST_CONTROL_BUSY
Definition: phantom.h:191
#define NX_CDRP_CMD_DESTROY_TX_CTX
void * memcpy(void *dest, const void *src, size_t len) __nonnull
struct phantom_clp_data::@96 dwords
Dwords for the CLP interface.
#define PHN_RDS_MAX_FILL
RX maximum fill level.
Definition: phantom.c:93
volatile uint32_t cmd_cons
TX consumer index.
Definition: phantom.c:114
SPI interface.
u8 port
Port number.
Definition: CIB_PRM.h:31
NetXen Phantom NICs.
#define UNM_CAM_RAM_CLP_COMMAND
Definition: phantom.h:132
static __always_inline unsigned long virt_to_bus(volatile const void *addr)
Convert virtual address to a bus address.
Definition: io.h:183
#define UNM_2M_CRB_WINDOW
Definition: phantom.h:69
struct phantom_sds sds[PHN_NUM_SDS]
RX status descriptors.
Definition: phantom.c:110
Assertions.
#define UNM_DMA_BUFFER_ALIGN
DMA buffer alignment.
Definition: phantom.h:56
#define be32_to_cpu(value)
Definition: byteswap.h:116
#define UNM_ROMUSB_GLB_SW_RESET_MAGIC
Definition: phantom.h:174
#define PHN_LINK_POLL_FREQUENCY
Link state poll frequency.
Definition: phantom.c:87
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
void * bar0
BAR 0.
Definition: phantom.c:144
#define NX_CAP0_LEGACY_CONTEXT
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:572
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
Ethernet protocol.
int pci_read_config_dword(struct pci_device *pci, unsigned int where, uint32_t *value)
Read 32-bit dword from PCI configuration space.
#define NX_CDRP_SIGNATURE_MAKE(pcifn, version)
static int phantom_dmesg(struct phantom_nic *phantom, unsigned int log, unsigned int max_lines)
Dump Phantom firmware dmesg log.
Definition: phantom.c:480
#define UNM_CRB_OFFSET(reg)
Definition: phantom.h:92
void * priv
Driver private data.
Definition: netdevice.h:431
#define UNM_PCIE_IRQ_STATUS_F2
Definition: phantom.h:112
#define DBGC_HDA(...)
Definition: compiler.h:506
static void phantom_post_rds(struct phantom_nic *phantom, struct phantom_rds *rds)
Post Phantom RX descriptor.
Definition: phantom.c:899
static void netdev_link_up(struct net_device *netdev)
Mark network device as having link up.
Definition: netdevice.h:774
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
#define UNM_CAM_RAM
Definition: phantom.h:122
#define UNM_CAM_RAM_MAC_ADDRS
Definition: phantom.h:143
uint32_t hi
High dword, in network byte order.
Definition: phantom.c:1478
#define UNM_PEG_2_HALT_STATUS
Definition: phantom.h:206
#define UNM_PCIE_IRQ_MASK_F7
Definition: phantom.h:108
unsigned int rds_producer_idx
RX producer index.
Definition: phantom.c:168
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
static struct net_device * netdev
Definition: gdbudp.c:52
#define UNM_CAM_RAM_DMESG_TAIL(n)
Definition: phantom.h:128
u32 link
Link to next descriptor.
Definition: ar9003_mac.h:68
unsigned long pci_bar_start(struct pci_device *pci, unsigned int reg)
Find the start of a PCI BAR.
Definition: pci.c:96
#define UNM_CAM_RAM_CLP_STATUS
Definition: phantom.h:136
#define NX_CDRP_FORM_CMD(cmd)
struct settings settings
Non-volatile settings.
Definition: phantom.c:201
#define UNM_CAM_RAM_BOOT_ENABLE
Definition: phantom.h:141
static int phantom_init_rcvpeg(struct phantom_nic *phantom)
Initialise Phantom receive PEG.
Definition: phantom.c:2026
#define UNM_TEST_RDDATA_HI
Definition: phantom.h:195
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:941
struct nx_hostrq_sds_ring_s sds
Definition: phantom.c:122
#define UNM_PEG_1_HALT_STATUS
Definition: phantom.h:202
#define cpu_to_le32(value)
Definition: byteswap.h:107
#define EPROTO
Protocol error.
Definition: errno.h:624
#define PHN_CLP_CMD_TIMEOUT_MS
Maximum time to wait for CLP command to be issued.
Definition: phantom.c:81
static void phantom_destroy_rx_ctx(struct phantom_nic *phantom)
Destroy Phantom RX context.
Definition: phantom.c:729
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
#define UNM_CAM_RAM_CLP_DATA_LO
Definition: phantom.h:134
#define DBGC2_HDA(...)
Definition: compiler.h:523
Configuration settings.
union phantom_cds cds[PHN_NUM_CDS]
TX descriptors.
Definition: phantom.c:112
#define PCI_BUSDEVFN(segment, bus, slot, func)
Definition: pci_io.h:28
#define UNM_CAM_RAM_DMESG_SIG(n)
Definition: phantom.h:129
nx_hostrq_cds_ring_t cds_ring
static int phantom_create_rx_ctx(struct phantom_nic *phantom)
Create Phantom RX context.
Definition: phantom.c:638
static int phantom_probe(struct pci_device *pci)
Probe PCI device.
Definition: phantom.c:2059
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
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static void phantom_irq(struct net_device *netdev, int enable)
Enable/disable interrupts.
Definition: phantom.c:1436
static const struct settings_scope phantom_settings_scope
Phantom CLP settings scope.
Definition: phantom.c:1462
struct refcnt refcnt
Reference counter.
Definition: netdevice.h:354
#define UNM_CAM_RAM_DMESG_HEAD(n)
Definition: phantom.h:126
#define UNM_CAM_RAM_CLP_DATA_HI
Definition: phantom.h:135
union aes_table_entry entry[256]
Table entries, indexed by S(N)
Definition: aes.c:26
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:307
unsigned long pci_bar_size(struct pci_device *pci, unsigned int reg)
Find the size of a PCI BAR.
Definition: pciextra.c:92
uint32_t link_state
Last known link state.
Definition: phantom.c:195
#define PCI_SLOT(busdevfn)
Definition: pci.h:280
#define UNM_PEG_0_HALT_STATUS
Definition: phantom.h:198
PCI bus.
static struct phantom_clp_setting clp_settings[]
Phantom CLP settings.
Definition: phantom.c:1669
A PCI device.
Definition: pci.h:206
int register_netdev(struct net_device *netdev)
Register network device.
Definition: netdevice.c:759
uint8_t bytes[8]
Data bytes.
Definition: phantom.c:1474
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:155
const char * eth_ntoa(const void *ll_addr)
Transcribe Ethernet address.
Definition: ethernet.c:175
static void phantom_destroy_tx_ctx(struct phantom_nic *phantom)
Destroy Phantom TX context.
Definition: phantom.c:834
A network device.
Definition: netdevice.h:352
#define UNM_PCIE_IRQ_STATUS_F3
Definition: phantom.h:113
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
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 void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:528
Settings block operations.
Definition: settings.h:85
A settings block.
Definition: settings.h:132
#define UNM_PCIE_IRQ_MASK_F0
Definition: phantom.h:101
static void phantom_poll(struct net_device *netdev)
Poll for received packets.
Definition: phantom.c:1299
#define UNM_NIC_REG_RCVPEG_STATE
Definition: phantom.h:165
unsigned char uint8_t
Definition: stdint.h:10
#define UNM_NIC_REG_XG_STATE_P3_LINK_DOWN
Definition: phantom.h:164
static uint32_t phantom_readl(struct phantom_nic *phantom, unsigned long reg)
Read from Phantom CRB register.
Definition: phantom.c:358
static void phantom_refill_rx_ring(struct net_device *netdev)
Refill descriptor ring.
Definition: phantom.c:1111
RX context creation request and response buffers.
Definition: phantom.c:118
unsigned int clp_setting
Setting number.
Definition: phantom.c:1665
A setting scope.
Definition: settings.h:176
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
#define UNM_PCIE_IRQ_VECTOR
Definition: phantom.h:97
struct io_buffer * cds_iobuf[PHN_NUM_CDS]
TX I/O buffers.
Definition: phantom.c:187
#define NX_CDRP_FORM_RSP(rsp)
#define ETH_ALEN
Definition: if_ether.h:8
A PCI device ID list entry.
Definition: pci.h:170
static int command
Definition: epic100.c:68
uint32_t last
Length to read in last segment, or zero.
Definition: pccrc.h:30
#define UNM_CAM_RAM_COLD_BOOT_MAGIC
Definition: phantom.h:145
#define le16_to_cpu(value)
Definition: byteswap.h:112
unsigned int uint32_t
Definition: stdint.h:12
Delete MAC address.
Definition: phantom_hw.h:137
static int phantom_create_tx_ctx(struct phantom_nic *phantom)
Create Phantom TX context.
Definition: phantom.c:763
static struct pci_device_id phantom_nics[]
Phantom PCI IDs.
Definition: phantom.c:2173
#define PHN_TEST_MEM_TIMEOUT_MS
Maximum time to wait for test memory.
Definition: phantom.c:78
#define UNM_NIC_REG_XG_STATE_P3_LINK(port, state_p3)
Definition: phantom.h:161
unsigned char byte
Definition: smc9000.h:38
#define UNM_NIC_REG_NX_SIGN
Definition: phantom.h:152
#define UNM_PCIE_IRQ_STATUS_F1
Definition: phantom.h:111
static struct xen_remove_from_physmap * remove
Definition: xenmem.h:39
struct nx_hostrq_rx_ctx_s rx_ctx
Definition: phantom.c:120
A setting.
Definition: settings.h:23
Network device operations.
Definition: netdevice.h:213
static const unsigned long phantom_irq_status_reg[PHN_MAX_NUM_PORTS]
Interrupt status registers.
Definition: phantom.c:217
void netdev_rx(struct net_device *netdev, struct io_buffer *iobuf)
Add packet to receive queue.
Definition: netdevice.c:548
struct device * dev
Underlying hardware device.
Definition: netdevice.h:364
#define NX_CAP0_LEGACY_MN
Network device management.
#define UNM_PCIE_IRQ_STATE
Definition: phantom.h:99
unsigned long(* crb_access)(struct phantom_nic *phantom, unsigned long reg)
CRB window access method.
Definition: phantom.c:148
static void * pci_get_drvdata(struct pci_device *pci)
Get PCI driver-private data.
Definition: pci.h:369
unsigned long sds_consumer_crb
RX status descriptor consumer CRB offset.
Definition: phantom.c:161
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:78
#define cpu_to_be32(value)
Definition: byteswap.h:110
static int phantom_fetch_setting(struct settings *settings, struct setting *setting, void *data, size_t len)
Fetch Phantom CLP setting.
Definition: phantom.c:1762
uint32_t busdevfn
Segment, bus, device, and function (bus:dev.fn) number.
Definition: pci.h:233
static void phantom_unhalt_pegs(struct phantom_nic *phantom)
Unhalt all PEGs.
Definition: phantom.c:1859
void netdev_tx_complete_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Complete network transmission.
Definition: netdevice.c:470
#define NX_CDRP_CMD_CREATE_TX_CTX
static void phantom_dmesg_all(struct phantom_nic *phantom, unsigned int max_lines)
Dump Phantom firmware dmesg logs.
Definition: phantom.c:530
uint32_t len
Length.
Definition: ena.h:14
unsigned int rds_consumer_idx
RX consumer index.
Definition: phantom.c:170
uint8_t unused[32]
Unused.
Definition: eltorito.h:15
#define NX_CDRP_RSP_FAIL
#define ENOBUFS
No buffer space available.
Definition: errno.h:498
#define DBGC2(...)
Definition: compiler.h:522
#define NX_RDS_RING_TYPE_NORMAL
uint8_t block[3][8]
DES-encrypted blocks.
Definition: mschapv2.h:12
uint16_t rx_context_id
RX context ID.
Definition: phantom.c:157
int(* probe)(struct pci_device *pci)
Probe device.
Definition: pci.h:260
#define UNM_NIC_REG_NX_CDRP
Definition: phantom.h:148
static int phantom_wait_for_cmd(struct phantom_nic *phantom)
Wait for firmware to accept command.
Definition: phantom.c:549
static void phantom_writel(struct phantom_nic *phantom, uint32_t value, unsigned long reg)
Write to Phantom CRB register.
Definition: phantom.c:373
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
void * data
Start of data.
Definition: iobuf.h:48
#define UNM_PCIE_IRQ_MASK_F4
Definition: phantom.h:105
#define EIO
Input/output error.
Definition: errno.h:433
struct phantom_create_tx_ctx_rqrsp::@94 hostrq
#define UNM_128M_CRB_WINDOW
Definition: phantom.h:67
struct net_device * alloc_etherdev(size_t priv_size)
Allocate Ethernet device.
Definition: ethernet.c:264
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:310
#define PHN_MAX_NUM_PORTS
Maximum number of ports.
Definition: phantom.c:53
#define PHN_NUM_CDS
Number of TX descriptors.
Definition: phantom.c:103
int pci_write_config_dword(struct pci_device *pci, unsigned int where, uint32_t value)
Write 32-bit dword to PCI configuration space.
#define UNM_PCIE_IRQ_STATUS_F5
Definition: phantom.h:115
#define cpu_to_le16(value)
Definition: byteswap.h:106
union @17 u
#define NX_DESTROY_CTX_RESET
uint8_t data[48]
Additional event data.
Definition: ena.h:22
unsigned long rds_producer_crb
RX descriptor producer CRB offset.
Definition: phantom.c:159
#define UNM_PCIE_IRQ_STATE_TRIGGERED(state)
Definition: phantom.h:100
static void phantom_close(struct net_device *netdev)
Close NIC.
Definition: phantom.c:1222
struct pci_driver phantom_driver __pci_driver
Phantom PCI driver.
Definition: phantom.c:2178
static int phantom_del_macaddr(struct phantom_nic *phantom, const uint8_t *ll_addr)
Remove MAC address.
Definition: phantom.c:1044
#define UNM_CAM_RAM_PORT_MODE_AUTO_NEG_1G
Definition: phantom.h:125
unsigned int sds_consumer_idx
RX status consumer index.
Definition: phantom.c:172
static void free_phys(void *ptr, size_t size)
Free memory allocated with malloc_phys()
Definition: malloc.h:77
int(* applies)(struct settings *settings, const struct setting *setting)
Check applicability of setting.
Definition: settings.h:98
int register_settings(struct settings *settings, struct settings *parent, const char *name)
Register settings block.
Definition: settings.c:475
#define NX_FILL_3(_ptr, _index,...)
Definition: nx_bitops.h:168
void mb(void)
Memory barrier.
#define NX_CDRP_RSP_OK
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_remove(struct pci_device *pci)
Remove PCI device.
Definition: phantom.c:2162
unsigned int cds_consumer_idx
TX consumer index.
Definition: phantom.c:185
#define UNM_CRB_BLK(reg)
Definition: phantom.h:91
static int phantom_init_cmdpeg(struct phantom_nic *phantom)
Initialise the Phantom command PEG.
Definition: phantom.c:1880
#define NX_CDRP_CMD_DESTROY_RX_CTX
unsigned long sds_irq_mask_crb
RX interrupt mask CRB offset.
Definition: phantom.c:163
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:387
#define UNM_NIC_REG_DUMMY_BUF_ADDR_HI
Definition: phantom.h:153
uint64_t index
Index of the first segment within the content.
Definition: pccrc.h:21
#define NX_HOST_INT_CRB_MODE_SHARED
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
struct phantom_create_tx_ctx_rqrsp::@95 cardrsp
Add MAC address.
Definition: phantom_hw.h:136
#define UNM_NIC_REG_NX_ARG1
Definition: phantom.h:149
unsigned int cds_producer_idx
TX producer index.
Definition: phantom.c:183
void * pci_ioremap(struct pci_device *pci, unsigned long bus_addr, size_t len)
Map PCI bus address as an I/O address.
const struct settings_scope * scope
Setting scope (or NULL)
Definition: settings.h:49
static unsigned int unsigned long unsigned long arg2
Definition: xen.h:66
A Phantom NIC.
Definition: phantom.c:142
#define NX_FILL_2(_ptr, _index,...)
Definition: nx_bitops.h:165
uint8_t bytes[64]
Definition: ib_mad.h:16
static const unsigned long phantom_irq_mask_reg[PHN_MAX_NUM_PORTS]
Interrupt mask registers.
Definition: phantom.c:205
#define UNM_PEG_4_HALT_STATUS
Definition: phantom.h:214
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 UNM_PCIE_IRQ_STATUS_F4
Definition: phantom.h:114
static unsigned int unsigned long unsigned long unsigned long arg3
Definition: xen.h:90
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
#define DBG_LOG
Definition: compiler.h:317
static int phantom_transmit(struct net_device *netdev, struct io_buffer *iobuf)
Transmit packet.
Definition: phantom.c:1259
uint32_t lo
Low dword, in network byte order.
Definition: phantom.c:1480
u8 signature
Signature.
Definition: CIB_PRM.h:35
#define NXHAL_VERSION
Definition: phantom.h:52
uint16_t handle
Handle.
Definition: smbios.h:16
static void phantom_poll_link_state(struct net_device *netdev)
Poll link state.
Definition: phantom.c:1064
#define PCI_SEG(busdevfn)
Definition: pci.h:278
int setting_cmp(const struct setting *a, const struct setting *b)
Compare two settings.
Definition: settings.c:1120
uint8_t hw_addr[MAX_HW_ADDR_LEN]
Hardware address.
Definition: netdevice.h:381
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
#define UNM_PCIE_IRQ_MASK_F2
Definition: phantom.h:103
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:669
#define NX_GET(_ptr, _field)
Extract value of named field (for fields up to the size of a long)
Definition: nx_bitops.h:196
String functions.
#define PCI_ROM(_vendor, _device, _name, _description, _data)
Definition: pci.h:303
#define UNM_NIC_REG_XG_STATE_P3_LINK_UP
Definition: phantom.h:163
#define UNM_NIC_REG_NX_ARG2
Definition: phantom.h:150
#define UNM_NIC_REG_DUMMY_BUF_ADDR_LO
Definition: phantom.h:154
unsigned int port
Port number.
Definition: phantom.c:153
struct io_buffer * rds_iobuf[PHN_RDS_MAX_FILL]
RX I/O buffers.
Definition: phantom.c:174
static int phantom_open(struct net_device *netdev)
Open NIC.
Definition: phantom.c:1162
u8 tx[WPA_TKIP_MIC_KEY_LEN]
MIC key for packets to the AP.
Definition: wpa.h:237
#define NX_HOST_RDS_CRB_MODE_UNIQUE
#define UNM_ROMUSB_GLB_PEGTUNE_DONE_MAGIC
Definition: phantom.h:176
static struct net_device_operations phantom_operations
Phantom net device operations.
Definition: phantom.c:1447
#define UNM_CAM_RAM_CLP_STATUS_DONE
Definition: phantom.h:138
#define UNM_TEST_CONTROL
Definition: phantom.h:188
void * memset(void *dest, int character, size_t len) __nonnull
A persistent I/O buffer.
Definition: iobuf.h:33
static int phantom_alloc_rds(struct phantom_nic *phantom)
Allocate Phantom RX descriptor.
Definition: phantom.c:872
#define UNM_PCIE_IRQ_MASK_F3
Definition: phantom.h:104
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