iPXE
Data Structures | Macros | Functions | Variables
phantom.c File Reference

NetXen Phantom NICs. More...

#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <assert.h>
#include <byteswap.h>
#include <ipxe/pci.h>
#include <ipxe/io.h>
#include <ipxe/malloc.h>
#include <ipxe/iobuf.h>
#include <ipxe/netdevice.h>
#include <ipxe/if_ether.h>
#include <ipxe/ethernet.h>
#include <ipxe/spi.h>
#include <ipxe/settings.h>
#include "phantom.h"

Go to the source code of this file.

Data Structures

struct  phantom_descriptor_rings
 A Phantom descriptor ring set. More...
 
struct  phantom_create_rx_ctx_rqrsp
 RX context creation request and response buffers. More...
 
struct  phantom_create_tx_ctx_rqrsp
 TX context creation request and response buffers. More...
 
struct  phantom_nic
 A Phantom NIC. More...
 
union  phantom_clp_data
 Phantom CLP data. More...
 
struct  phantom_clp_setting
 A Phantom CLP setting. More...
 

Macros

#define PHN_MAX_NUM_PORTS   8
 Maximum number of ports. More...
 
#define PHN_CMDPEG_INIT_TIMEOUT_SEC   50
 Maximum time to wait for command PEG to initialise. More...
 
#define PHN_RCVPEG_INIT_TIMEOUT_SEC   2
 Maximum time to wait for receive PEG to initialise. More...
 
#define PHN_ISSUE_CMD_TIMEOUT_MS   2000
 Maximum time to wait for firmware to accept a command. More...
 
#define PHN_TEST_MEM_TIMEOUT_MS   100
 Maximum time to wait for test memory. More...
 
#define PHN_CLP_CMD_TIMEOUT_MS   500
 Maximum time to wait for CLP command to be issued. More...
 
#define PHN_LINK_POLL_FREQUENCY   4096
 Link state poll frequency. More...
 
#define PHN_NUM_RDS   32
 Number of RX descriptors. More...
 
#define PHN_RDS_MAX_FILL   16
 RX maximum fill level. More...
 
#define PHN_RX_BUFSIZE
 RX buffer size. More...
 
#define PHN_NUM_SDS   32
 Number of RX status descriptors. More...
 
#define PHN_NUM_CDS   8
 Number of TX descriptors. More...
 
#define PHN_CLP_BLKSIZE   ( sizeof ( union phantom_clp_data ) )
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static unsigned long phantom_crb_access_128m (struct phantom_nic *phantom, unsigned long reg)
 Prepare for access to CRB register via 128MB BAR. More...
 
static unsigned long phantom_crb_access_32m (struct phantom_nic *phantom, unsigned long reg)
 Prepare for access to CRB register via 32MB BAR. More...
 
static unsigned long phantom_crb_access_2m (struct phantom_nic *phantom, unsigned long reg)
 Prepare for access to CRB register via 2MB BAR. More...
 
static uint32_t phantom_readl (struct phantom_nic *phantom, unsigned long reg)
 Read from Phantom CRB register. More...
 
static void phantom_writel (struct phantom_nic *phantom, uint32_t value, unsigned long reg)
 Write to Phantom CRB register. More...
 
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. More...
 
static int phantom_read_test_mem_block (struct phantom_nic *phantom, unsigned long offset, uint32_t buf[2])
 Read from Phantom test memory. More...
 
static int phantom_read_test_mem (struct phantom_nic *phantom, unsigned long offset)
 Read single byte from Phantom test memory. More...
 
static int phantom_dmesg (struct phantom_nic *phantom, unsigned int log, unsigned int max_lines)
 Dump Phantom firmware dmesg log. More...
 
static void phantom_dmesg_all (struct phantom_nic *phantom, unsigned int max_lines)
 Dump Phantom firmware dmesg logs. More...
 
static int phantom_wait_for_cmd (struct phantom_nic *phantom)
 Wait for firmware to accept command. More...
 
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. More...
 
static int phantom_issue_buf_cmd (struct phantom_nic *phantom, uint32_t command, void *buffer, size_t len)
 Issue buffer-format command to firmware. More...
 
static int phantom_create_rx_ctx (struct phantom_nic *phantom)
 Create Phantom RX context. More...
 
static void phantom_destroy_rx_ctx (struct phantom_nic *phantom)
 Destroy Phantom RX context. More...
 
static int phantom_create_tx_ctx (struct phantom_nic *phantom)
 Create Phantom TX context. More...
 
static void phantom_destroy_tx_ctx (struct phantom_nic *phantom)
 Destroy Phantom TX context. More...
 
static int phantom_alloc_rds (struct phantom_nic *phantom)
 Allocate Phantom RX descriptor. More...
 
static void phantom_post_rds (struct phantom_nic *phantom, struct phantom_rds *rds)
 Post Phantom RX descriptor. More...
 
static int phantom_alloc_cds (struct phantom_nic *phantom)
 Allocate Phantom TX descriptor. More...
 
static void phantom_post_cds (struct phantom_nic *phantom, union phantom_cds *cds)
 Post Phantom TX descriptor. More...
 
static int phantom_update_macaddr (struct phantom_nic *phantom, const uint8_t *ll_addr, unsigned int opcode)
 Add/remove MAC address. More...
 
static int phantom_add_macaddr (struct phantom_nic *phantom, const uint8_t *ll_addr)
 Add MAC address. More...
 
static int phantom_del_macaddr (struct phantom_nic *phantom, const uint8_t *ll_addr)
 Remove MAC address. More...
 
static void phantom_poll_link_state (struct net_device *netdev)
 Poll link state. More...
 
static void phantom_refill_rx_ring (struct net_device *netdev)
 Refill descriptor ring. More...
 
static int phantom_open (struct net_device *netdev)
 Open NIC. More...
 
static void phantom_close (struct net_device *netdev)
 Close NIC. More...
 
static int phantom_transmit (struct net_device *netdev, struct io_buffer *iobuf)
 Transmit packet. More...
 
static void phantom_poll (struct net_device *netdev)
 Poll for received packets. More...
 
static void phantom_irq (struct net_device *netdev, int enable)
 Enable/disable interrupts. More...
 
static int phantom_clp_wait (struct phantom_nic *phantom)
 Wait for Phantom CLP command to complete. More...
 
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. More...
 
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. More...
 
static int phantom_clp_fetch (struct phantom_nic *phantom, unsigned int port, unsigned int setting, void *data, size_t len)
 Fetch Phantom CLP setting. More...
 
static unsigned int phantom_clp_setting (struct phantom_nic *phantom, const struct setting *setting)
 Find Phantom CLP setting. More...
 
static int phantom_setting_applies (struct settings *settings, const struct setting *setting)
 Check applicability of Phantom CLP setting. More...
 
static int phantom_store_setting (struct settings *settings, const struct setting *setting, const void *data, size_t len)
 Store Phantom CLP setting. More...
 
static int phantom_fetch_setting (struct settings *settings, struct setting *setting, void *data, size_t len)
 Fetch Phantom CLP setting. More...
 
static int phantom_map_crb (struct phantom_nic *phantom, struct pci_device *pci)
 Map Phantom CRB window. More...
 
static void phantom_unhalt_pegs (struct phantom_nic *phantom)
 Unhalt all PEGs. More...
 
static int phantom_init_cmdpeg (struct phantom_nic *phantom)
 Initialise the Phantom command PEG. More...
 
static void phantom_get_macaddr (struct phantom_nic *phantom, uint8_t *hw_addr)
 Read Phantom MAC address. More...
 
static int phantom_check_boot_enable (struct phantom_nic *phantom)
 Check Phantom is enabled for boot. More...
 
static int phantom_init_rcvpeg (struct phantom_nic *phantom)
 Initialise Phantom receive PEG. More...
 
static int phantom_probe (struct pci_device *pci)
 Probe PCI device. More...
 
static void phantom_remove (struct pci_device *pci)
 Remove PCI device. More...
 

Variables

static const unsigned long phantom_irq_mask_reg [PHN_MAX_NUM_PORTS]
 Interrupt mask registers. More...
 
static const unsigned long phantom_irq_status_reg [PHN_MAX_NUM_PORTS]
 Interrupt status registers. More...
 
static struct net_device_operations phantom_operations
 Phantom net device operations. More...
 
static const struct settings_scope phantom_settings_scope
 Phantom CLP settings scope. More...
 
static struct phantom_clp_setting clp_settings []
 Phantom CLP settings. More...
 
static struct settings_operations phantom_settings_operations
 Phantom CLP settings operations. More...
 
static struct pci_device_id phantom_nics []
 Phantom PCI IDs. More...
 
struct pci_driver phantom_driver __pci_driver
 Phantom PCI driver. More...
 

Detailed Description

NetXen Phantom NICs.

Definition in file phantom.c.

Macro Definition Documentation

◆ PHN_MAX_NUM_PORTS

#define PHN_MAX_NUM_PORTS   8

Maximum number of ports.

Definition at line 53 of file phantom.c.

◆ PHN_CMDPEG_INIT_TIMEOUT_SEC

#define PHN_CMDPEG_INIT_TIMEOUT_SEC   50

Maximum time to wait for command PEG to initialise.

BUGxxxx

The command PEG will currently report initialisation complete only when at least one PHY has detected a link (so that the global PHY clock can be set to 10G/1G as appropriate). This can take a very, very long time.

A future firmware revision should decouple PHY initialisation from firmware initialisation, at which point the command PEG will report initialisation complete much earlier, and this timeout can be reduced.

Definition at line 69 of file phantom.c.

◆ PHN_RCVPEG_INIT_TIMEOUT_SEC

#define PHN_RCVPEG_INIT_TIMEOUT_SEC   2

Maximum time to wait for receive PEG to initialise.

Definition at line 72 of file phantom.c.

◆ PHN_ISSUE_CMD_TIMEOUT_MS

#define PHN_ISSUE_CMD_TIMEOUT_MS   2000

Maximum time to wait for firmware to accept a command.

Definition at line 75 of file phantom.c.

◆ PHN_TEST_MEM_TIMEOUT_MS

#define PHN_TEST_MEM_TIMEOUT_MS   100

Maximum time to wait for test memory.

Definition at line 78 of file phantom.c.

◆ PHN_CLP_CMD_TIMEOUT_MS

#define PHN_CLP_CMD_TIMEOUT_MS   500

Maximum time to wait for CLP command to be issued.

Definition at line 81 of file phantom.c.

◆ PHN_LINK_POLL_FREQUENCY

#define PHN_LINK_POLL_FREQUENCY   4096

Link state poll frequency.

The link state will be checked once in every N calls to poll().

Definition at line 87 of file phantom.c.

◆ PHN_NUM_RDS

#define PHN_NUM_RDS   32

Number of RX descriptors.

Definition at line 90 of file phantom.c.

◆ PHN_RDS_MAX_FILL

#define PHN_RDS_MAX_FILL   16

RX maximum fill level.

Must be strictly less than PHN_NUM_RDS.

Definition at line 93 of file phantom.c.

◆ PHN_RX_BUFSIZE

#define PHN_RX_BUFSIZE
Value:
( 32 /* max LL padding added by card */ + \
ETH_FRAME_LEN )

RX buffer size.

Definition at line 96 of file phantom.c.

◆ PHN_NUM_SDS

#define PHN_NUM_SDS   32

Number of RX status descriptors.

Definition at line 100 of file phantom.c.

◆ PHN_NUM_CDS

#define PHN_NUM_CDS   8

Number of TX descriptors.

Definition at line 103 of file phantom.c.

◆ PHN_CLP_BLKSIZE

#define PHN_CLP_BLKSIZE   ( sizeof ( union phantom_clp_data ) )

Definition at line 1483 of file phantom.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ phantom_crb_access_128m()

static unsigned long phantom_crb_access_128m ( struct phantom_nic phantom,
unsigned long  reg 
)
static

Prepare for access to CRB register via 128MB BAR.

Parameters
phantomPhantom NIC
regRegister offset within abstract address space
Return values
offsetRegister offset within PCI BAR0

Definition at line 241 of file phantom.c.

242  {
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 }
unsigned long crb_window
Current CRB window.
Definition: phantom.c:146
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
void * bar0
BAR 0.
Definition: phantom.c:144
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
static unsigned int unsigned int reg
Definition: intel.h:245
unsigned int uint32_t
Definition: stdint.h:12
#define UNM_128M_CRB_WINDOW
Definition: phantom.h:67

References assert(), phantom_nic::bar0, phantom_nic::crb_window, offset, readl(), reg, UNM_128M_CRB_WINDOW, and writel().

Referenced by phantom_map_crb().

◆ phantom_crb_access_32m()

static unsigned long phantom_crb_access_32m ( struct phantom_nic phantom,
unsigned long  reg 
)
static

Prepare for access to CRB register via 32MB BAR.

Parameters
phantomPhantom NIC
regRegister offset within abstract address space
Return values
offsetRegister offset within PCI BAR0

Definition at line 270 of file phantom.c.

271  {
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 }
unsigned long crb_window
Current CRB window.
Definition: phantom.c:146
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define UNM_32M_CRB_WINDOW
Definition: phantom.h:68
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
void * bar0
BAR 0.
Definition: phantom.c:144
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
static unsigned int unsigned int reg
Definition: intel.h:245
unsigned int uint32_t
Definition: stdint.h:12

References assert(), phantom_nic::bar0, phantom_nic::crb_window, offset, readl(), reg, UNM_32M_CRB_WINDOW, and writel().

Referenced by phantom_map_crb().

◆ phantom_crb_access_2m()

static unsigned long phantom_crb_access_2m ( struct phantom_nic phantom,
unsigned long  reg 
)
static

Prepare for access to CRB register via 2MB BAR.

Parameters
phantomPhantom NIC
regRegister offset within abstract address space
Return values
offsetRegister offset within PCI BAR0

Definition at line 299 of file phantom.c.

300  {
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 }
unsigned long crb_window
Current CRB window.
Definition: phantom.c:146
unsigned short uint16_t
Definition: stdint.h:11
uint16_t block
Definition: tftp.h:12
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define UNM_2M_CRB_WINDOW
Definition: phantom.h:69
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
void * bar0
BAR 0.
Definition: phantom.c:144
#define UNM_CRB_OFFSET(reg)
Definition: phantom.h:92
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
static unsigned int unsigned int reg
Definition: intel.h:245
unsigned char uint8_t
Definition: stdint.h:10
unsigned int uint32_t
Definition: stdint.h:12
#define UNM_CRB_BLK(reg)
Definition: phantom.h:91

References assert(), phantom_nic::bar0, block, phantom_nic::crb_window, offset, readl(), reg, UNM_2M_CRB_WINDOW, UNM_CRB_BLK, UNM_CRB_BLK_CAM, UNM_CRB_BLK_PCIE, UNM_CRB_BLK_PEG_0, UNM_CRB_BLK_PEG_1, UNM_CRB_BLK_PEG_2, UNM_CRB_BLK_PEG_3, UNM_CRB_BLK_PEG_4, UNM_CRB_BLK_ROMUSB, UNM_CRB_BLK_TEST, UNM_CRB_OFFSET, and writel().

Referenced by phantom_map_crb().

◆ phantom_readl()

static uint32_t phantom_readl ( struct phantom_nic phantom,
unsigned long  reg 
)
static

Read from Phantom CRB register.

Parameters
phantomPhantom NIC
regRegister offset within abstract address space
Return values
valueRegister value

Definition at line 358 of file phantom.c.

359  {
360  unsigned long offset;
361 
362  offset = phantom->crb_access ( phantom, reg );
363  return readl ( phantom->bar0 + offset );
364 }
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
void * bar0
BAR 0.
Definition: phantom.c:144
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
static unsigned int unsigned int reg
Definition: intel.h:245
unsigned long(* crb_access)(struct phantom_nic *phantom, unsigned long reg)
CRB window access method.
Definition: phantom.c:148

References phantom_nic::bar0, phantom_nic::crb_access, offset, readl(), and reg.

Referenced by phantom_check_boot_enable(), phantom_clp_cmd(), phantom_clp_wait(), phantom_dmesg(), phantom_get_macaddr(), phantom_init_cmdpeg(), phantom_init_rcvpeg(), phantom_poll(), phantom_poll_link_state(), phantom_read_test_mem_block(), phantom_unhalt_pegs(), and phantom_wait_for_cmd().

◆ phantom_writel()

static void phantom_writel ( struct phantom_nic phantom,
uint32_t  value,
unsigned long  reg 
)
static

Write to Phantom CRB register.

Parameters
phantomPhantom NIC
valueRegister value
regRegister offset within abstract address space

Definition at line 373 of file phantom.c.

374  {
375  unsigned long offset;
376 
377  offset = phantom->crb_access ( phantom, reg );
378  writel ( value, phantom->bar0 + offset );
379 }
void * bar0
BAR 0.
Definition: phantom.c:144
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
static unsigned int unsigned int reg
Definition: intel.h:245
unsigned long(* crb_access)(struct phantom_nic *phantom, unsigned long reg)
CRB window access method.
Definition: phantom.c:148

References phantom_nic::bar0, phantom_nic::crb_access, offset, reg, value, and writel().

Referenced by phantom_clp_cmd(), phantom_init_cmdpeg(), phantom_irq(), phantom_issue_cmd(), phantom_poll(), phantom_post_cds(), phantom_post_rds(), phantom_read_test_mem_block(), phantom_unhalt_pegs(), and phantom_write_hilo().

◆ phantom_write_hilo()

static void phantom_write_hilo ( struct phantom_nic phantom,
uint64_t  value,
unsigned long  lo_offset,
unsigned long  hi_offset 
)
inlinestatic

Write to Phantom CRB HI/LO register pair.

Parameters
phantomPhantom NIC
valueRegister value
lo_offsetLO register offset within CRB
hi_offsetHI register offset within CRB

Definition at line 389 of file phantom.c.

392  {
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 }
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
unsigned int uint32_t
Definition: stdint.h:12
static void phantom_writel(struct phantom_nic *phantom, uint32_t value, unsigned long reg)
Write to Phantom CRB register.
Definition: phantom.c:373

References phantom_writel(), and value.

Referenced by phantom_init_cmdpeg(), and phantom_read_test_mem_block().

◆ phantom_read_test_mem_block()

static int phantom_read_test_mem_block ( struct phantom_nic phantom,
unsigned long  offset,
uint32_t  buf[2] 
)
static

Read from Phantom test memory.

Parameters
phantomPhantom NIC
offsetOffset within test memory
buf8-byte buffer to fill
Return values
rcReturn status code

Definition at line 414 of file phantom.c.

416  {
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 }
#define UNM_TEST_RDDATA_LO
Definition: phantom.h:194
#define UNM_TEST_ADDR_HI
Definition: phantom.h:193
#define UNM_TEST_CONTROL_ENABLE
Definition: phantom.h:190
#define UNM_TEST_CONTROL_START
Definition: phantom.h:189
#define UNM_TEST_ADDR_LO
Definition: phantom.h:192
#define DBGC(...)
Definition: compiler.h:505
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
#define UNM_TEST_CONTROL_BUSY
Definition: phantom.h:191
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
#define UNM_TEST_RDDATA_HI
Definition: phantom.h:195
static uint32_t phantom_readl(struct phantom_nic *phantom, unsigned long reg)
Read from Phantom CRB register.
Definition: phantom.c:358
unsigned int uint32_t
Definition: stdint.h:12
#define PHN_TEST_MEM_TIMEOUT_MS
Maximum time to wait for test memory.
Definition: phantom.c:78
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:78
static void phantom_writel(struct phantom_nic *phantom, uint32_t value, unsigned long reg)
Write to Phantom CRB register.
Definition: phantom.c:373
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:669
#define UNM_TEST_CONTROL
Definition: phantom.h:188

References DBGC, ETIMEDOUT, mdelay(), offset, phantom_readl(), phantom_write_hilo(), phantom_writel(), PHN_TEST_MEM_TIMEOUT_MS, UNM_TEST_ADDR_HI, UNM_TEST_ADDR_LO, UNM_TEST_CONTROL, UNM_TEST_CONTROL_BUSY, UNM_TEST_CONTROL_ENABLE, UNM_TEST_CONTROL_START, UNM_TEST_RDDATA_HI, and UNM_TEST_RDDATA_LO.

Referenced by phantom_read_test_mem().

◆ phantom_read_test_mem()

static int phantom_read_test_mem ( struct phantom_nic phantom,
unsigned long  offset 
)
static

Read single byte from Phantom test memory.

Parameters
phantomPhantom NIC
offsetOffset within test memory
Return values
byteByte read, or negative error

Definition at line 449 of file phantom.c.

450  {
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 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
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 userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
unsigned char uint8_t
Definition: stdint.h:10
unsigned int uint32_t
Definition: stdint.h:12
uint8_t bytes[64]
Definition: ib_mad.h:16

References bytes, offset, phantom_read_test_mem_block(), and rc.

Referenced by phantom_dmesg().

◆ phantom_dmesg()

static int phantom_dmesg ( struct phantom_nic phantom,
unsigned int  log,
unsigned int  max_lines 
)
static

Dump Phantom firmware dmesg log.

Parameters
phantomPhantom NIC
logLog number
max_linesMaximum number of lines to show, or -1 to show all
Return values
rcReturn status code

Definition at line 480 of file phantom.c.

481  {
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 }
#define UNM_CAM_RAM_DMESG_SIG_MAGIC
Definition: phantom.h:130
u8 sig
Definition: CIB_PRM.h:43
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 DBGC(...)
Definition: compiler.h:505
uint8_t head
Head number.
Definition: int13.h:34
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
#define UNM_CAM_RAM_DMESG_TAIL(n)
Definition: phantom.h:128
#define UNM_CAM_RAM_DMESG_SIG(n)
Definition: phantom.h:129
#define UNM_CAM_RAM_DMESG_HEAD(n)
Definition: phantom.h:126
static uint32_t phantom_readl(struct phantom_nic *phantom, unsigned long reg)
Read from Phantom CRB register.
Definition: phantom.c:358
unsigned int uint32_t
Definition: stdint.h:12
unsigned char byte
Definition: smc9000.h:38
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
#define DBG_LOG
Definition: compiler.h:317

References assert(), DBG, DBG_LOG, DBGC, head, offset, phantom_read_test_mem(), phantom_readl(), sig, UNM_CAM_RAM_DMESG_HEAD, UNM_CAM_RAM_DMESG_SIG, UNM_CAM_RAM_DMESG_SIG_MAGIC, and UNM_CAM_RAM_DMESG_TAIL.

Referenced by phantom_dmesg_all().

◆ phantom_dmesg_all()

static void phantom_dmesg_all ( struct phantom_nic phantom,
unsigned int  max_lines 
)
static

Dump Phantom firmware dmesg logs.

Parameters
phantomPhantom NIC
max_linesMaximum number of lines to show, or -1 to show all

Definition at line 530 of file phantom.c.

530  {
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 }
#define UNM_CAM_RAM_NUM_DMESG_BUFFERS
Definition: phantom.h:131
static int phantom_dmesg(struct phantom_nic *phantom, unsigned int log, unsigned int max_lines)
Dump Phantom firmware dmesg log.
Definition: phantom.c:480

References phantom_dmesg(), and UNM_CAM_RAM_NUM_DMESG_BUFFERS.

◆ phantom_wait_for_cmd()

static int phantom_wait_for_cmd ( struct phantom_nic phantom)
static

Wait for firmware to accept command.

Parameters
phantomPhantom NIC
Return values
rcReturn status code

Definition at line 549 of file phantom.c.

549  {
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 }
#define DBGC(...)
Definition: compiler.h:505
#define NX_CDRP_RSP_TIMEOUT
#define NX_CDRP_IS_RSP(rsp)
#define PHN_ISSUE_CMD_TIMEOUT_MS
Maximum time to wait for firmware to accept a command.
Definition: phantom.c:75
#define EPROTO
Protocol error.
Definition: errno.h:624
static uint32_t phantom_readl(struct phantom_nic *phantom, unsigned long reg)
Read from Phantom CRB register.
Definition: phantom.c:358
#define NX_CDRP_FORM_RSP(rsp)
unsigned int uint32_t
Definition: stdint.h:12
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:78
#define NX_CDRP_RSP_FAIL
#define UNM_NIC_REG_NX_CDRP
Definition: phantom.h:148
#define EIO
Input/output error.
Definition: errno.h:433
#define NX_CDRP_RSP_OK
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:669

References DBGC, EIO, EPROTO, ETIMEDOUT, mdelay(), NX_CDRP_FORM_RSP, NX_CDRP_IS_RSP, NX_CDRP_RSP_FAIL, NX_CDRP_RSP_OK, NX_CDRP_RSP_TIMEOUT, phantom_readl(), PHN_ISSUE_CMD_TIMEOUT_MS, and UNM_NIC_REG_NX_CDRP.

Referenced by phantom_issue_cmd().

◆ phantom_issue_cmd()

static int phantom_issue_cmd ( struct phantom_nic phantom,
uint32_t  command,
uint32_t  arg1,
uint32_t  arg2,
uint32_t  arg3 
)
static

Issue command to firmware.

Parameters
phantomPhantom NIC
commandFirmware command
arg1Argument 1
arg2Argument 2
arg3Argument 3
Return values
rcReturn status code

Definition at line 585 of file phantom.c.

587  {
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 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
A command-line command.
Definition: command.h:9
#define DBGC(...)
Definition: compiler.h:505
#define UNM_NIC_REG_NX_ARG3
Definition: phantom.h:151
static unsigned int unsigned long arg1
Definition: xen.h:43
u8 signature
Definition: CIB_PRM.h:35
#define NX_CDRP_SIGNATURE_MAKE(pcifn, version)
#define NX_CDRP_FORM_CMD(cmd)
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
unsigned int uint32_t
Definition: stdint.h:12
#define UNM_NIC_REG_NX_SIGN
Definition: phantom.h:152
#define DBGC2(...)
Definition: compiler.h:522
#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
#define UNM_NIC_REG_NX_ARG1
Definition: phantom.h:149
static unsigned int unsigned long unsigned long arg2
Definition: xen.h:66
static unsigned int unsigned long unsigned long unsigned long arg3
Definition: xen.h:90
#define NXHAL_VERSION
Definition: phantom.h:52
#define UNM_NIC_REG_NX_ARG2
Definition: phantom.h:150
unsigned int port
Port number.
Definition: phantom.c:153

References arg1, arg2, arg3, DBGC, DBGC2, NX_CDRP_FORM_CMD, NX_CDRP_SIGNATURE_MAKE, NXHAL_VERSION, phantom_wait_for_cmd(), phantom_writel(), phantom_nic::port, rc, signature, strerror(), UNM_NIC_REG_NX_ARG1, UNM_NIC_REG_NX_ARG2, UNM_NIC_REG_NX_ARG3, UNM_NIC_REG_NX_CDRP, and UNM_NIC_REG_NX_SIGN.

Referenced by phantom_destroy_rx_ctx(), phantom_destroy_tx_ctx(), and phantom_issue_buf_cmd().

◆ phantom_issue_buf_cmd()

static int phantom_issue_buf_cmd ( struct phantom_nic phantom,
uint32_t  command,
void *  buffer,
size_t  len 
)
static

Issue buffer-format command to firmware.

Parameters
phantomPhantom NIC
commandFirmware command
bufferBuffer to pass to firmware
lenLength of buffer
Return values
rcReturn status code

Definition at line 622 of file phantom.c.

624  {
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 }
A command-line command.
Definition: command.h:9
unsigned long long uint64_t
Definition: stdint.h:13
uint32_t buffer
Buffer index (or NETVSC_RNDIS_NO_BUFFER)
Definition: netvsc.h:16
static __always_inline unsigned long virt_to_bus(volatile const void *addr)
Convert virtual address to a bus address.
Definition: io.h:183
uint32_t len
Length.
Definition: ena.h:14
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

References buffer, len, phantom_issue_cmd(), and virt_to_bus().

Referenced by phantom_create_rx_ctx(), and phantom_create_tx_ctx().

◆ phantom_create_rx_ctx()

static int phantom_create_rx_ctx ( struct phantom_nic phantom)
static

Create Phantom RX context.

Parameters
phantomPhantom NIC
Return values
rcReturn status code

Definition at line 638 of file phantom.c.

638  {
639  struct phantom_create_rx_ctx_rqrsp *buf;
640  int rc;
641 
642  /* Allocate context creation buffer */
643  buf = malloc_dma ( 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_dma ( buf, sizeof ( *buf ) );
720  return rc;
721 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct phantom_rds rds[PHN_NUM_RDS]
RX descriptors.
Definition: phantom.c:108
#define PHN_RX_BUFSIZE
RX buffer size.
Definition: phantom.c:96
struct nx_hostrq_rds_ring_s rds
Definition: phantom.c:121
#define le32_to_cpu(value)
Definition: byteswap.h:113
#define PHN_NUM_SDS
Number of RX status descriptors.
Definition: phantom.c:100
#define DBGC(...)
Definition: compiler.h:505
#define cpu_to_le64(value)
Definition: byteswap.h:108
#define PHN_NUM_RDS
Number of RX descriptors.
Definition: phantom.c:90
#define NX_CDRP_CMD_CREATE_RX_CTX
struct phantom_create_rx_ctx_rqrsp::@85 hostrq
struct phantom_descriptor_rings * desc
Descriptor rings.
Definition: phantom.c:191
#define ENOMEM
Not enough space.
Definition: errno.h:534
static __always_inline unsigned long virt_to_bus(volatile const void *addr)
Convert virtual address to a bus address.
Definition: io.h:183
struct phantom_sds sds[PHN_NUM_SDS]
RX status descriptors.
Definition: phantom.c:110
#define UNM_DMA_BUFFER_ALIGN
DMA buffer alignment.
Definition: phantom.h:56
#define NX_CAP0_LEGACY_CONTEXT
#define DBGC_HDA(...)
Definition: compiler.h:506
#define UNM_CAM_RAM
Definition: phantom.h:122
__be32 out[4]
Definition: CIB_PRM.h:36
struct nx_hostrq_sds_ring_s sds
Definition: phantom.c:122
#define cpu_to_le32(value)
Definition: byteswap.h:107
#define DBGC2_HDA(...)
Definition: compiler.h:523
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
RX context creation request and response buffers.
Definition: phantom.c:118
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 le16_to_cpu(value)
Definition: byteswap.h:112
struct nx_hostrq_rx_ctx_s rx_ctx
Definition: phantom.c:120
#define NX_CAP0_LEGACY_MN
unsigned long sds_consumer_crb
RX status descriptor consumer CRB offset.
Definition: phantom.c:161
#define NX_RDS_RING_TYPE_NORMAL
uint16_t rx_context_id
RX context ID.
Definition: phantom.c:157
struct phantom_create_rx_ctx_rqrsp::@86 cardrsp
static void *__malloc malloc_dma(size_t size, size_t phys_align)
Allocate memory for DMA.
Definition: malloc.h:66
#define cpu_to_le16(value)
Definition: byteswap.h:106
unsigned long rds_producer_crb
RX descriptor producer CRB offset.
Definition: phantom.c:159
unsigned long sds_irq_mask_crb
RX interrupt mask CRB offset.
Definition: phantom.c:163
#define NX_HOST_INT_CRB_MODE_SHARED
static void free_dma(void *ptr, size_t size)
Free memory allocated with malloc_dma()
Definition: malloc.h:81
#define NX_HOST_RDS_CRB_MODE_UNIQUE
void * memset(void *dest, int character, size_t len) __nonnull

References nx_hostrq_rds_ring_s::buff_size, nx_hostrq_rx_ctx_s::capabilities, phantom_create_rx_ctx_rqrsp::cardrsp, cpu_to_le16, cpu_to_le32, cpu_to_le64, DBGC, DBGC2_HDA, DBGC_HDA, phantom_nic::desc, ENOMEM, free_dma(), nx_hostrq_rx_ctx_s::host_int_crb_mode, nx_hostrq_sds_ring_s::host_phys_addr, nx_hostrq_rds_ring_s::host_phys_addr, nx_hostrq_rx_ctx_s::host_rds_crb_mode, nx_hostrq_rx_ctx_s::host_rsp_dma_addr, phantom_create_rx_ctx_rqrsp::hostrq, le16_to_cpu, le32_to_cpu, malloc_dma(), memset(), nx_hostrq_rx_ctx_s::num_rds_rings, nx_hostrq_rx_ctx_s::num_sds_rings, NX_CAP0_LEGACY_CONTEXT, NX_CAP0_LEGACY_MN, NX_CDRP_CMD_CREATE_RX_CTX, NX_HOST_INT_CRB_MODE_SHARED, NX_HOST_RDS_CRB_MODE_UNIQUE, NX_RDS_RING_TYPE_NORMAL, out, phantom_issue_buf_cmd(), PHN_NUM_RDS, PHN_NUM_SDS, PHN_RX_BUFSIZE, rc, phantom_create_rx_ctx_rqrsp::rds, phantom_descriptor_rings::rds, phantom_nic::rds_producer_crb, nx_hostrq_rx_ctx_s::rds_ring_offset, nx_hostrq_rds_ring_s::ring_kind, nx_hostrq_sds_ring_s::ring_size, nx_hostrq_rds_ring_s::ring_size, phantom_nic::rx_context_id, phantom_create_rx_ctx_rqrsp::rx_ctx, phantom_create_rx_ctx_rqrsp::sds, phantom_descriptor_rings::sds, phantom_nic::sds_consumer_crb, phantom_nic::sds_irq_mask_crb, nx_hostrq_rx_ctx_s::sds_ring_offset, strerror(), UNM_CAM_RAM, UNM_DMA_BUFFER_ALIGN, and virt_to_bus().

Referenced by phantom_open().

◆ phantom_destroy_rx_ctx()

static void phantom_destroy_rx_ctx ( struct phantom_nic phantom)
static

Destroy Phantom RX context.

Parameters
phantomPhantom NIC
Return values
rcReturn status code

Definition at line 729 of file phantom.c.

729  {
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 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DBGC(...)
Definition: compiler.h:505
unsigned int rds_producer_idx
RX producer index.
Definition: phantom.c:168
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
unsigned long sds_consumer_crb
RX status descriptor consumer CRB offset.
Definition: phantom.c:161
unsigned int rds_consumer_idx
RX consumer index.
Definition: phantom.c:170
uint16_t rx_context_id
RX context ID.
Definition: phantom.c:157
#define NX_DESTROY_CTX_RESET
unsigned long rds_producer_crb
RX descriptor producer CRB offset.
Definition: phantom.c:159
unsigned int sds_consumer_idx
RX status consumer index.
Definition: phantom.c:172
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
#define NX_CDRP_CMD_DESTROY_RX_CTX

References DBGC, NX_CDRP_CMD_DESTROY_RX_CTX, NX_DESTROY_CTX_RESET, phantom_issue_cmd(), rc, phantom_nic::rds_consumer_idx, phantom_nic::rds_producer_crb, phantom_nic::rds_producer_idx, phantom_nic::rx_context_id, phantom_nic::sds_consumer_crb, phantom_nic::sds_consumer_idx, and strerror().

Referenced by phantom_close(), and phantom_open().

◆ phantom_create_tx_ctx()

static int phantom_create_tx_ctx ( struct phantom_nic phantom)
static

Create Phantom TX context.

Parameters
phantomPhantom NIC
Return values
rcReturn status code

Definition at line 763 of file phantom.c.

763  {
764  struct phantom_create_tx_ctx_rqrsp *buf;
765  int rc;
766 
767  /* Allocate context creation buffer */
768  buf = malloc_dma ( 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_dma ( buf, sizeof ( *buf ) );
825  return rc;
826 }
unsigned long cds_producer_crb
TX descriptor producer CRB offset.
Definition: phantom.c:180
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define le32_to_cpu(value)
Definition: byteswap.h:113
uint16_t tx_context_id
TX context ID.
Definition: phantom.c:178
TX context creation request and response buffers.
Definition: phantom.c:132
struct nx_hostrq_tx_ctx_s tx_ctx
Definition: phantom.c:134
#define DBGC(...)
Definition: compiler.h:505
#define cpu_to_le64(value)
Definition: byteswap.h:108
struct phantom_descriptor_rings * desc
Descriptor rings.
Definition: phantom.c:191
#define ENOMEM
Not enough space.
Definition: errno.h:534
volatile uint32_t cmd_cons
TX consumer index.
Definition: phantom.c:114
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_DMA_BUFFER_ALIGN
DMA buffer alignment.
Definition: phantom.h:56
#define NX_CAP0_LEGACY_CONTEXT
#define DBGC_HDA(...)
Definition: compiler.h:506
#define UNM_CAM_RAM
Definition: phantom.h:122
__be32 out[4]
Definition: CIB_PRM.h:36
#define cpu_to_le32(value)
Definition: byteswap.h:107
#define DBGC2_HDA(...)
Definition: compiler.h:523
union phantom_cds cds[PHN_NUM_CDS]
TX descriptors.
Definition: phantom.c:112
nx_hostrq_cds_ring_t cds_ring
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
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 le16_to_cpu(value)
Definition: byteswap.h:112
struct phantom_create_tx_ctx_rqrsp::@88 cardrsp
#define NX_CAP0_LEGACY_MN
#define NX_CDRP_CMD_CREATE_TX_CTX
#define PHN_NUM_CDS
Number of TX descriptors.
Definition: phantom.c:103
static void *__malloc malloc_dma(size_t size, size_t phys_align)
Allocate memory for DMA.
Definition: malloc.h:66
#define NX_HOST_INT_CRB_MODE_SHARED
static void free_dma(void *ptr, size_t size)
Free memory allocated with malloc_dma()
Definition: malloc.h:81
struct phantom_create_tx_ctx_rqrsp::@87 hostrq
void * memset(void *dest, int character, size_t len) __nonnull

References nx_hostrq_tx_ctx_s::capabilities, phantom_create_tx_ctx_rqrsp::cardrsp, phantom_descriptor_rings::cds, phantom_nic::cds_producer_crb, nx_hostrq_tx_ctx_s::cds_ring, phantom_descriptor_rings::cmd_cons, nx_hostrq_tx_ctx_s::cmd_cons_dma_addr, cpu_to_le32, cpu_to_le64, DBGC, DBGC2_HDA, DBGC_HDA, phantom_nic::desc, ENOMEM, free_dma(), nx_hostrq_tx_ctx_s::host_int_crb_mode, nx_hostrq_cds_ring_s::host_phys_addr, nx_hostrq_tx_ctx_s::host_rsp_dma_addr, phantom_create_tx_ctx_rqrsp::hostrq, le16_to_cpu, le32_to_cpu, malloc_dma(), memset(), NX_CAP0_LEGACY_CONTEXT, NX_CAP0_LEGACY_MN, NX_CDRP_CMD_CREATE_TX_CTX, NX_HOST_INT_CRB_MODE_SHARED, out, phantom_issue_buf_cmd(), PHN_NUM_CDS, rc, nx_hostrq_cds_ring_s::ring_size, strerror(), phantom_nic::tx_context_id, phantom_create_tx_ctx_rqrsp::tx_ctx, UNM_CAM_RAM, UNM_DMA_BUFFER_ALIGN, and virt_to_bus().

Referenced by phantom_open().

◆ phantom_destroy_tx_ctx()

static void phantom_destroy_tx_ctx ( struct phantom_nic phantom)
static

Destroy Phantom TX context.

Parameters
phantomPhantom NIC
Return values
rcReturn status code

Definition at line 834 of file phantom.c.

834  {
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 }
unsigned long cds_producer_crb
TX descriptor producer CRB offset.
Definition: phantom.c:180
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint16_t tx_context_id
TX context ID.
Definition: phantom.c:178
#define DBGC(...)
Definition: compiler.h:505
#define NX_CDRP_CMD_DESTROY_TX_CTX
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define NX_DESTROY_CTX_RESET
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
unsigned int cds_consumer_idx
TX consumer index.
Definition: phantom.c:185
unsigned int cds_producer_idx
TX producer index.
Definition: phantom.c:183

References phantom_nic::cds_consumer_idx, phantom_nic::cds_producer_crb, phantom_nic::cds_producer_idx, DBGC, NX_CDRP_CMD_DESTROY_TX_CTX, NX_DESTROY_CTX_RESET, phantom_issue_cmd(), rc, strerror(), and phantom_nic::tx_context_id.

Referenced by phantom_close(), and phantom_open().

◆ phantom_alloc_rds()

static int phantom_alloc_rds ( struct phantom_nic phantom)
static

Allocate Phantom RX descriptor.

Parameters
phantomPhantom NIC
Return values
indexRX descriptor index, or negative error

Definition at line 872 of file phantom.c.

872  {
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 }
#define DBGC(...)
Definition: compiler.h:505
#define PHN_NUM_RDS
Number of RX descriptors.
Definition: phantom.c:90
unsigned int rds_producer_idx
RX producer index.
Definition: phantom.c:168
unsigned int rds_consumer_idx
RX consumer index.
Definition: phantom.c:170
#define ENOBUFS
No buffer space available.
Definition: errno.h:498

References DBGC, ENOBUFS, PHN_NUM_RDS, phantom_nic::rds_consumer_idx, and phantom_nic::rds_producer_idx.

Referenced by phantom_refill_rx_ring().

◆ phantom_post_rds()

static void phantom_post_rds ( struct phantom_nic phantom,
struct phantom_rds rds 
)
static

Post Phantom RX descriptor.

Parameters
phantomPhantom NIC
rdsRX descriptor

Definition at line 899 of file phantom.c.

900  {
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 }
wmb()
struct phantom_rds rds[PHN_NUM_RDS]
RX descriptors.
Definition: phantom.c:108
#define PHN_NUM_RDS
Number of RX descriptors.
Definition: phantom.c:90
struct phantom_descriptor_rings * desc
Descriptor rings.
Definition: phantom.c:191
void * memcpy(void *dest, const void *src, size_t len) __nonnull
static __always_inline unsigned long virt_to_bus(volatile const void *addr)
Convert virtual address to a bus address.
Definition: io.h:183
unsigned int rds_producer_idx
RX producer index.
Definition: phantom.c:168
#define DBGC2_HDA(...)
Definition: compiler.h:523
union aes_table_entry entry[256]
Table entries, indexed by S(N)
Definition: aes.c:26
#define DBGC2(...)
Definition: compiler.h:522
static void phantom_writel(struct phantom_nic *phantom, uint32_t value, unsigned long reg)
Write to Phantom CRB register.
Definition: phantom.c:373
unsigned long rds_producer_crb
RX descriptor producer CRB offset.
Definition: phantom.c:159
uint16_t handle
Handle.
Definition: smbios.h:16
#define NX_GET(_ptr, _field)
Extract value of named field (for fields up to the size of a long)
Definition: nx_bitops.h:196

References DBGC2, DBGC2_HDA, phantom_nic::desc, entry, handle, memcpy(), NX_GET, phantom_writel(), PHN_NUM_RDS, phantom_descriptor_rings::rds, phantom_nic::rds_producer_crb, phantom_nic::rds_producer_idx, virt_to_bus(), and wmb().

Referenced by phantom_refill_rx_ring().

◆ phantom_alloc_cds()

static int phantom_alloc_cds ( struct phantom_nic phantom)
static

Allocate Phantom TX descriptor.

Parameters
phantomPhantom NIC
Return values
indexTX descriptor index, or negative error

Definition at line 927 of file phantom.c.

927  {
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 }
#define DBGC(...)
Definition: compiler.h:505
#define ENOBUFS
No buffer space available.
Definition: errno.h:498
#define PHN_NUM_CDS
Number of TX descriptors.
Definition: phantom.c:103
unsigned int cds_consumer_idx
TX consumer index.
Definition: phantom.c:185
unsigned int cds_producer_idx
TX producer index.
Definition: phantom.c:183

References phantom_nic::cds_consumer_idx, phantom_nic::cds_producer_idx, DBGC, ENOBUFS, and PHN_NUM_CDS.

Referenced by phantom_transmit(), and phantom_update_macaddr().

◆ phantom_post_cds()

static void phantom_post_cds ( struct phantom_nic phantom,
union phantom_cds cds 
)
static

Post Phantom TX descriptor.

Parameters
phantomPhantom NIC
cdsTX descriptor

Definition at line 952 of file phantom.c.

953  {
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 }
unsigned long cds_producer_crb
TX descriptor producer CRB offset.
Definition: phantom.c:180
wmb()
struct phantom_descriptor_rings * desc
Descriptor rings.
Definition: phantom.c:191
void * memcpy(void *dest, const void *src, size_t len) __nonnull
static __always_inline unsigned long virt_to_bus(volatile const void *addr)
Convert virtual address to a bus address.
Definition: io.h:183
#define DBGC2_HDA(...)
Definition: compiler.h:523
union phantom_cds cds[PHN_NUM_CDS]
TX descriptors.
Definition: phantom.c:112
union aes_table_entry entry[256]
Table entries, indexed by S(N)
Definition: aes.c:26
#define DBGC2(...)
Definition: compiler.h:522
static void phantom_writel(struct phantom_nic *phantom, uint32_t value, unsigned long reg)
Write to Phantom CRB register.
Definition: phantom.c:373
#define PHN_NUM_CDS
Number of TX descriptors.
Definition: phantom.c:103
unsigned int cds_producer_idx
TX producer index.
Definition: phantom.c:183

References phantom_descriptor_rings::cds, phantom_nic::cds_producer_crb, phantom_nic::cds_producer_idx, DBGC2, DBGC2_HDA, phantom_nic::desc, entry, memcpy(), phantom_writel(), PHN_NUM_CDS, virt_to_bus(), and wmb().

Referenced by phantom_transmit(), and phantom_update_macaddr().

◆ phantom_update_macaddr()

static int phantom_update_macaddr ( struct phantom_nic phantom,
const uint8_t ll_addr,
unsigned int  opcode 
)
static

Add/remove MAC address.

Parameters
phantomPhantom NIC
ll_addrMAC address to add or remove
opcodeMAC request opcode
Return values
rcReturn status code

Definition at line 988 of file phantom.c.

990  {
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 }
static int phantom_alloc_cds(struct phantom_nic *phantom)
Allocate Phantom TX descriptor.
Definition: phantom.c:927
static void phantom_post_cds(struct phantom_nic *phantom, union phantom_cds *cds)
Post Phantom TX descriptor.
Definition: phantom.c:952
uint8_t opcode
Opcode.
Definition: ena.h:16
#define NX_FILL_1(_ptr, _index,...)
Definition: nx_bitops.h:162
#define NX_FILL_7(_ptr, _index,...)
Definition: nx_bitops.h:180
NIC request.
Definition: phantom_hw.h:186
Add/delete MAC address.
Definition: phantom_hw.h:174
#define NX_FILL_2(_ptr, _index,...)
Definition: nx_bitops.h:165
uint64_t index
Index of the first segment within the content.
Definition: pccrc.h:21
unsigned int port
Port number.
Definition: phantom.c:153
void * memset(void *dest, int character, size_t len) __nonnull

References index, memset(), NX_FILL_1, NX_FILL_2, NX_FILL_7, opcode, phantom_alloc_cds(), phantom_post_cds(), phantom_nic::port, UNM_MAC_EVENT, and UNM_NIC_REQUEST.

Referenced by phantom_add_macaddr(), and phantom_del_macaddr().

◆ phantom_add_macaddr()

static int phantom_add_macaddr ( struct phantom_nic phantom,
const uint8_t ll_addr 
)
inlinestatic

Add MAC address.

Parameters
phantomPhantom NIC
ll_addrMAC address to add or remove
Return values
rcReturn status code

Definition at line 1028 of file phantom.c.

1029  {
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 }
#define DBGC(...)
Definition: compiler.h:505
const char * eth_ntoa(const void *ll_addr)
Transcribe Ethernet address.
Definition: ethernet.c:175
Add MAC address.
Definition: phantom_hw.h:136
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

References DBGC, eth_ntoa(), phantom_update_macaddr(), and UNM_MAC_ADD.

Referenced by phantom_open().

◆ phantom_del_macaddr()

static int phantom_del_macaddr ( struct phantom_nic phantom,
const uint8_t ll_addr 
)
inlinestatic

Remove MAC address.

Parameters
phantomPhantom NIC
ll_addrMAC address to add or remove
Return values
rcReturn status code

Definition at line 1044 of file phantom.c.

1045  {
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 }
#define DBGC(...)
Definition: compiler.h:505
const char * eth_ntoa(const void *ll_addr)
Transcribe Ethernet address.
Definition: ethernet.c:175
Delete MAC address.
Definition: phantom_hw.h:137
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

References DBGC, eth_ntoa(), phantom_update_macaddr(), and UNM_MAC_DEL.

Referenced by phantom_close(), and phantom_open().

◆ phantom_poll_link_state()

static void phantom_poll_link_state ( struct net_device netdev)
static

Poll link state.

Parameters
netdevNetwork device

Definition at line 1064 of file phantom.c.

1064  {
1065  struct phantom_nic *phantom = netdev_priv ( netdev );
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 }
static void * netdev_priv(struct net_device *netdev)
Get driver private area for this network device.
Definition: netdevice.h:566
#define UNM_NIC_REG_XG_STATE_P3
Definition: phantom.h:160
#define DBGC(...)
Definition: compiler.h:505
void netdev_link_down(struct net_device *netdev)
Mark network device as having link down.
Definition: netdevice.c:186
static void netdev_link_up(struct net_device *netdev)
Mark network device as having link up.
Definition: netdevice.h:768
static struct net_device * netdev
Definition: gdbudp.c:52
u32 link
Link to next descriptor.
Definition: ar9003_mac.h:68
uint32_t link_state
Last known link state.
Definition: phantom.c:195
#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
unsigned int uint32_t
Definition: stdint.h:12
#define UNM_NIC_REG_XG_STATE_P3_LINK(port, state_p3)
Definition: phantom.h:161
A Phantom NIC.
Definition: phantom.c:142
#define UNM_NIC_REG_XG_STATE_P3_LINK_UP
Definition: phantom.h:163
unsigned int port
Port number.
Definition: phantom.c:153

References DBGC, link, phantom_nic::link_state, netdev, netdev_link_down(), netdev_link_up(), netdev_priv(), phantom_readl(), phantom_nic::port, UNM_NIC_REG_XG_STATE_P3, UNM_NIC_REG_XG_STATE_P3_LINK, UNM_NIC_REG_XG_STATE_P3_LINK_DOWN, and UNM_NIC_REG_XG_STATE_P3_LINK_UP.

Referenced by phantom_poll().

◆ phantom_refill_rx_ring()

static void phantom_refill_rx_ring ( struct net_device netdev)
static

Refill descriptor ring.

Parameters
netdevNet device

Definition at line 1111 of file phantom.c.

1111  {
1112  struct phantom_nic *phantom = netdev_priv ( netdev );
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 }
uint16_t length
Length.
Definition: intel.h:14
static void * netdev_priv(struct net_device *netdev)
Get driver private area for this network device.
Definition: netdevice.h:566
#define PHN_RX_BUFSIZE
RX buffer size.
Definition: phantom.c:96
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition: netdevice.c:501
#define NX_FILL_1(_ptr, _index,...)
Definition: nx_bitops.h:162
#define PHN_NUM_RDS
Number of RX descriptors.
Definition: phantom.c:90
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:128
#define ENOMEM
Not enough space.
Definition: errno.h:534
#define PHN_RDS_MAX_FILL
RX maximum fill level.
Definition: phantom.c:93
static __always_inline unsigned long virt_to_bus(volatile const void *addr)
Convert virtual address to a bus address.
Definition: io.h:183
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static void phantom_post_rds(struct phantom_nic *phantom, struct phantom_rds *rds)
Post Phantom RX descriptor.
Definition: phantom.c:899
static struct net_device * netdev
Definition: gdbudp.c:52
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:151
void * data
Start of data.
Definition: iobuf.h:44
A Phantom NIC.
Definition: phantom.c:142
#define NX_FILL_2(_ptr, _index,...)
Definition: nx_bitops.h:165
uint64_t index
Index of the first segment within the content.
Definition: pccrc.h:21
uint16_t handle
Handle.
Definition: smbios.h:16
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
struct io_buffer * rds_iobuf[PHN_RDS_MAX_FILL]
RX I/O buffers.
Definition: phantom.c:174
void * memset(void *dest, int character, size_t len) __nonnull
A persistent I/O buffer.
Definition: iobuf.h:32
static int phantom_alloc_rds(struct phantom_nic *phantom)
Allocate Phantom RX descriptor.
Definition: phantom.c:872

References alloc_iob(), assert(), io_buffer::data, ENOMEM, handle, index, iob_len(), length, memset(), netdev, netdev_priv(), netdev_rx_err(), NULL, NX_FILL_1, NX_FILL_2, phantom_alloc_rds(), phantom_post_rds(), PHN_NUM_RDS, PHN_RDS_MAX_FILL, PHN_RX_BUFSIZE, phantom_nic::rds_iobuf, and virt_to_bus().

Referenced by phantom_open(), and phantom_poll().

◆ phantom_open()

static int phantom_open ( struct net_device netdev)
static

Open NIC.

Parameters
netdevNet device
Return values
rcReturn status code

Definition at line 1162 of file phantom.c.

1162  {
1163  struct phantom_nic *phantom = netdev_priv ( netdev );
1164  int rc;
1165 
1166  /* Allocate and zero descriptor rings */
1167  phantom->desc = malloc_dma ( 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_dma ( phantom->desc, sizeof ( *(phantom->desc) ) );
1212  phantom->desc = NULL;
1213  err_alloc_desc:
1214  return rc;
1215 }
static void * netdev_priv(struct net_device *netdev)
Get driver private area for this network device.
Definition: netdevice.h:566
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const uint8_t * ll_broadcast
Link-layer broadcast address.
Definition: netdevice.h:383
static int phantom_add_macaddr(struct phantom_nic *phantom, const uint8_t *ll_addr)
Add MAC address.
Definition: phantom.c:1028
struct phantom_descriptor_rings * desc
Descriptor rings.
Definition: phantom.c:191
#define ENOMEM
Not enough space.
Definition: errno.h:534
#define UNM_DMA_BUFFER_ALIGN
DMA buffer alignment.
Definition: phantom.h:56
static struct net_device * netdev
Definition: gdbudp.c:52
static void phantom_destroy_rx_ctx(struct phantom_nic *phantom)
Destroy Phantom RX context.
Definition: phantom.c:729
static int phantom_create_rx_ctx(struct phantom_nic *phantom)
Create Phantom RX context.
Definition: phantom.c:638
static void phantom_destroy_tx_ctx(struct phantom_nic *phantom)
Destroy Phantom TX context.
Definition: phantom.c:834
static void phantom_refill_rx_ring(struct net_device *netdev)
Refill descriptor ring.
Definition: phantom.c:1111
static int phantom_create_tx_ctx(struct phantom_nic *phantom)
Create Phantom TX context.
Definition: phantom.c:763
static void *__malloc malloc_dma(size_t size, size_t phys_align)
Allocate memory for DMA.
Definition: malloc.h:66
static int phantom_del_macaddr(struct phantom_nic *phantom, const uint8_t *ll_addr)
Remove MAC address.
Definition: phantom.c:1044
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:381
A Phantom NIC.
Definition: phantom.c:142
static void free_dma(void *ptr, size_t size)
Free memory allocated with malloc_dma()
Definition: malloc.h:81
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
void * memset(void *dest, int character, size_t len) __nonnull

References phantom_nic::desc, ENOMEM, free_dma(), net_device::ll_addr, net_device::ll_broadcast, malloc_dma(), memset(), netdev, netdev_priv(), NULL, phantom_add_macaddr(), phantom_create_rx_ctx(), phantom_create_tx_ctx(), phantom_del_macaddr(), phantom_destroy_rx_ctx(), phantom_destroy_tx_ctx(), phantom_refill_rx_ring(), rc, and UNM_DMA_BUFFER_ALIGN.

◆ phantom_close()

static void phantom_close ( struct net_device netdev)
static

Close NIC.

Parameters
netdevNet device

Definition at line 1222 of file phantom.c.

1222  {
1223  struct phantom_nic *phantom = netdev_priv ( netdev );
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_dma ( 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 }
static void * netdev_priv(struct net_device *netdev)
Get driver private area for this network device.
Definition: netdevice.h:566
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:145
const uint8_t * ll_broadcast
Link-layer broadcast address.
Definition: netdevice.h:383
#define ECANCELED
Operation canceled.
Definition: errno.h:343
struct phantom_descriptor_rings * desc
Descriptor rings.
Definition: phantom.c:191
#define PHN_RDS_MAX_FILL
RX maximum fill level.
Definition: phantom.c:93
static struct net_device * netdev
Definition: gdbudp.c:52
static void phantom_destroy_rx_ctx(struct phantom_nic *phantom)
Destroy Phantom RX context.
Definition: phantom.c:729
static void phantom_destroy_tx_ctx(struct phantom_nic *phantom)
Destroy Phantom TX context.
Definition: phantom.c:834
struct io_buffer * cds_iobuf[PHN_NUM_CDS]
TX I/O buffers.
Definition: phantom.c:187
void netdev_tx_complete_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Complete network transmission.
Definition: netdevice.c:395
#define PHN_NUM_CDS
Number of TX descriptors.
Definition: phantom.c:103
static int phantom_del_macaddr(struct phantom_nic *phantom, const uint8_t *ll_addr)
Remove MAC address.
Definition: phantom.c:1044
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:381
A Phantom NIC.
Definition: phantom.c:142
static void free_dma(void *ptr, size_t size)
Free memory allocated with malloc_dma()
Definition: malloc.h:81
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
struct io_buffer * rds_iobuf[PHN_RDS_MAX_FILL]
RX I/O buffers.
Definition: phantom.c:174
A persistent I/O buffer.
Definition: iobuf.h:32

References phantom_nic::cds_iobuf, phantom_nic::desc, ECANCELED, free_dma(), free_iob(), net_device::ll_addr, net_device::ll_broadcast, netdev, netdev_priv(), netdev_tx_complete_err(), NULL, phantom_del_macaddr(), phantom_destroy_rx_ctx(), phantom_destroy_tx_ctx(), PHN_NUM_CDS, PHN_RDS_MAX_FILL, and phantom_nic::rds_iobuf.

◆ phantom_transmit()

static int phantom_transmit ( struct net_device netdev,
struct io_buffer iobuf 
)
static

Transmit packet.

Parameters
netdevNetwork device
iobufI/O buffer
Return values
rcReturn status code

Definition at line 1259 of file phantom.c.

1260  {
1261  struct phantom_nic *phantom = netdev_priv ( netdev );
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 }
static void * netdev_priv(struct net_device *netdev)
Get driver private area for this network device.
Definition: netdevice.h:566
Transmit raw Ethernet.
Definition: phantom_hw.h:185
static int phantom_alloc_cds(struct phantom_nic *phantom)
Allocate Phantom TX descriptor.
Definition: phantom.c:927
static void phantom_post_cds(struct phantom_nic *phantom, union phantom_cds *cds)
Post Phantom TX descriptor.
Definition: phantom.c:952
#define NX_FILL_1(_ptr, _index,...)
Definition: nx_bitops.h:162
static __always_inline unsigned long virt_to_bus(volatile const void *addr)
Convert virtual address to a bus address.
Definition: io.h:183
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static struct net_device * netdev
Definition: gdbudp.c:52
uint32_t tx
Maximum number of transmit queues.
Definition: intelvf.h:14
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:151
struct io_buffer * cds_iobuf[PHN_NUM_CDS]
TX I/O buffers.
Definition: phantom.c:187
void * data
Start of data.
Definition: iobuf.h:44
#define NX_FILL_3(_ptr, _index,...)
Definition: nx_bitops.h:168
A Phantom NIC.
Definition: phantom.c:142
#define NX_FILL_2(_ptr, _index,...)
Definition: nx_bitops.h:165
uint64_t index
Index of the first segment within the content.
Definition: pccrc.h:21
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
unsigned int port
Port number.
Definition: phantom.c:153
void * memset(void *dest, int character, size_t len) __nonnull

References assert(), phantom_nic::cds_iobuf, io_buffer::data, index, iob_len(), memset(), netdev, netdev_priv(), NULL, NX_FILL_1, NX_FILL_2, NX_FILL_3, phantom_alloc_cds(), phantom_post_cds(), phantom_nic::port, tx, UNM_TX_ETHER_PKT, and virt_to_bus().

◆ phantom_poll()

static void phantom_poll ( struct net_device netdev)
static

Poll for received packets.

Parameters
netdevNetwork device

Definition at line 1299 of file phantom.c.

1299  {
1300  struct phantom_nic *phantom = netdev_priv ( netdev );
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 }
#define iob_pull(iobuf, len)
Definition: iobuf.h:98
#define UNM_PCIE_IRQ_STATUS_MAGIC
Definition: phantom.h:118
static void * netdev_priv(struct net_device *netdev)
Get driver private area for this network device.
Definition: netdevice.h:566
unsigned int sds_irq_enabled
RX interrupts enabled.
Definition: phantom.c:165
static void netdev_tx_complete(struct net_device *netdev, struct io_buffer *iobuf)
Complete network transmission.
Definition: netdevice.h:746
wmb()
#define iob_put(iobuf, len)
Definition: iobuf.h:116
#define UNM_PCIE_IRQ_VECTOR_BIT(n)
Definition: phantom.h:98
#define le32_to_cpu(value)
Definition: byteswap.h:113
unsigned long link_poll_timer
Link state poll timer.
Definition: phantom.c:197
uint8_t opcode
Opcode.
Definition: ena.h:16
u8 owner
Definition: CIB_PRM.h:36
#define PHN_NUM_SDS
Number of RX status descriptors.
Definition: phantom.c:100
#define DBGC(...)
Definition: compiler.h:505
#define PHN_NUM_RDS
Number of RX descriptors.
Definition: phantom.c:90
struct phantom_descriptor_rings * desc
Descriptor rings.
Definition: phantom.c:191
volatile uint32_t cmd_cons
TX consumer index.
Definition: phantom.c:114
static __always_inline unsigned long virt_to_bus(volatile const void *addr)
Convert virtual address to a bus address.
Definition: io.h:183
struct phantom_sds sds[PHN_NUM_SDS]
RX status descriptors.
Definition: phantom.c:110
#define PHN_LINK_POLL_FREQUENCY
Link state poll frequency.
Definition: phantom.c:87
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define DBGC_HDA(...)
Definition: compiler.h:506
static struct net_device * netdev
Definition: gdbudp.c:52
#define DBGC2_HDA(...)
Definition: compiler.h:523
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
#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
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:470
#define UNM_PCIE_IRQ_STATE
Definition: phantom.h:99
unsigned long sds_consumer_crb
RX status descriptor consumer CRB offset.
Definition: phantom.c:161
unsigned int rds_consumer_idx
RX consumer index.
Definition: phantom.c:170
#define DBGC2(...)
Definition: compiler.h:522
static void phantom_writel(struct phantom_nic *phantom, uint32_t value, unsigned long reg)
Write to Phantom CRB register.
Definition: phantom.c:373
#define PHN_NUM_CDS
Number of TX descriptors.
Definition: phantom.c:103
#define UNM_PCIE_IRQ_STATE_TRIGGERED(state)
Definition: phantom.h:100
unsigned int sds_consumer_idx
RX status consumer index.
Definition: phantom.c:172
unsigned int cds_consumer_idx
TX consumer index.
Definition: phantom.c:185
A Phantom NIC.
Definition: phantom.c:142
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 NULL
NULL pointer (VOID *)
Definition: Base.h:362
#define NX_GET(_ptr, _field)
Extract value of named field (for fields up to the size of a long)
Definition: nx_bitops.h:196
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
void * memset(void *dest, int character, size_t len) __nonnull
A persistent I/O buffer.
Definition: iobuf.h:32

References assert(), phantom_nic::cds_consumer_idx, phantom_nic::cds_iobuf, phantom_descriptor_rings::cmd_cons, DBGC, DBGC2, DBGC2_HDA, DBGC_HDA, phantom_nic::desc, handle, iob_pull, iob_put, le32_to_cpu, phantom_nic::link_poll_timer, memset(), netdev, netdev_priv(), netdev_rx(), netdev_tx_complete(), NULL, NX_GET, opcode, owner, phantom_irq_status_reg, phantom_poll_link_state(), phantom_readl(), phantom_refill_rx_ring(), phantom_writel(), PHN_LINK_POLL_FREQUENCY, PHN_NUM_CDS, PHN_NUM_RDS, PHN_NUM_SDS, phantom_nic::port, phantom_nic::rds_consumer_idx, phantom_nic::rds_iobuf, phantom_descriptor_rings::sds, phantom_nic::sds_consumer_crb, phantom_nic::sds_consumer_idx, phantom_nic::sds_irq_enabled, UNM_PCIE_IRQ_STATE, UNM_PCIE_IRQ_STATE_TRIGGERED, UNM_PCIE_IRQ_STATUS_MAGIC, UNM_PCIE_IRQ_VECTOR, UNM_PCIE_IRQ_VECTOR_BIT, UNM_RXPKT_DESC, UNM_SYN_OFFLOAD, virt_to_bus(), and wmb().

◆ phantom_irq()

static void phantom_irq ( struct net_device netdev,
int  enable 
)
static

Enable/disable interrupts.

Parameters
netdevNetwork device
enableInterrupts should be enabled

Definition at line 1436 of file phantom.c.

1436  {
1437  struct phantom_nic *phantom = netdev_priv ( netdev );
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 }
static void * netdev_priv(struct net_device *netdev)
Get driver private area for this network device.
Definition: netdevice.h:566
unsigned int sds_irq_enabled
RX interrupts enabled.
Definition: phantom.c:165
#define UNM_PCIE_IRQ_MASK_MAGIC
Definition: phantom.h:109
static struct net_device * netdev
Definition: gdbudp.c:52
static void phantom_writel(struct phantom_nic *phantom, uint32_t value, unsigned long reg)
Write to Phantom CRB register.
Definition: phantom.c:373
unsigned long sds_irq_mask_crb
RX interrupt mask CRB offset.
Definition: phantom.c:163
A Phantom NIC.
Definition: phantom.c:142
static const unsigned long phantom_irq_mask_reg[PHN_MAX_NUM_PORTS]
Interrupt mask registers.
Definition: phantom.c:205
unsigned int port
Port number.
Definition: phantom.c:153

References netdev, netdev_priv(), phantom_irq_mask_reg, phantom_writel(), phantom_nic::port, phantom_nic::sds_irq_enabled, phantom_nic::sds_irq_mask_crb, and UNM_PCIE_IRQ_MASK_MAGIC.

◆ phantom_clp_wait()

static int phantom_clp_wait ( struct phantom_nic phantom)
static

Wait for Phantom CLP command to complete.

Parameters
phantomPhantom NIC
Return values
rcReturn status code

Definition at line 1491 of file phantom.c.

1491  {
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 }
#define DBGC(...)
Definition: compiler.h:505
uint8_t status
Status.
Definition: ena.h:16
#define UNM_CAM_RAM_CLP_STATUS
Definition: phantom.h:136
#define PHN_CLP_CMD_TIMEOUT_MS
Maximum time to wait for CLP command to be issued.
Definition: phantom.c:81
static uint32_t phantom_readl(struct phantom_nic *phantom, unsigned long reg)
Read from Phantom CRB register.
Definition: phantom.c:358
unsigned int uint32_t
Definition: stdint.h:12
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:78
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:669
#define UNM_CAM_RAM_CLP_STATUS_DONE
Definition: phantom.h:138

References DBGC, ETIMEDOUT, mdelay(), phantom_readl(), PHN_CLP_CMD_TIMEOUT_MS, status, UNM_CAM_RAM_CLP_STATUS, and UNM_CAM_RAM_CLP_STATUS_DONE.

Referenced by phantom_clp_cmd().

◆ phantom_clp_cmd()

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 
)
static

Issue Phantom CLP command.

Parameters
phantomPhantom NIC
portVirtual port number
opcodeOpcode
data_inData in, or NULL
data_outData out, or NULL
offsetOffset within data
lenData buffer length
Return values
lenTotal transfer length (for reads), or negative error

Definition at line 1519 of file phantom.c.

1521  {
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 }
#define EINVAL
Invalid argument.
Definition: errno.h:428
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
Phantom CLP data.
Definition: phantom.c:1467
uint8_t opcode
Opcode.
Definition: ena.h:16
A command-line command.
Definition: command.h:9
struct arbelprm_completion_with_error error
Definition: arbel.h:12
#define DBGC(...)
Definition: compiler.h:505
#define UNM_CAM_RAM_CLP_STATUS_START
Definition: phantom.h:137
static int phantom_clp_wait(struct phantom_nic *phantom)
Wait for Phantom CLP command to complete.
Definition: phantom.c:1491
uint8_t status
Status.
Definition: ena.h:16
void * memcpy(void *dest, const void *src, size_t len) __nonnull
u8 port
Port number.
Definition: CIB_PRM.h:31
#define UNM_CAM_RAM_CLP_COMMAND
Definition: phantom.h:132
#define be32_to_cpu(value)
Definition: byteswap.h:116
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
#define UNM_CAM_RAM_CLP_STATUS
Definition: phantom.h:136
#define UNM_CAM_RAM_CLP_DATA_LO
Definition: phantom.h:134
#define UNM_CAM_RAM_CLP_DATA_HI
Definition: phantom.h:135
unsigned char uint8_t
Definition: stdint.h:10
static uint32_t phantom_readl(struct phantom_nic *phantom, unsigned long reg)
Read from Phantom CRB register.
Definition: phantom.c:358
uint32_t last
Length to read in last segment, or zero.
Definition: pccrc.h:30
unsigned int uint32_t
Definition: stdint.h:12
#define cpu_to_be32(value)
Definition: byteswap.h:110
uint32_t len
Length.
Definition: ena.h:14
static void phantom_writel(struct phantom_nic *phantom, uint32_t value, unsigned long reg)
Write to Phantom CRB register.
Definition: phantom.c:373
#define EIO
Input/output error.
Definition: errno.h:433
uint8_t command
Command.
Definition: intel.h:18
void mb(void)
Memory barrier.
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
uint64_t index
Index of the first segment within the content.
Definition: pccrc.h:21
void * memset(void *dest, int character, size_t len) __nonnull

References assert(), be32_to_cpu, command, cpu_to_be32, data, DBGC, EINVAL, EIO, error, index, last, len, mb(), memcpy(), memset(), offset, opcode, phantom_clp_wait(), phantom_readl(), phantom_writel(), port, rc, status, UNM_CAM_RAM_CLP_COMMAND, UNM_CAM_RAM_CLP_DATA_HI, UNM_CAM_RAM_CLP_DATA_LO, UNM_CAM_RAM_CLP_STATUS, and UNM_CAM_RAM_CLP_STATUS_START.

Referenced by phantom_clp_fetch(), and phantom_clp_store().

◆ phantom_clp_store()

static int phantom_clp_store ( struct phantom_nic phantom,
unsigned int  port,
unsigned int  setting,
const void *  data,
size_t  len 
)
static

Store Phantom CLP setting.

Parameters
phantomPhantom NIC
portVirtual port number
settingSetting number
dataData buffer
lenLength of data buffer
Return values
rcReturn status code

Definition at line 1615 of file phantom.c.

1617  {
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 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define PHN_CLP_BLKSIZE
Definition: phantom.c:1483
uint8_t opcode
Opcode.
Definition: ena.h:16
u8 port
Port number.
Definition: CIB_PRM.h:31
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
A setting.
Definition: settings.h:23
uint32_t len
Length.
Definition: ena.h:14
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
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References data, len, NULL, offset, opcode, phantom_clp_cmd(), PHN_CLP_BLKSIZE, port, and rc.

Referenced by phantom_store_setting().

◆ phantom_clp_fetch()

static int phantom_clp_fetch ( struct phantom_nic phantom,
unsigned int  port,
unsigned int  setting,
void *  data,
size_t  len 
)
static

Fetch Phantom CLP setting.

Parameters
phantomPhantom NIC
portVirtual port number
settingSetting number
dataData buffer
lenLength of data buffer
Return values
lenLength of setting, or negative error

Definition at line 1640 of file phantom.c.

1641  {
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 }
#define PHN_CLP_BLKSIZE
Definition: phantom.c:1483
uint8_t opcode
Opcode.
Definition: ena.h:16
u8 port
Port number.
Definition: CIB_PRM.h:31
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
A setting.
Definition: settings.h:23
uint32_t len
Length.
Definition: ena.h:14
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
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References data, len, NULL, offset, opcode, phantom_clp_cmd(), PHN_CLP_BLKSIZE, and port.

Referenced by phantom_fetch_setting().

◆ phantom_clp_setting()

static unsigned int phantom_clp_setting ( struct phantom_nic phantom,
const struct setting setting 
)
static

Find Phantom CLP setting.

Parameters
settingiPXE setting
clp_settingSetting number, or 0 if not found

Definition at line 1680 of file phantom.c.

1681  {
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 }
A Phantom CLP setting.
Definition: phantom.c:1661
const char * name
Name.
Definition: settings.h:28
uint64_t tag
Setting tag, if applicable.
Definition: settings.h:43
static const struct settings_scope phantom_settings_scope
Phantom CLP settings scope.
Definition: phantom.c:1462
static struct phantom_clp_setting clp_settings[]
Phantom CLP settings.
Definition: phantom.c:1669
unsigned int clp_setting
Setting number.
Definition: phantom.c:1665
A setting.
Definition: settings.h:23
#define DBGC2(...)
Definition: compiler.h:522
const struct settings_scope * scope
Setting scope (or NULL)
Definition: settings.h:49
int setting_cmp(const struct setting *a, const struct setting *b)
Compare two settings.
Definition: settings.c:1124

References phantom_clp_setting::clp_setting, clp_settings, DBGC2, setting::name, phantom_settings_scope, setting::scope, setting_cmp(), and setting::tag.

Referenced by phantom_fetch_setting(), phantom_setting_applies(), and phantom_store_setting().

◆ phantom_setting_applies()

static int phantom_setting_applies ( struct settings settings,
const struct setting setting 
)
static

Check applicability of Phantom CLP setting.

Parameters
settingsSettings block
settingSetting
Return values
appliesSetting applies within this settings block

Definition at line 1710 of file phantom.c.

1711  {
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 }
static unsigned int phantom_clp_setting(struct phantom_nic *phantom, const struct setting *setting)
Find Phantom CLP setting.
Definition: phantom.c:1680
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
A settings block.
Definition: settings.h:132
A setting.
Definition: settings.h:23
A Phantom NIC.
Definition: phantom.c:142

References container_of, and phantom_clp_setting().

◆ phantom_store_setting()

static int phantom_store_setting ( struct settings settings,
const struct setting setting,
const void *  data,
size_t  len 
)
static

Store Phantom CLP setting.

Parameters
settingsSettings block
settingSetting to store
dataSetting data, or NULL to clear setting
lenLength of setting data
Return values
rcReturn status code

Definition at line 1730 of file phantom.c.

1732  {
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 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DBGC(...)
Definition: compiler.h:505
static unsigned int phantom_clp_setting(struct phantom_nic *phantom, const struct setting *setting)
Find Phantom CLP setting.
Definition: phantom.c:1680
const char * name
Name.
Definition: settings.h:28
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
A settings block.
Definition: settings.h:132
A setting.
Definition: settings.h:23
uint32_t len
Length.
Definition: ena.h:14
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
A Phantom NIC.
Definition: phantom.c:142
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
unsigned int port
Port number.
Definition: phantom.c:153

References assert(), container_of, data, DBGC, len, setting::name, phantom_clp_setting(), phantom_clp_store(), phantom_nic::port, rc, and strerror().

◆ phantom_fetch_setting()

static int phantom_fetch_setting ( struct settings settings,
struct setting setting,
void *  data,
size_t  len 
)
static

Fetch Phantom CLP setting.

Parameters
settingsSettings block
settingSetting to fetch
dataBuffer to fill with setting data
lenLength of buffer
Return values
lenLength of setting data, or negative error

Definition at line 1762 of file phantom.c.

1764  {
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 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DBGC(...)
Definition: compiler.h:505
static unsigned int phantom_clp_setting(struct phantom_nic *phantom, const struct setting *setting)
Find Phantom CLP setting.
Definition: phantom.c:1680
const char * name
Name.
Definition: settings.h:28
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
A settings block.
Definition: settings.h:132
A setting.
Definition: settings.h:23
uint32_t len
Length.
Definition: ena.h:14
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
A Phantom NIC.
Definition: phantom.c:142
unsigned int port
Port number.
Definition: phantom.c:153
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

References assert(), container_of, data, DBGC, len, setting::name, phantom_clp_fetch(), phantom_clp_setting(), phantom_nic::port, rc, and strerror().

◆ phantom_map_crb()

static int phantom_map_crb ( struct phantom_nic phantom,
struct pci_device pci 
)
static

Map Phantom CRB window.

Parameters
phantomPhantom NIC
Return values
rcReturn status code

Definition at line 1806 of file phantom.c.

1807  {
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 = ioremap ( 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 }
#define EINVAL
Invalid argument.
Definition: errno.h:428
unsigned long crb_window
Current CRB window.
Definition: phantom.c:146
#define DBGC(...)
Definition: compiler.h:505
#define PCI_BASE_ADDRESS_0
Definition: pci.h:61
void * bar0
BAR 0.
Definition: phantom.c:144
unsigned long pci_bar_start(struct pci_device *pci, unsigned int reg)
Find the start of a PCI BAR.
Definition: pci.c:96
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
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:287
unsigned long pci_bar_size(struct pci_device *pci, unsigned int reg)
Find the size of a PCI BAR.
Definition: pciextra.c:90
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
unsigned long(* crb_access)(struct phantom_nic *phantom, unsigned long reg)
CRB window access method.
Definition: phantom.c:148
#define EIO
Input/output error.
Definition: errno.h:433
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:290
void * ioremap(unsigned long bus_addr, size_t len)
Map bus address as an I/O address.

References phantom_nic::bar0, phantom_nic::crb_access, phantom_nic::crb_window, DBGC, EINVAL, EIO, ioremap(), PCI_ARGS, pci_bar_size(), pci_bar_start(), PCI_BASE_ADDRESS_0, PCI_FMT, phantom_crb_access_128m(), phantom_crb_access_2m(), and phantom_crb_access_32m().

Referenced by phantom_probe().

◆ phantom_unhalt_pegs()

static void phantom_unhalt_pegs ( struct phantom_nic phantom)
static

Unhalt all PEGs.

Parameters
phantomPhantom NIC

Definition at line 1859 of file phantom.c.

1859  {
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 }
#define UNM_PEG_3_HALT_STATUS
Definition: phantom.h:210
#define UNM_PEG_2_HALT_STATUS
Definition: phantom.h:206
#define UNM_PEG_1_HALT_STATUS
Definition: phantom.h:202
#define UNM_PEG_0_HALT_STATUS
Definition: phantom.h:198
static uint32_t phantom_readl(struct phantom_nic *phantom, unsigned long reg)
Read from Phantom CRB register.
Definition: phantom.c:358
unsigned int uint32_t
Definition: stdint.h:12
static void phantom_writel(struct phantom_nic *phantom, uint32_t value, unsigned long reg)
Write to Phantom CRB register.
Definition: phantom.c:373
#define UNM_PEG_4_HALT_STATUS
Definition: phantom.h:214

References phantom_readl(), phantom_writel(), UNM_PEG_0_HALT_STATUS, UNM_PEG_1_HALT_STATUS, UNM_PEG_2_HALT_STATUS, UNM_PEG_3_HALT_STATUS, and UNM_PEG_4_HALT_STATUS.

Referenced by phantom_init_cmdpeg().

◆ phantom_init_cmdpeg()

static int phantom_init_cmdpeg ( struct phantom_nic phantom)
static

Initialise the Phantom command PEG.

Parameters
phantomPhantom NIC
Return values
rcReturn status code

Definition at line 1880 of file phantom.c.

1880  {
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 }
#define UNM_CAM_RAM_WOL_PORT_MODE
Definition: phantom.h:142
#define UNM_ROMUSB_GLB_SW_RESET
Definition: phantom.h:173
#define UNM_ROMUSB_GLB_PEGTUNE_DONE
Definition: phantom.h:175
#define PHN_CMDPEG_INIT_TIMEOUT_SEC
Maximum time to wait for command PEG to initialise.
Definition: phantom.c:69
#define DBGC(...)
Definition: compiler.h:505
#define UNM_CAM_RAM_COLD_BOOT
Definition: phantom.h:144
#define UNM_NIC_REG_DUMMY_BUF
Definition: phantom.h:158
#define UNM_NIC_REG_CMDPEG_STATE_INITIALIZE_ACK
Definition: phantom.h:157
#define UNM_NIC_REG_CMDPEG_STATE_INITIALIZED
Definition: phantom.h:156
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
#define UNM_NIC_REG_CMDPEG_STATE
Definition: phantom.h:155
#define UNM_NIC_REG_DUMMY_BUF_INIT
Definition: phantom.h:159
#define UNM_ROMUSB_GLB_SW_RESET_MAGIC
Definition: phantom.h:174
static uint32_t phantom_readl(struct phantom_nic *phantom, unsigned long reg)
Read from Phantom CRB register.
Definition: phantom.c:358
#define UNM_CAM_RAM_COLD_BOOT_MAGIC
Definition: phantom.h:145
unsigned int uint32_t
Definition: stdint.h:12
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:78
static void phantom_unhalt_pegs(struct phantom_nic *phantom)
Unhalt all PEGs.
Definition: phantom.c:1859
static void phantom_writel(struct phantom_nic *phantom, uint32_t value, unsigned long reg)
Write to Phantom CRB register.
Definition: phantom.c:373
#define EIO
Input/output error.
Definition: errno.h:433
#define UNM_CAM_RAM_PORT_MODE_AUTO_NEG_1G
Definition: phantom.h:125
#define UNM_NIC_REG_DUMMY_BUF_ADDR_HI
Definition: phantom.h:153
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:669
#define UNM_NIC_REG_DUMMY_BUF_ADDR_LO
Definition: phantom.h:154
#define UNM_ROMUSB_GLB_PEGTUNE_DONE_MAGIC
Definition: phantom.h:176

References DBGC, EIO, ETIMEDOUT, mdelay(), phantom_readl(), phantom_unhalt_pegs(), phantom_write_hilo(), phantom_writel(), PHN_CMDPEG_INIT_TIMEOUT_SEC, UNM_CAM_RAM_COLD_BOOT, UNM_CAM_RAM_COLD_BOOT_MAGIC, UNM_CAM_RAM_PORT_MODE_AUTO_NEG_1G, UNM_CAM_RAM_WOL_PORT_MODE, UNM_NIC_REG_CMDPEG_STATE, UNM_NIC_REG_CMDPEG_STATE_INITIALIZE_ACK, UNM_NIC_REG_CMDPEG_STATE_INITIALIZED, UNM_NIC_REG_DUMMY_BUF, UNM_NIC_REG_DUMMY_BUF_ADDR_HI, UNM_NIC_REG_DUMMY_BUF_ADDR_LO, UNM_NIC_REG_DUMMY_BUF_INIT, UNM_ROMUSB_GLB_PEGTUNE_DONE, UNM_ROMUSB_GLB_PEGTUNE_DONE_MAGIC, UNM_ROMUSB_GLB_SW_RESET, and UNM_ROMUSB_GLB_SW_RESET_MAGIC.

Referenced by phantom_probe().

◆ phantom_get_macaddr()

static void phantom_get_macaddr ( struct phantom_nic phantom,
uint8_t hw_addr 
)
static

Read Phantom MAC address.

Parameters
phanton_portPhantom NIC
hw_addrBuffer to fill with MAC address

Definition at line 1969 of file phantom.c.

1970  {
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 }
#define DBGC(...)
Definition: compiler.h:505
#define UNM_CAM_RAM_MAC_ADDRS
Definition: phantom.h:143
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
const char * eth_ntoa(const void *ll_addr)
Transcribe Ethernet address.
Definition: ethernet.c:175
unsigned char uint8_t
Definition: stdint.h:10
static uint32_t phantom_readl(struct phantom_nic *phantom, unsigned long reg)
Read from Phantom CRB register.
Definition: phantom.c:358
#define ETH_ALEN
Definition: if_ether.h:8
unsigned int uint32_t
Definition: stdint.h:12
union @16 u
unsigned int port
Port number.
Definition: phantom.c:153

References DBGC, ETH_ALEN, eth_ntoa(), offset, phantom_readl(), phantom_nic::port, u, and UNM_CAM_RAM_MAC_ADDRS.

Referenced by phantom_probe().

◆ phantom_check_boot_enable()

static int phantom_check_boot_enable ( struct phantom_nic phantom)
static

Check Phantom is enabled for boot.

Parameters
phanton_portPhantom NIC
Return values
rcReturn status code

This is something of an ugly hack to accommodate an OEM requirement. The NIC has only one expansion ROM BAR, rather than one per port. To allow individual ports to be selectively enabled/disabled for PXE boot (as required), we must therefore leave the expansion ROM always enabled, and place the per-port enable/disable logic within the iPXE driver.

Definition at line 2007 of file phantom.c.

2007  {
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 }
#define DBGC(...)
Definition: compiler.h:505
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
#define UNM_CAM_RAM_BOOT_ENABLE
Definition: phantom.h:141
static uint32_t phantom_readl(struct phantom_nic *phantom, unsigned long reg)
Read from Phantom CRB register.
Definition: phantom.c:358
unsigned int port
Port number.
Definition: phantom.c:153

References DBGC, ENOTSUP, phantom_readl(), phantom_nic::port, and UNM_CAM_RAM_BOOT_ENABLE.

Referenced by phantom_probe().

◆ phantom_init_rcvpeg()

static int phantom_init_rcvpeg ( struct phantom_nic phantom)
static

Initialise Phantom receive PEG.

Parameters
phantomPhantom NIC
Return values
rcReturn status code

Definition at line 2026 of file phantom.c.

2026  {
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 }
#define UNM_NIC_REG_RCVPEG_STATE_INITIALIZED
Definition: phantom.h:166
#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
#define UNM_NIC_REG_RCVPEG_STATE
Definition: phantom.h:165
static uint32_t phantom_readl(struct phantom_nic *phantom, unsigned long reg)
Read from Phantom CRB register.
Definition: phantom.c:358
unsigned int uint32_t
Definition: stdint.h:12
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:78
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:669

References DBGC, ETIMEDOUT, mdelay(), phantom_readl(), PHN_RCVPEG_INIT_TIMEOUT_SEC, UNM_NIC_REG_RCVPEG_STATE, and UNM_NIC_REG_RCVPEG_STATE_INITIALIZED.

Referenced by phantom_probe().

◆ phantom_probe()

static int phantom_probe ( struct pci_device pci)
static

Probe PCI device.

Parameters
pciPCI device
idPCI ID
Return values
rcReturn status code

Definition at line 2059 of file phantom.c.

2059  {
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 ( netdev );
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 =
2100  PCI_BUSDEVFN ( PCI_SEG ( 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 }
static int phantom_check_boot_enable(struct phantom_nic *phantom)
Check Phantom is enabled for boot.
Definition: phantom.c:2007
static struct settings_operations phantom_settings_operations
Phantom CLP settings operations.
Definition: phantom.c:1788
#define PCI_FUNC(busdevfn)
Definition: pci.h:258
#define PCI_BUS(busdevfn)
Definition: pci.h:256
static void * netdev_priv(struct net_device *netdev)
Get driver private area for this network device.
Definition: netdevice.h:566
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static void phantom_get_macaddr(struct phantom_nic *phantom, uint8_t *hw_addr)
Read Phantom MAC address.
Definition: phantom.c:1969
void unregister_settings(struct settings *settings)
Unregister settings block.
Definition: settings.c:517
#define DBGC(...)
Definition: compiler.h:505
#define PCI_BUSDEVFN(segment, bus, slot, func)
Definition: pci.h:259
void adjust_pci_device(struct pci_device *pci)
Enable PCI device.
Definition: pci.c:149
struct device dev
Generic device.
Definition: pci.h:189
static struct settings * netdev_settings(struct net_device *netdev)
Get per-netdevice configuration settings block.
Definition: netdevice.h:577
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:495
static int phantom_map_crb(struct phantom_nic *phantom, struct pci_device *pci)
Map Phantom CRB window.
Definition: phantom.c:1806
static void netdev_init(struct net_device *netdev, struct net_device_operations *op)
Initialise a network device.
Definition: netdevice.h:498
static void pci_set_drvdata(struct pci_device *pci, void *priv)
Set PCI driver-private data.
Definition: pci.h:338
#define ENOMEM
Not enough space.
Definition: errno.h:534
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:555
int pci_read_config_dword(struct pci_device *pci, unsigned int where, uint32_t *value)
Read 32-bit dword from PCI configuration space.
static struct net_device * netdev
Definition: gdbudp.c:52
struct settings settings
Non-volatile settings.
Definition: phantom.c:201
static int phantom_init_rcvpeg(struct phantom_nic *phantom)
Initialise Phantom receive PEG.
Definition: phantom.c:2026
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:844
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static const struct settings_scope phantom_settings_scope
Phantom CLP settings scope.
Definition: phantom.c:1462
struct refcnt refcnt
Reference counter.
Definition: netdevice.h:350
#define PCI_SLOT(busdevfn)
Definition: pci.h:257
int register_netdev(struct net_device *netdev)
Register network device.
Definition: netdevice.c:667
A network device.
Definition: netdevice.h:348
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:511
A settings block.
Definition: settings.h:132
unsigned int uint32_t
Definition: stdint.h:12
struct device * dev
Underlying hardware device.
Definition: netdevice.h:360
uint32_t busdevfn
Segment, bus, device, and function (bus:dev.fn) number.
Definition: pci.h:210
struct net_device * alloc_etherdev(size_t priv_size)
Allocate Ethernet device.
Definition: ethernet.c:264
#define PHN_MAX_NUM_PORTS
Maximum number of ports.
Definition: phantom.c:53
int pci_write_config_dword(struct pci_device *pci, unsigned int where, uint32_t value)
Write 32-bit dword to PCI configuration space.
int register_settings(struct settings *settings, struct settings *parent, const char *name)
Register settings block.
Definition: settings.c:478
static int phantom_init_cmdpeg(struct phantom_nic *phantom)
Initialise the Phantom command PEG.
Definition: phantom.c:1880
A Phantom NIC.
Definition: phantom.c:142
#define PCI_SEG(busdevfn)
Definition: pci.h:255
uint8_t hw_addr[MAX_HW_ADDR_LEN]
Hardware address.
Definition: netdevice.h:375
unsigned int port
Port number.
Definition: phantom.c:153
static struct net_device_operations phantom_operations
Phantom net device operations.
Definition: phantom.c:1447
void * memset(void *dest, int character, size_t len) __nonnull

References adjust_pci_device(), alloc_etherdev(), assert(), pci_device::busdevfn, DBGC, pci_device::dev, net_device::dev, ENOMEM, net_device::hw_addr, memset(), netdev, netdev_init(), netdev_nullify(), netdev_priv(), netdev_put(), netdev_settings(), PCI_BUS, PCI_BUSDEVFN, PCI_FUNC, pci_read_config_dword(), PCI_SEG, pci_set_drvdata(), PCI_SLOT, pci_write_config_dword(), phantom_check_boot_enable(), phantom_get_macaddr(), phantom_init_cmdpeg(), phantom_init_rcvpeg(), phantom_map_crb(), phantom_operations, phantom_settings_operations, phantom_settings_scope, PHN_MAX_NUM_PORTS, phantom_nic::port, rc, net_device::refcnt, register_netdev(), register_settings(), phantom_nic::settings, settings_init(), strerror(), unregister_netdev(), and unregister_settings().

◆ phantom_remove()

static void phantom_remove ( struct pci_device pci)
static

Remove PCI device.

Parameters
pciPCI device

Definition at line 2162 of file phantom.c.

2162  {
2163  struct net_device *netdev = pci_get_drvdata ( pci );
2164  struct phantom_nic *phantom = netdev_priv ( netdev );
2165 
2166  unregister_settings ( &phantom->settings );
2168  netdev_nullify ( netdev );
2169  netdev_put ( netdev );
2170 }
static void * netdev_priv(struct net_device *netdev)
Get driver private area for this network device.
Definition: netdevice.h:566
void unregister_settings(struct settings *settings)
Unregister settings block.
Definition: settings.c:517
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:555
static struct net_device * netdev
Definition: gdbudp.c:52
struct settings settings
Non-volatile settings.
Definition: phantom.c:201
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:844
A network device.
Definition: netdevice.h:348
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:511
static void * pci_get_drvdata(struct pci_device *pci)
Get PCI driver-private data.
Definition: pci.h:348
A Phantom NIC.
Definition: phantom.c:142

References netdev, netdev_nullify(), netdev_priv(), netdev_put(), pci_get_drvdata(), phantom_nic::settings, unregister_netdev(), and unregister_settings().

Variable Documentation

◆ phantom_irq_mask_reg

const unsigned long phantom_irq_mask_reg[PHN_MAX_NUM_PORTS]
static
Initial value:
= {
}
#define UNM_PCIE_IRQ_MASK_F1
Definition: phantom.h:102
#define UNM_PCIE_IRQ_MASK_F6
Definition: phantom.h:107
#define UNM_PCIE_IRQ_MASK_F5
Definition: phantom.h:106
#define UNM_PCIE_IRQ_MASK_F7
Definition: phantom.h:108
#define UNM_PCIE_IRQ_MASK_F0
Definition: phantom.h:101
#define UNM_PCIE_IRQ_MASK_F4
Definition: phantom.h:105
#define UNM_PCIE_IRQ_MASK_F2
Definition: phantom.h:103
#define UNM_PCIE_IRQ_MASK_F3
Definition: phantom.h:104

Interrupt mask registers.

Definition at line 205 of file phantom.c.

Referenced by phantom_irq().

◆ phantom_irq_status_reg

const unsigned long phantom_irq_status_reg[PHN_MAX_NUM_PORTS]
static
Initial value:
= {
}
#define UNM_PCIE_IRQ_STATUS_F6
Definition: phantom.h:116
#define UNM_PCIE_IRQ_STATUS_F7
Definition: phantom.h:117
#define UNM_PCIE_IRQ_STATUS_F0
Definition: phantom.h:110
#define UNM_PCIE_IRQ_STATUS_F2
Definition: phantom.h:112
#define UNM_PCIE_IRQ_STATUS_F3
Definition: phantom.h:113
#define UNM_PCIE_IRQ_STATUS_F1
Definition: phantom.h:111
#define UNM_PCIE_IRQ_STATUS_F5
Definition: phantom.h:115
#define UNM_PCIE_IRQ_STATUS_F4
Definition: phantom.h:114

Interrupt status registers.

Definition at line 217 of file phantom.c.

Referenced by phantom_poll().

◆ phantom_operations

struct net_device_operations phantom_operations
static
Initial value:
= {
.open = phantom_open,
.close = phantom_close,
.transmit = phantom_transmit,
.poll = phantom_poll,
.irq = phantom_irq,
}
static void phantom_irq(struct net_device *netdev, int enable)
Enable/disable interrupts.
Definition: phantom.c:1436
static void phantom_poll(struct net_device *netdev)
Poll for received packets.
Definition: phantom.c:1299
static void phantom_close(struct net_device *netdev)
Close NIC.
Definition: phantom.c:1222
static int phantom_transmit(struct net_device *netdev, struct io_buffer *iobuf)
Transmit packet.
Definition: phantom.c:1259
static int phantom_open(struct net_device *netdev)
Open NIC.
Definition: phantom.c:1162

Phantom net device operations.

Definition at line 1447 of file phantom.c.

Referenced by phantom_probe().

◆ phantom_settings_scope

const struct settings_scope phantom_settings_scope
static

Phantom CLP settings scope.

Definition at line 1462 of file phantom.c.

Referenced by phantom_clp_setting(), and phantom_probe().

◆ clp_settings

struct phantom_clp_setting clp_settings[]
static
Initial value:
= {
{ &mac_setting, 0x01 },
}

Phantom CLP settings.

Definition at line 1669 of file phantom.c.

Referenced by phantom_clp_setting().

◆ phantom_settings_operations

struct settings_operations phantom_settings_operations
static
Initial value:
= {
}
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
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_fetch_setting(struct settings *settings, struct setting *setting, void *data, size_t len)
Fetch Phantom CLP setting.
Definition: phantom.c:1762

Phantom CLP settings operations.

Definition at line 1788 of file phantom.c.

Referenced by phantom_probe().

◆ phantom_nics

struct pci_device_id phantom_nics[]
static
Initial value:
= {
PCI_ROM ( 0x4040, 0x0100, "nx", "NX", 0 ),
}
#define PCI_ROM(_vendor, _device, _name, _description, _data)
Definition: pci.h:283

Phantom PCI IDs.

Definition at line 2173 of file phantom.c.

◆ __pci_driver

struct pci_driver phantom_driver __pci_driver
Initial value:
= {
.ids = phantom_nics,
.id_count = ( sizeof ( phantom_nics ) / sizeof ( phantom_nics[0] ) ),
.probe = phantom_probe,
}
static int phantom_probe(struct pci_device *pci)
Probe PCI device.
Definition: phantom.c:2059
static struct pci_device_id phantom_nics[]
Phantom PCI IDs.
Definition: phantom.c:2173
static struct xen_remove_from_physmap * remove
Definition: xenmem.h:39
static void phantom_remove(struct pci_device *pci)
Remove PCI device.
Definition: phantom.c:2162

Phantom PCI driver.

Definition at line 2178 of file phantom.c.