summaryrefslogtreecommitdiffstats
path: root/src/drivers
diff options
context:
space:
mode:
authorSimon Rettberg2021-03-08 15:55:33 +0100
committerSimon Rettberg2021-03-08 15:55:33 +0100
commit6707d9218c8e6e760e53068d5f41ceb31fac6ea0 (patch)
tree88e8fc84ede2a0ed2c1cec3a6109beb9fb53abf5 /src/drivers
parentMerge branch 'master' into openslx (diff)
parent[linux] Do not assume that stat() works on sysfs files (diff)
downloadipxe-6707d9218c8e6e760e53068d5f41ceb31fac6ea0.tar.gz
ipxe-6707d9218c8e6e760e53068d5f41ceb31fac6ea0.tar.xz
ipxe-6707d9218c8e6e760e53068d5f41ceb31fac6ea0.zip
Merge branch 'master' into openslx
Diffstat (limited to 'src/drivers')
-rw-r--r--src/drivers/block/ibft.c8
-rw-r--r--src/drivers/bus/isa.c3
-rw-r--r--src/drivers/bus/pcimsix.c2
-rw-r--r--src/drivers/bus/usb.c96
-rw-r--r--src/drivers/bus/virtio-pci.c2
-rw-r--r--src/drivers/infiniband/MT25218_PRM.h176
-rw-r--r--src/drivers/infiniband/MT25408_PRM.h264
-rw-r--r--src/drivers/infiniband/arbel.c78
-rw-r--r--src/drivers/infiniband/flexboot_nodnic.c3
-rwxr-xr-xsrc/drivers/infiniband/golan.c68
-rw-r--r--src/drivers/infiniband/hermon.c406
-rw-r--r--src/drivers/infiniband/hermon.h37
-rw-r--r--src/drivers/infiniband/linda.c19
-rw-r--r--src/drivers/infiniband/mlx_utils_flexboot/src/mlx_memory_priv.c4
-rw-r--r--src/drivers/infiniband/mlx_utils_flexboot/src/mlx_pci_priv.c2
-rw-r--r--src/drivers/infiniband/nodnic_prm.h4
-rw-r--r--src/drivers/infiniband/qib7322.c19
-rw-r--r--src/drivers/linux/af_packet.c2
-rw-r--r--src/drivers/linux/linux.c50
-rw-r--r--src/drivers/linux/slirp.c552
-rw-r--r--src/drivers/linux/tap.c2
-rw-r--r--src/drivers/net/3c90x.c8
-rw-r--r--src/drivers/net/amd8111e.c2
-rw-r--r--src/drivers/net/ath/ath5k/ath5k.c8
-rw-r--r--src/drivers/net/ath/ath5k/ath5k_eeprom.c1
-rw-r--r--src/drivers/net/ath/ath9k/ath9k.c2
-rw-r--r--src/drivers/net/ath/ath9k/ath9k_init.c6
-rw-r--r--src/drivers/net/atl1e.c4
-rw-r--r--src/drivers/net/b44.c14
-rw-r--r--src/drivers/net/bnx2.c2
-rw-r--r--src/drivers/net/bnxt/bnxt.c32
-rw-r--r--src/drivers/net/eepro100.c18
-rw-r--r--src/drivers/net/efi/nii.c42
-rw-r--r--src/drivers/net/ena.c66
-rw-r--r--src/drivers/net/ena.h2
-rw-r--r--src/drivers/net/etherfabric.c6
-rw-r--r--src/drivers/net/exanic.c10
-rw-r--r--src/drivers/net/forcedeth.c6
-rw-r--r--src/drivers/net/icplus.c8
-rw-r--r--src/drivers/net/igbvf/igbvf_main.c12
-rw-r--r--src/drivers/net/intel.c47
-rw-r--r--src/drivers/net/intel.h5
-rw-r--r--src/drivers/net/intelx.c8
-rw-r--r--src/drivers/net/intelxl.c122
-rw-r--r--src/drivers/net/intelxl.h34
-rw-r--r--src/drivers/net/intelxlvf.c23
-rw-r--r--src/drivers/net/intelxvf.c7
-rw-r--r--src/drivers/net/iphone.c2268
-rw-r--r--src/drivers/net/iphone.h291
-rw-r--r--src/drivers/net/jme.c10
-rw-r--r--src/drivers/net/myri10ge.c8
-rw-r--r--src/drivers/net/myson.c8
-rw-r--r--src/drivers/net/natsemi.c8
-rw-r--r--src/drivers/net/ncm.c13
-rw-r--r--src/drivers/net/netfront.c6
-rw-r--r--src/drivers/net/pcnet32.c8
-rw-r--r--src/drivers/net/phantom/phantom.c18
-rw-r--r--src/drivers/net/prism2_pci.c2
-rw-r--r--src/drivers/net/realtek.c135
-rw-r--r--src/drivers/net/realtek.h18
-rw-r--r--src/drivers/net/rhine.c6
-rw-r--r--src/drivers/net/rtl818x/rtl818x.c12
-rw-r--r--src/drivers/net/sfc/efx_common.c7
-rw-r--r--src/drivers/net/sfc/efx_hunt.c9
-rw-r--r--src/drivers/net/sfc/efx_hunt.h5
-rw-r--r--src/drivers/net/sfc/mcdi.h6
-rw-r--r--src/drivers/net/sfc/sfc_hunt.c5
-rw-r--r--src/drivers/net/sis190.c10
-rw-r--r--src/drivers/net/skeleton.c2
-rwxr-xr-xsrc/drivers/net/skge.c9
-rw-r--r--src/drivers/net/sky2.c16
-rw-r--r--src/drivers/net/tg3/tg3.c22
-rw-r--r--src/drivers/net/thunderx.c16
-rw-r--r--src/drivers/net/velocity.c14
-rw-r--r--src/drivers/net/vmxnet3.c15
-rw-r--r--src/drivers/net/vxge/vxge_config.c12
-rw-r--r--src/drivers/net/vxge/vxge_main.c2
-rw-r--r--src/drivers/usb/ehci.c31
-rw-r--r--src/drivers/usb/uhci.c26
-rw-r--r--src/drivers/usb/usbblk.c912
-rw-r--r--src/drivers/usb/usbblk.h121
-rw-r--r--src/drivers/usb/usbio.c5
-rw-r--r--src/drivers/usb/xhci.c265
-rw-r--r--src/drivers/usb/xhci.h43
84 files changed, 5689 insertions, 967 deletions
diff --git a/src/drivers/block/ibft.c b/src/drivers/block/ibft.c
index f9918363a..ca5fad9ff 100644
--- a/src/drivers/block/ibft.c
+++ b/src/drivers/block/ibft.c
@@ -48,11 +48,15 @@ FILE_LICENCE ( BSD2 );
*
* iSCSI boot firmware table
*
- * The information in this file is derived from the document "iSCSI
- * Boot Firmware Table (iBFT)" as published by IBM at
+ * The information in this file is originally derived from the document "iSCSI
+ * Boot Firmware Table (iBFT)" as published by IBM at:
*
* ftp://ftp.software.ibm.com/systems/support/system_x_pdf/ibm_iscsi_boot_firmware_table_v1.02.pdf
*
+ * That file is no longer available, but a more recent version is available:
+ *
+ * ftp://ftp.software.ibm.com/systems/support/bladecenter/iscsi_boot_firmware_table_v1.03.pdf
+ *
*/
/**
diff --git a/src/drivers/bus/isa.c b/src/drivers/bus/isa.c
index da0c43c60..94d4ce99b 100644
--- a/src/drivers/bus/isa.c
+++ b/src/drivers/bus/isa.c
@@ -5,6 +5,7 @@
#include <errno.h>
#include <ipxe/io.h>
#include <ipxe/isa.h>
+#include <config/isa.h>
FILE_LICENCE ( GPL2_OR_LATER );
@@ -94,7 +95,7 @@ static void isa_remove ( struct isa_device *isa ) {
static int isabus_probe ( struct root_device *rootdev ) {
struct isa_device *isa = NULL;
struct isa_driver *driver;
- int ioidx;
+ long ioidx;
int rc;
for_each_table_entry ( driver, ISA_DRIVERS ) {
diff --git a/src/drivers/bus/pcimsix.c b/src/drivers/bus/pcimsix.c
index 80893c418..eb0450d91 100644
--- a/src/drivers/bus/pcimsix.c
+++ b/src/drivers/bus/pcimsix.c
@@ -84,7 +84,7 @@ static void * pci_msix_ioremap ( struct pci_device *pci, struct pci_msix *msix,
msix, pci_msix_name ( cfg ), base, bar, offset );
/* Map BAR portion */
- io = ioremap ( ( start + offset ), PCI_MSIX_LEN );
+ io = pci_ioremap ( pci, ( start + offset ), PCI_MSIX_LEN );
if ( ! io ) {
DBGC ( msix, "MSI-X %p %s could not map %#08lx\n",
msix, pci_msix_name ( cfg ), base );
diff --git a/src/drivers/bus/usb.c b/src/drivers/bus/usb.c
index a7b687528..428ae26c1 100644
--- a/src/drivers/bus/usb.c
+++ b/src/drivers/bus/usb.c
@@ -363,6 +363,35 @@ static int usb_endpoint_clear_tt ( struct usb_endpoint *ep ) {
}
/**
+ * Clear endpoint halt (if applicable)
+ *
+ * @v ep USB endpoint
+ * @ret rc Return status code
+ */
+int usb_endpoint_clear_halt ( struct usb_endpoint *ep ) {
+ struct usb_device *usb = ep->usb;
+ unsigned int type;
+ int rc;
+
+ /* Clear transaction translator, if applicable */
+ if ( ( rc = usb_endpoint_clear_tt ( ep ) ) != 0 )
+ return rc;
+
+ /* Clear endpoint halt (if applicable) */
+ type = ( ep->attributes & USB_ENDPOINT_ATTR_TYPE_MASK );
+ if ( ( type != USB_ENDPOINT_ATTR_CONTROL ) &&
+ ( ( rc = usb_clear_feature ( usb, USB_RECIP_ENDPOINT,
+ USB_ENDPOINT_HALT,
+ ep->address ) ) != 0 ) ) {
+ DBGC ( usb, "USB %s %s could not clear endpoint halt: %s\n",
+ usb->name, usb_endpoint_name ( ep ), strerror ( rc ) );
+ return rc;
+ }
+
+ return 0;
+}
+
+/**
* Close USB endpoint
*
* @v ep USB endpoint
@@ -399,26 +428,14 @@ void usb_endpoint_close ( struct usb_endpoint *ep ) {
*/
static int usb_endpoint_reset ( struct usb_endpoint *ep ) {
struct usb_device *usb = ep->usb;
- unsigned int type;
int rc;
/* Sanity check */
assert ( ! list_empty ( &ep->halted ) );
- /* Clear transaction translator, if applicable */
- if ( ( rc = usb_endpoint_clear_tt ( ep ) ) != 0 )
- return rc;
-
- /* Clear endpoint halt, if applicable */
- type = ( ep->attributes & USB_ENDPOINT_ATTR_TYPE_MASK );
- if ( ( type != USB_ENDPOINT_ATTR_CONTROL ) &&
- ( ( rc = usb_clear_feature ( usb, USB_RECIP_ENDPOINT,
- USB_ENDPOINT_HALT,
- ep->address ) ) != 0 ) ) {
- DBGC ( usb, "USB %s %s could not clear endpoint halt: %s\n",
- usb->name, usb_endpoint_name ( ep ), strerror ( rc ) );
+ /* Clear device halt, if applicable */
+ if ( ( rc = usb_endpoint_clear_halt ( ep ) ) != 0 )
return rc;
- }
/* Reset endpoint */
if ( ( rc = ep->host->reset ( ep ) ) != 0 ) {
@@ -634,12 +651,13 @@ int usb_prefill ( struct usb_endpoint *ep ) {
}
/**
- * Refill endpoint
+ * Refill endpoint up to specified limit
*
* @v ep USB endpoint
+ * @v max Fill limit
* @ret rc Return status code
*/
-int usb_refill ( struct usb_endpoint *ep ) {
+int usb_refill_limit ( struct usb_endpoint *ep, unsigned int max ) {
struct io_buffer *iobuf;
size_t reserve = ep->reserve;
size_t len = ( ep->len ? ep->len : ep->mtu );
@@ -650,7 +668,9 @@ int usb_refill ( struct usb_endpoint *ep ) {
assert ( ep->max > 0 );
/* Refill endpoint */
- while ( ep->fill < ep->max ) {
+ if ( max > ep->max )
+ max = ep->max;
+ while ( ep->fill < max ) {
/* Get or allocate buffer */
if ( list_empty ( &ep->recycled ) ) {
@@ -682,6 +702,16 @@ int usb_refill ( struct usb_endpoint *ep ) {
}
/**
+ * Refill endpoint
+ *
+ * @v ep USB endpoint
+ * @ret rc Return status code
+ */
+int usb_refill ( struct usb_endpoint *ep ) {
+ return usb_refill_limit ( ep, ep->max );
+}
+
+/**
* Discard endpoint recycled buffer list
*
* @v ep USB endpoint
@@ -818,6 +848,7 @@ int usb_control ( struct usb_device *usb, unsigned int request,
"failed: %s\n", usb->name, request,
value, index, strerror ( rc ) );
free_iob ( cmplt );
+ usb_endpoint_reset ( ep );
return rc;
}
@@ -912,9 +943,15 @@ int usb_get_string_descriptor ( struct usb_device *usb, unsigned int index,
sizeof ( *desc ) ) ) != 0 )
goto err_get_descriptor;
- /* Copy to buffer */
+ /* Calculate string length */
+ if ( desc->header.len < sizeof ( desc->header ) ) {
+ rc = -EINVAL;
+ goto err_len;
+ }
actual = ( ( desc->header.len - sizeof ( desc->header ) ) /
sizeof ( desc->character[0] ) );
+
+ /* Copy to buffer */
for ( i = 0 ; ( ( i < actual ) && ( i < max ) ) ; i++ )
buf[i] = le16_to_cpu ( desc->character[i] );
if ( len )
@@ -925,6 +962,7 @@ int usb_get_string_descriptor ( struct usb_device *usb, unsigned int index,
return actual;
+ err_len:
err_get_descriptor:
free ( desc );
err_alloc:
@@ -1636,6 +1674,11 @@ static void unregister_usb ( struct usb_device *usb ) {
struct io_buffer *iobuf;
struct io_buffer *tmp;
+ DBGC ( usb, "USB %s addr %d %04x:%04x class %d:%d:%d removed\n",
+ usb->name, usb->address, le16_to_cpu ( usb->device.vendor ),
+ le16_to_cpu ( usb->device.product ), usb->device.class.class,
+ usb->device.class.subclass, usb->device.class.protocol );
+
/* Sanity checks */
assert ( port->usb == usb );
@@ -2235,23 +2278,6 @@ unsigned int usb_route_string ( struct usb_device *usb ) {
}
/**
- * Get USB depth
- *
- * @v usb USB device
- * @ret depth Hub depth
- */
-unsigned int usb_depth ( struct usb_device *usb ) {
- struct usb_device *parent;
- unsigned int depth;
-
- /* Navigate up to root hub, constructing depth as we go */
- for ( depth = 0 ; ( parent = usb->port->hub->usb ) ; usb = parent )
- depth++;
-
- return depth;
-}
-
-/**
* Get USB root hub port
*
* @v usb USB device
diff --git a/src/drivers/bus/virtio-pci.c b/src/drivers/bus/virtio-pci.c
index 402bf4f12..5d2d62750 100644
--- a/src/drivers/bus/virtio-pci.c
+++ b/src/drivers/bus/virtio-pci.c
@@ -321,7 +321,7 @@ int virtio_pci_map_capability(struct pci_device *pci, int cap, size_t minlen,
region->flags = VIRTIO_PCI_REGION_PORT;
} else {
/* Region mapped into memory space */
- region->base = ioremap(base + offset, length);
+ region->base = pci_ioremap(pci, base + offset, length);
region->flags = VIRTIO_PCI_REGION_MEMORY;
}
}
diff --git a/src/drivers/infiniband/MT25218_PRM.h b/src/drivers/infiniband/MT25218_PRM.h
index 4011bd0ba..c4dc3316b 100644
--- a/src/drivers/infiniband/MT25218_PRM.h
+++ b/src/drivers/infiniband/MT25218_PRM.h
@@ -73,7 +73,7 @@ struct arbelprm_ud_address_vector_st { /* Little Endian */
/* -------------- */
pseudo_bit_t rgid_31_0[0x00020]; /* Remote GID[31:0] if G bit is set. Must be set to 0x2 if G bit is cleared. */
/* -------------- */
-};
+};
/* Send doorbell */
@@ -88,7 +88,7 @@ struct arbelprm_send_doorbell_st { /* Little Endian */
pseudo_bit_t reserved1[0x00002];
pseudo_bit_t qpn[0x00018]; /* QP number this doorbell is rung on */
/* -------------- */
-};
+};
/* ACCESS_LAM_inject_errors_input_modifier */
@@ -102,7 +102,7 @@ struct arbelprm_access_lam_inject_errors_input_modifier_st { /* Little Endian */
pseudo_bit_t index0[0x00007];
pseudo_bit_t q0[0x00001];
/* -------------- */
-};
+};
/* ACCESS_LAM_inject_errors_input_parameter */
@@ -114,7 +114,7 @@ struct arbelprm_access_lam_inject_errors_input_parameter_st { /* Little Endian *
pseudo_bit_t ra[0x00010]; /* Row Address */
pseudo_bit_t ca[0x00010]; /* Column Address */
/* -------------- */
-};
+};
/* */
@@ -127,7 +127,7 @@ struct arbelprm_recv_wqe_segment_next_st { /* Little Endian */
*/
pseudo_bit_t reserved1[0x0001a];
/* -------------- */
-};
+};
/* Send wqe segment data inline */
@@ -141,7 +141,7 @@ struct arbelprm_wqe_segment_data_inline_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved2[0x00040];
/* -------------- */
-};
+};
/* Send wqe segment data ptr */
@@ -155,7 +155,7 @@ struct arbelprm_wqe_segment_data_ptr_st { /* Little Endian */
/* -------------- */
pseudo_bit_t local_address_l[0x00020];
/* -------------- */
-};
+};
/* Send wqe segment rd */
@@ -167,7 +167,7 @@ struct arbelprm_local_invalidate_segment_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved2[0x000a0];
/* -------------- */
-};
+};
/* Fast_Registration_Segment */
@@ -197,7 +197,7 @@ struct arbelprm_fast_registration_segment_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reg_len_l[0x00020]; /* Region Length[31:0] */
/* -------------- */
-};
+};
/* Send wqe segment atomic */
@@ -210,7 +210,7 @@ struct arbelprm_wqe_segment_atomic_st { /* Little Endian */
/* -------------- */
pseudo_bit_t compare_l[0x00020];
/* -------------- */
-};
+};
/* Send wqe segment remote address */
@@ -223,7 +223,7 @@ struct arbelprm_wqe_segment_remote_address_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved0[0x00020];
/* -------------- */
-};
+};
/* end wqe segment bind */
@@ -253,7 +253,7 @@ struct arbelprm_wqe_segment_bind_st { /* Little Endian */
/* -------------- */
pseudo_bit_t length_l[0x00020];
/* -------------- */
-};
+};
/* Send wqe segment ud */
@@ -267,7 +267,7 @@ struct arbelprm_wqe_segment_ud_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved1[0x00040];
/* -------------- */
-};
+};
/* Send wqe segment rd */
@@ -279,7 +279,7 @@ struct arbelprm_wqe_segment_rd_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved1[0x00040];
/* -------------- */
-};
+};
/* Send wqe segment ctrl */
@@ -296,7 +296,7 @@ struct arbelprm_wqe_segment_ctrl_send_st { /* Little Endian */
/* -------------- */
pseudo_bit_t immediate[0x00020]; /* If the OpCode encodes an operation with Immediate (RDMA-write/SEND), This field will hold the Immediate data to be sent. If the OpCode encodes send and invalidate operations, this field holds the Invalidation key to be inserted into the packet; otherwise, this field is reserved. */
/* -------------- */
-};
+};
/* Send wqe segment next */
@@ -338,7 +338,7 @@ struct arbelprm_wqe_segment_next_st { /* Little Endian */
pseudo_bit_t always1[0x00001];
pseudo_bit_t reserved1[0x00018];
/* -------------- */
-};
+};
/* Address Path */
@@ -384,7 +384,7 @@ struct arbelprm_address_path_st { /* Little Endian */
/* -------------- */
pseudo_bit_t rgid_31_0[0x00020]; /* Remote GID[31:0] */
/* -------------- */
-};
+};
/* HCA Command Register (HCR) */
@@ -414,7 +414,7 @@ struct arbelprm_hca_command_register_st { /* Little Endian */
pseudo_bit_t status[0x00008]; /* Command execution status report. Valid only if command interface in under SW ownership (Go bit is cleared)
0 - command completed without error. If different than zero, command execution completed with error. Syndrom encoding is depended on command executed and is defined for each command */
/* -------------- */
-};
+};
/* CQ Doorbell */
@@ -435,7 +435,7 @@ struct arbelprm_cq_cmd_doorbell_st { /* Little Endian */
/* -------------- */
pseudo_bit_t cq_param[0x00020]; /* parameter to be used by CQ command */
/* -------------- */
-};
+};
/* RD-send doorbell */
@@ -449,7 +449,7 @@ struct arbelprm_rd_send_doorbell_st { /* Little Endian */
/* -------------- */
struct arbelprm_send_doorbell_st send_doorbell;/* Send Parameters */
/* -------------- */
-};
+};
/* Multicast Group Member QP */
@@ -458,7 +458,7 @@ struct arbelprm_mgmqp_st { /* Little Endian */
pseudo_bit_t reserved0[0x00007];
pseudo_bit_t qi[0x00001]; /* Qi: QPN_i is valid */
/* -------------- */
-};
+};
/* vsd */
@@ -575,7 +575,7 @@ struct arbelprm_vsd_st { /* Little Endian */
/* -------------- */
pseudo_bit_t vsd_dw55[0x00020];
/* -------------- */
-};
+};
/* ACCESS_LAM_inject_errors */
@@ -586,7 +586,7 @@ struct arbelprm_access_lam_inject_errors_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved0[0x00020];
/* -------------- */
-};
+};
/* Logical DIMM Information */
@@ -626,7 +626,7 @@ struct arbelprm_dimminfo_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved4[0x00040];
/* -------------- */
-};
+};
/* UAR Parameters */
@@ -661,7 +661,7 @@ struct arbelprm_uar_params_st { /* Little Endian */
Number of entries in table is 2^log_max_uars.
Table must be aligned to its size. */
/* -------------- */
-};
+};
/* Translation and Protection Tables Parameters */
@@ -695,7 +695,7 @@ struct arbelprm_tptparams_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved3[0x00040];
/* -------------- */
-};
+};
/* Multicast Support Parameters */
@@ -729,7 +729,7 @@ struct arbelprm_multicastparam_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved5[0x00020];
/* -------------- */
-};
+};
/* QPC/EEC/CQC/EQC/RDB Parameters */
@@ -821,7 +821,7 @@ struct arbelprm_qpcbaseaddr_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved10[0x00040];
/* -------------- */
-};
+};
/* Header_Log_Register */
@@ -830,7 +830,7 @@ struct arbelprm_header_log_register_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved0[0x00060];
/* -------------- */
-};
+};
/* Performance Monitors */
@@ -862,7 +862,7 @@ struct arbelprm_performance_monitors_st { /* Little Endian */
/* -------------- */
pseudo_bit_t event_counter2[0x00020];/* Read/write event counter, counting events specified by EvCntl and EvCnt2 fields repsectively. When the event counter reaches is maximum value of 0xFFFFFF, the next event will cause it to roll over to zero, set F1 or F2 bit respectively and generate interrupt by I1 I2 bit respectively. */
/* -------------- */
-};
+};
/* Receive segment format */
@@ -876,7 +876,7 @@ struct arbelprm_wqe_segment_ctrl_recv_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved4[0x00020];
/* -------------- */
-};
+};
/* MLX WQE segment format */
@@ -895,7 +895,7 @@ struct arbelprm_wqe_segment_ctrl_mlx_st { /* Little Endian */
pseudo_bit_t vcrc[0x00010]; /* Packet's VCRC (if not 0 - otherwise computed by HW) */
pseudo_bit_t rlid[0x00010]; /* Destination LID (must match given headers) */
/* -------------- */
-};
+};
/* Send WQE segment format */
@@ -926,7 +926,7 @@ struct arbelprm_send_wqe_segment_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved1[0x00200];
/* -------------- */
-};
+};
/* QP and EE Context Entry */
@@ -1118,7 +1118,7 @@ struct arbelprm_queue_pair_ee_context_entry_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved33[0x00040];
/* -------------- */
-};
+};
/* Clear Interrupt [63:0] */
@@ -1132,7 +1132,7 @@ struct arbelprm_clr_int_st { /* Little Endian */
Write transactions to this register will clear (de-assert) the virtual interrupt output pins of InfiniHost-III-EX. The value to be written in this register is obtained by executing QUERY_ADAPTER command on command interface after system boot.
This register is write-only. Reading from this register will cause undefined result */
/* -------------- */
-};
+};
/* EQ_Arm_DB_Region */
@@ -1143,7 +1143,7 @@ struct arbelprm_eq_arm_db_region_st { /* Little Endian */
pseudo_bit_t eq_x_arm_l[0x00020]; /* EQ[31:0] X state.
This register is used to Arm EQs when setting the appropriate bits. */
/* -------------- */
-};
+};
/* EQ Set CI DBs Table */
@@ -1404,7 +1404,7 @@ struct arbelprm_eq_set_ci_table_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved63[0x00020];
/* -------------- */
-};
+};
/* InfiniHost-III-EX Configuration Registers */
@@ -1415,7 +1415,7 @@ struct arbelprm_configuration_registers_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved1[0x3fcb20];
/* -------------- */
-};
+};
/* QP_DB_Record */
@@ -1429,7 +1429,7 @@ struct arbelprm_qp_db_record_st { /* Little Endian */
0x5 for SRQ */
pseudo_bit_t qp_number[0x00018]; /* QP number */
/* -------------- */
-};
+};
/* CQ_ARM_DB_Record */
@@ -1445,7 +1445,7 @@ struct arbelprm_cq_arm_db_record_st { /* Little Endian */
pseudo_bit_t res[0x00003]; /* Must be 0x2 */
pseudo_bit_t cq_number[0x00018]; /* CQ number */
/* -------------- */
-};
+};
/* CQ_CI_DB_Record */
@@ -1456,7 +1456,7 @@ struct arbelprm_cq_ci_db_record_st { /* Little Endian */
pseudo_bit_t res[0x00003]; /* Must be 0x1 */
pseudo_bit_t cq_number[0x00018]; /* CQ number */
/* -------------- */
-};
+};
/* Virtual_Physical_Mapping */
@@ -1472,7 +1472,7 @@ struct arbelprm_virtual_physical_mapping_st { /* Little Endian */
pseudo_bit_t reserved1[0x00006];
pseudo_bit_t pa_l[0x00014]; /* Physical Address[31:12] */
/* -------------- */
-};
+};
/* MOD_STAT_CFG */
@@ -1485,7 +1485,7 @@ struct arbelprm_mod_stat_cfg_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved2[0x007e0];
/* -------------- */
-};
+};
/* SRQ Context */
@@ -1528,7 +1528,7 @@ struct arbelprm_srq_context_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved4[0x00060];
/* -------------- */
-};
+};
/* PBL */
@@ -1549,7 +1549,7 @@ struct arbelprm_pbl_st { /* Little Endian */
/* -------------- */
pseudo_bit_t mtt_3_l[0x00020]; /* Fourth MTT[31:0] */
/* -------------- */
-};
+};
/* Performance Counters */
@@ -1580,7 +1580,7 @@ struct arbelprm_performance_counters_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved3[0x00620];
/* -------------- */
-};
+};
/* Transport and CI Error Counters */
@@ -1724,7 +1724,7 @@ struct arbelprm_transport_and_ci_error_counters_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved12[0x002a0];
/* -------------- */
-};
+};
/* Event_data Field - HCR Completion Event */
@@ -1743,7 +1743,7 @@ struct arbelprm_hcr_completion_event_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved3[0x00020];
/* -------------- */
-};
+};
/* Completion with Error CQE */
@@ -1791,7 +1791,7 @@ struct arbelprm_completion_with_error_st { /* Little Endian */
0xFE - For completion with error on Receive Queues
0xFF - For completion with error on Send Queues */
/* -------------- */
-};
+};
/* Resize CQ Input Mailbox */
@@ -1814,7 +1814,7 @@ struct arbelprm_resize_cq_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved4[0x00100];
/* -------------- */
-};
+};
/* MAD_IFC Input Modifier */
@@ -1826,7 +1826,7 @@ struct arbelprm_mad_ifc_input_modifier_st { /* Little Endian */
pseudo_bit_t rlid[0x00010]; /* Remote (source) LID from the received MAD.
This field is required for trap generation upon MKey/BKey validation. */
/* -------------- */
-};
+};
/* MAD_IFC Input Mailbox */
@@ -1863,7 +1863,7 @@ struct arbelprm_mad_ifc_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved5[0x004c0];
/* -------------- */
-};
+};
/* Query Debug Message */
@@ -1924,7 +1924,7 @@ struct arbelprm_query_debug_msg_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved3[0x00400];
/* -------------- */
-};
+};
/* User Access Region */
@@ -1939,7 +1939,7 @@ struct arbelprm_uar_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved1[0x03ec0];
/* -------------- */
-};
+};
/* Receive doorbell */
@@ -1953,7 +1953,7 @@ struct arbelprm_receive_doorbell_st { /* Little Endian */
pseudo_bit_t reserved3[0x00002];
pseudo_bit_t qpn[0x00018]; /* QP number or SRQ number this doorbell is rung on */
/* -------------- */
-};
+};
/* SET_IB Parameters */
@@ -1974,7 +1974,7 @@ struct arbelprm_set_ib_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved2[0x00180];
/* -------------- */
-};
+};
/* Multicast Group Member */
@@ -2014,7 +2014,7 @@ struct arbelprm_mgm_entry_st { /* Little Endian */
/* -------------- */
struct arbelprm_mgmqp_st mgmqp_7; /* Multicast Group Member QP */
/* -------------- */
-};
+};
/* INIT_IB Parameters */
@@ -2068,7 +2068,7 @@ struct arbelprm_init_ib_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved5[0x006c0];
/* -------------- */
-};
+};
/* Query Device Limitations */
@@ -2285,7 +2285,7 @@ struct arbelprm_query_dev_lim_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved41[0x002c0];
/* -------------- */
-};
+};
/* QUERY_ADAPTER Parameters Block */
@@ -2299,7 +2299,7 @@ struct arbelprm_query_adapter_st { /* Little Endian */
/* -------------- */
struct arbelprm_vsd_st vsd;
/* -------------- */
-};
+};
/* QUERY_FW Parameters Block */
@@ -2375,7 +2375,7 @@ struct arbelprm_query_fw_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved6[0x004c0];
/* -------------- */
-};
+};
/* ACCESS_LAM */
@@ -2384,7 +2384,7 @@ struct arbelprm_access_lam_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved0[0x00080];
/* -------------- */
-};
+};
/* ENABLE_LAM Parameters Block */
@@ -2418,7 +2418,7 @@ struct arbelprm_enable_lam_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved2[0x00400];
/* -------------- */
-};
+};
/* Memory Access Parameters for UD Address Vector Table */
@@ -2430,7 +2430,7 @@ struct arbelprm_udavtable_memory_parameters_st { /* Little Endian */
pseudo_bit_t xlation_en[0x00001]; /* When cleared, address is physical address and no translation will be done. When set, address is virtual. */
pseudo_bit_t reserved1[0x00002];
/* -------------- */
-};
+};
/* INIT_HCA & QUERY_HCA Parameters Block */
@@ -2495,7 +2495,7 @@ struct arbelprm_init_hca_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved11[0x00600];
/* -------------- */
-};
+};
/* Event Queue Context Table Entry */
@@ -2555,7 +2555,7 @@ struct arbelprm_eqc_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved9[0x00080];
/* -------------- */
-};
+};
/* Memory Translation Table (MTT) Entry */
@@ -2566,7 +2566,7 @@ struct arbelprm_mtt_st { /* Little Endian */
pseudo_bit_t reserved0[0x0000b];
pseudo_bit_t ptag_l[0x00014]; /* Low-order bits of Physical tag. The size of the field depends on the page size of the region. Maximum PTAG size is 52 bits. */
/* -------------- */
-};
+};
/* Memory Protection Table (MPT) Entry */
@@ -2641,7 +2641,7 @@ struct arbelprm_mpt_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved8[0x00040];
/* -------------- */
-};
+};
/* Completion Queue Context Table Entry */
@@ -2719,7 +2719,7 @@ struct arbelprm_completion_queue_context_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved8[0x00020];
/* -------------- */
-};
+};
/* GPIO_event_data */
@@ -2732,7 +2732,7 @@ struct arbelprm_gpio_event_data_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved1[0x00020];
/* -------------- */
-};
+};
/* Event_data Field - QP/EE Events */
@@ -2749,7 +2749,7 @@ struct arbelprm_qp_ee_event_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved4[0x00060];
/* -------------- */
-};
+};
/* InfiniHost-III-EX Type0 Configuration Header */
@@ -2947,7 +2947,7 @@ struct arbelprm_mt25208_type0_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved13[0x006a0];
/* -------------- */
-};
+};
/* Event Data Field - Performance Monitor */
@@ -2965,7 +2965,7 @@ struct arbelprm_performance_monitor_event_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved1[0x00040];
/* -------------- */
-};
+};
/* Event_data Field - Page Faults */
@@ -2989,7 +2989,7 @@ struct arbelprm_page_fault_event_data_st { /* Little Endian */
/* -------------- */
pseudo_bit_t prefetch_len[0x00020]; /* Indicates how many subsequent pages in the same memory region/window will be accessed by the following transaction after this page fault is resolved. measured in bytes. SW can use this information in order to page-in the subsequent pages if they are not present. */
/* -------------- */
-};
+};
/* WQE segments format */
@@ -3006,7 +3006,7 @@ struct arbelprm_wqe_segment_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved2[0x00080];
/* -------------- */
-};
+};
/* Event_data Field - Port State Change */
@@ -3019,7 +3019,7 @@ struct arbelprm_port_state_change_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved3[0x00060];
/* -------------- */
-};
+};
/* Event_data Field - Completion Queue Error */
@@ -3036,7 +3036,7 @@ struct arbelprm_completion_queue_error_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved3[0x00060];
/* -------------- */
-};
+};
/* Event_data Field - Completion Event */
@@ -3046,7 +3046,7 @@ struct arbelprm_completion_event_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved1[0x000a0];
/* -------------- */
-};
+};
/* Event Queue Entry */
@@ -3065,7 +3065,7 @@ struct arbelprm_event_queue_entry_st { /* Little Endian */
1 HW */
pseudo_bit_t reserved3[0x00018];
/* -------------- */
-};
+};
/* QP/EE State Transitions Command Parameters */
@@ -3078,7 +3078,7 @@ struct arbelprm_qp_ee_state_transitions_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved1[0x009c0];
/* -------------- */
-};
+};
/* Completion Queue Entry Format */
@@ -3131,7 +3131,7 @@ struct arbelprm_completion_queue_entry_st { /* Little Endian */
0xFE - For completion with error on Receive Queues
0xFF - For completion with error on Send Queues */
/* -------------- */
-};
+};
/* */
@@ -3152,7 +3152,7 @@ struct arbelprm_ecc_detect_event_data_st { /* Little Endian */
pseudo_bit_t err_ra[0x00010];
pseudo_bit_t err_ca[0x00010];
/* -------------- */
-};
+};
/* Event_data Field - ECC Detection Event */
@@ -3177,7 +3177,7 @@ struct arbelprm_scrubbing_event_st { /* Little Endian */
pseudo_bit_t err_ra[0x00010]; /* Error row address */
pseudo_bit_t err_ca[0x00010]; /* Error column address */
/* -------------- */
-};
+};
/* Miscellaneous Counters */
@@ -3186,28 +3186,28 @@ struct arbelprm_misc_counters_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved0[0x007e0];
/* -------------- */
-};
+};
/* LAM_EN Output Parameter */
struct arbelprm_lam_en_out_param_st { /* Little Endian */
pseudo_bit_t reserved0[0x00040];
/* -------------- */
-};
+};
/* Extended_Completion_Queue_Entry */
struct arbelprm_extended_completion_queue_entry_st { /* Little Endian */
pseudo_bit_t reserved0[0x00020];
/* -------------- */
-};
+};
/* */
struct arbelprm_eq_cmd_doorbell_st { /* Little Endian */
pseudo_bit_t reserved0[0x00020];
/* -------------- */
-};
+};
/* 0 */
@@ -3456,5 +3456,5 @@ struct arbelprm_arbel_prm_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved59[0xffcfc0];
/* -------------- */
-};
+};
#endif /* H_prefix_arbelprm_bits_fixnames_MT25218_PRM_csp_H */
diff --git a/src/drivers/infiniband/MT25408_PRM.h b/src/drivers/infiniband/MT25408_PRM.h
index cc248daf9..f8c19ce72 100644
--- a/src/drivers/infiniband/MT25408_PRM.h
+++ b/src/drivers/infiniband/MT25408_PRM.h
@@ -47,7 +47,7 @@ struct hermonprm_ud_address_vector_st { /* Little Endian */
pseudo_bit_t reserved1[0x00008];
/* -------------- */
pseudo_bit_t hop_limit[0x00008]; /* IPv6 hop limit */
- pseudo_bit_t max_stat_rate[0x00004];/* Maximum static rate control.
+ pseudo_bit_t max_stat_rate[0x00004];/* Maximum static rate control.
0 - 4X injection rate
1 - 1X injection rate
other - reserved
@@ -72,7 +72,7 @@ struct hermonprm_ud_address_vector_st { /* Little Endian */
/* -------------- */
pseudo_bit_t rgid_31_0[0x00020]; /* Remote GID[31:0] if G bit is set. Must be set to 0x2 if G bit is cleared. */
/* -------------- */
-};
+};
/* Send doorbell */
@@ -87,7 +87,7 @@ struct hermonprm_send_doorbell_st { /* Little Endian */
pseudo_bit_t reserved1[0x00002];
pseudo_bit_t qpn[0x00018]; /* QP number this doorbell is rung on */
/* -------------- */
-};
+};
/* Send wqe segment data inline */
@@ -101,7 +101,7 @@ struct hermonprm_wqe_segment_data_inline_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved2[0x00040];
/* -------------- */
-};
+};
/* Send wqe segment data ptr */
@@ -115,7 +115,7 @@ struct hermonprm_wqe_segment_data_ptr_st { /* Little Endian */
/* -------------- */
pseudo_bit_t local_address_l[0x00020];
/* -------------- */
-};
+};
/* Send wqe segment rd */
@@ -127,7 +127,7 @@ struct hermonprm_local_invalidate_segment_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved2[0x000a0];
/* -------------- */
-};
+};
/* Fast_Registration_Segment ####michal - doesn't match PRM (fields were added, see below) new table size in bytes - 0x30 */
@@ -157,7 +157,7 @@ struct hermonprm_fast_registration_segment_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reg_len_l[0x00020]; /* Region Length[31:0] */
/* -------------- */
-};
+};
/* Send wqe segment atomic */
@@ -170,7 +170,7 @@ struct hermonprm_wqe_segment_atomic_st { /* Little Endian */
/* -------------- */
pseudo_bit_t compare_l[0x00020];
/* -------------- */
-};
+};
/* Send wqe segment remote address */
@@ -183,7 +183,7 @@ struct hermonprm_wqe_segment_remote_address_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved0[0x00020];
/* -------------- */
-};
+};
/* end wqe segment bind */
@@ -213,7 +213,7 @@ struct hermonprm_wqe_segment_bind_st { /* Little Endian */
/* -------------- */
pseudo_bit_t length_l[0x00020];
/* -------------- */
-};
+};
/* Send wqe segment ud */
@@ -227,7 +227,7 @@ struct hermonprm_wqe_segment_ud_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved1[0x00040];
/* -------------- */
-};
+};
/* Send wqe segment rd */
@@ -239,7 +239,7 @@ struct hermonprm_wqe_segment_rd_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved1[0x00040];
/* -------------- */
-};
+};
/* Send wqe segment ctrl */
@@ -263,7 +263,7 @@ struct hermonprm_wqe_segment_ctrl_send_st { /* Little Endian */
/* -------------- */
pseudo_bit_t immediate[0x00020]; /* If the OpCode encodes an operation with Immediate (RDMA-write/SEND), This field will hold the Immediate data to be sent. If the OpCode encodes send and invalidate operations, this field holds the Invalidation key to be inserted into the packet; otherwise, this field is reserved. */
/* -------------- */
-};
+};
/* Address Path # ###michal - match to PRM */
@@ -280,19 +280,19 @@ struct hermonprm_address_path_st { /* Little Endian */
pseudo_bit_t reserved1[0x00008];
/* -------------- */
pseudo_bit_t hop_limit[0x00008]; /* IPv6 hop limit */
- pseudo_bit_t max_stat_rate[0x00004];/* Maximum static rate control.
- 0 - 100% injection rate
+ pseudo_bit_t max_stat_rate[0x00004];/* Maximum static rate control.
+ 0 - 100% injection rate
1 - 25% injection rate
2 - 12.5% injection rate
3 - 50% injection rate
- 7: 2.5 Gb/s.
- 8: 10 Gb/s.
- 9: 30 Gb/s.
- 10: 5 Gb/s.
+ 7: 2.5 Gb/s.
+ 8: 10 Gb/s.
+ 9: 30 Gb/s.
+ 10: 5 Gb/s.
11: 20 Gb/s.
- 12: 40 Gb/s.
- 13: 60 Gb/s.
- 14: 80 Gb/s.
+ 12: 40 Gb/s.
+ 13: 60 Gb/s.
+ 14: 80 Gb/s.
15: 120 Gb/s. */
pseudo_bit_t reserved2[0x00004];
pseudo_bit_t mgid_index[0x00007]; /* Index to port GID table */
@@ -328,7 +328,7 @@ struct hermonprm_address_path_st { /* Little Endian */
/* -------------- */
pseudo_bit_t dmac_31_0[0x00020];
/* -------------- */
-};
+};
/* HCA Command Register (HCR) #### michal - match PRM */
@@ -359,7 +359,7 @@ struct hermonprm_hca_command_register_st { /* Little Endian */
pseudo_bit_t status[0x00008]; /* Command execution status report. Valid only if command interface in under SW ownership (Go bit is cleared)
0 - command completed without error. If different than zero, command execution completed with error. Syndrom encoding is depended on command executed and is defined for each command */
/* -------------- */
-};
+};
/* CQ Doorbell */
@@ -373,14 +373,14 @@ struct hermonprm_cq_cmd_doorbell_st { /* Little Endian */
Other - Reserved */
pseudo_bit_t reserved0[0x00001];
pseudo_bit_t cmd_sn[0x00002]; /* Command Sequence Number - This field should be incremented upon receiving completion notification of the respective CQ.
- This transition is done by ringing Request notification for next Solicited, Request notification for next Solicited or Unsolicited
+ This transition is done by ringing Request notification for next Solicited, Request notification for next Solicited or Unsolicited
completion or Request notification for multiple completions doorbells after receiving completion notification.
This field is initialized to Zero */
pseudo_bit_t reserved1[0x00002];
/* -------------- */
pseudo_bit_t cq_param[0x00020]; /* parameter to be used by CQ command */
/* -------------- */
-};
+};
/* RD-send doorbell */
@@ -394,7 +394,7 @@ struct hermonprm_rd_send_doorbell_st { /* Little Endian */
/* -------------- */
struct hermonprm_send_doorbell_st send_doorbell;/* Send Parameters */
/* -------------- */
-};
+};
/* Multicast Group Member QP #### michal - match PRM */
@@ -404,7 +404,7 @@ struct hermonprm_mgmqp_st { /* Little Endian */
pseudo_bit_t blck_lb[0x00001]; /* Block self-loopback messages arriving to this qp */
pseudo_bit_t qi[0x00001]; /* Qi: QPN_i is valid */
/* -------------- */
-};
+};
/* vsd */
@@ -521,7 +521,7 @@ struct hermonprm_vsd_st { /* Little Endian */
/* -------------- */
pseudo_bit_t vsd_dw55[0x00020];
/* -------------- */
-};
+};
/* UAR Parameters */
@@ -535,7 +535,7 @@ struct hermonprm_uar_params_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved2[0x000a0];
/* -------------- */
-};
+};
/* Translation and Protection Tables Parameters */
@@ -552,7 +552,7 @@ struct hermonprm_tptparams_st { /* Little Endian */
/* -------------- */
pseudo_bit_t log_dmpt_sz[0x00006]; /* Log (base 2) of the number of region/windows entries in the dMPT table. */
pseudo_bit_t reserved0[0x00002];
- pseudo_bit_t pfto[0x00005]; /* Page Fault RNR Timeout -
+ pseudo_bit_t pfto[0x00005]; /* Page Fault RNR Timeout -
The field returned in RNR Naks generated when a page fault is detected.
It has no effect when on-demand-paging is not used. */
pseudo_bit_t reserved1[0x00013];
@@ -575,7 +575,7 @@ struct hermonprm_tptparams_st { /* Little Endian */
Entry size is 64 bytes.
Table must be aligned to its size. */
/* -------------- */
-};
+};
/* Multicast Support Parameters #### michal - match PRM */
@@ -584,14 +584,14 @@ struct hermonprm_multicastparam_st { /* Little Endian */
The base address must be aligned to the entry size.
Address may be set to 0xFFFFFFFF if multicast is not supported. */
/* -------------- */
- pseudo_bit_t mc_base_addr_l[0x00020];/* Base Address of the Multicast Table [31:0].
+ pseudo_bit_t mc_base_addr_l[0x00020];/* Base Address of the Multicast Table [31:0].
The base address must be aligned to the entry size.
Address may be set to 0xFFFFFFFF if multicast is not supported. */
/* -------------- */
pseudo_bit_t reserved0[0x00040];
/* -------------- */
pseudo_bit_t log_mc_table_entry_sz[0x00005];/* Log2 of the Size of multicast group member (MGM) entry.
- Must be greater than 5 (to allow CTRL and GID sections).
+ Must be greater than 5 (to allow CTRL and GID sections).
That implies the number of QPs per MC table entry. */
pseudo_bit_t reserved1[0x0000b];
pseudo_bit_t reserved2[0x00010];
@@ -611,7 +611,7 @@ struct hermonprm_multicastparam_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved6[0x00020];
/* -------------- */
-};
+};
/* QPC/EEC/CQC/EQC/RDB Parameters #### michal - doesn't match PRM (field name are differs. see below) */
@@ -679,12 +679,12 @@ struct hermonprm_qpcbaseaddr_st { /* Little Endian */
/* -------------- */
pseudo_bit_t log_num_rd[0x00003]; /* Log (base 2) of the maximum number of RdmaRdC entries per QP. This denotes the maximum number of outstanding reads/atomics as a responder. */
pseudo_bit_t reserved7[0x00002];
- pseudo_bit_t rdmardc_base_addr_l[0x0001b];/* rdmardc_base_addr_l: Base address of table that holds remote read and remote atomic requests [31:0].
+ pseudo_bit_t rdmardc_base_addr_l[0x0001b];/* rdmardc_base_addr_l: Base address of table that holds remote read and remote atomic requests [31:0].
Table must be aligned to RDB entry size (32 bytes). */
/* -------------- */
pseudo_bit_t reserved8[0x00040];
/* -------------- */
-};
+};
/* Header_Log_Register */
@@ -693,7 +693,7 @@ struct hermonprm_header_log_register_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved0[0x00060];
/* -------------- */
-};
+};
/* Performance Monitors */
@@ -725,7 +725,7 @@ struct hermonprm_performance_monitors_st { /* Little Endian */
/* -------------- */
pseudo_bit_t event_counter2[0x00020];/* Read/write event counter, counting events specified by EvCntl and EvCnt2 fields repsectively. When the event counter reaches is maximum value of 0xFFFFFF, the next event will cause it to roll over to zero, set F1 or F2 bit respectively and generate interrupt by I1 I2 bit respectively. */
/* -------------- */
-};
+};
/* MLX WQE segment format */
@@ -751,7 +751,7 @@ struct hermonprm_wqe_segment_ctrl_mlx_st { /* Little Endian */
pseudo_bit_t reserved5[0x00010];
pseudo_bit_t rlid[0x00010]; /* Destination LID (must match given headers) */
/* -------------- */
-};
+};
/* Send WQE segment format */
@@ -780,7 +780,7 @@ struct hermonprm_send_wqe_segment_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved1[0x00200];
/* -------------- */
-};
+};
/* QP and EE Context Entry */
@@ -833,7 +833,7 @@ struct hermonprm_queue_pair_ee_context_entry_st { /* Little Endian */
0x3 - 1024
0x4 - 2048
other - reserved
-
+
Should be configured to 0x4 for UD and MLX QPs. */
/* -------------- */
pseudo_bit_t usr_page[0x00018]; /* UAR number to ring doorbells for this QP (aliased to doorbell and Blue Flame pages) */
@@ -883,7 +883,7 @@ struct hermonprm_queue_pair_ee_context_entry_st { /* Little Endian */
pseudo_bit_t reserved24[0x00008];
/* -------------- */
pseudo_bit_t reserved25[0x00004];
- pseudo_bit_t ric[0x00001]; /* Invalid Credits.
+ pseudo_bit_t ric[0x00001]; /* Invalid Credits.
1 - place "Invalid Credits" to ACKs sent from this queue.
0 - ACKs report the actual number of end to end credits on the connection.
Not valid (reserved) in EE context.
@@ -895,12 +895,12 @@ struct hermonprm_queue_pair_ee_context_entry_st { /* Little Endian */
pseudo_bit_t rwe[0x00001]; /* If set - RDMA - write enabled on receive queue. Not valid (reserved) in EE context. */
pseudo_bit_t rre[0x00001]; /* If set - RDMA - read enabled on receive queue. Not valid (reserved) in EE context. */
pseudo_bit_t reserved28[0x00005];
- pseudo_bit_t rra_max[0x00003]; /* Maximum number of outstanding RDMA-read/Atomic operations allowed on receive queue is 2^RRA_Max.
+ pseudo_bit_t rra_max[0x00003]; /* Maximum number of outstanding RDMA-read/Atomic operations allowed on receive queue is 2^RRA_Max.
Must be 0 for EE context. */
pseudo_bit_t physical_function[0x00008];
/* -------------- */
pseudo_bit_t next_rcv_psn[0x00018]; /* Next (expected) PSN on receive */
- pseudo_bit_t min_rnr_nak[0x00005]; /* Minimum RNR NAK timer value (TTTTT field encoding according to the IB spec Vol1 9.7.5.2.8).
+ pseudo_bit_t min_rnr_nak[0x00005]; /* Minimum RNR NAK timer value (TTTTT field encoding according to the IB spec Vol1 9.7.5.2.8).
Not valid (reserved) in EE context. */
pseudo_bit_t reserved30[0x00003];
/* -------------- */
@@ -919,7 +919,7 @@ struct hermonprm_queue_pair_ee_context_entry_st { /* Little Endian */
On send datagrams, if Q_Key[31] specified in the WQE is set, then this Q_Key will be transmitted in the outgoing message.
Not valid (reserved) in EE context. */
/* -------------- */
- pseudo_bit_t srqn[0x00018]; /* SRQN - Shared Receive Queue Number - specifies the SRQ number from which the QP dequeues receive descriptors.
+ pseudo_bit_t srqn[0x00018]; /* SRQN - Shared Receive Queue Number - specifies the SRQ number from which the QP dequeues receive descriptors.
SRQN is valid only if SRQ bit is set. Not valid (reserved) in EE context. */
pseudo_bit_t srq[0x00001]; /* SRQ - Shared Receive Queue. If this bit is set, then the QP is associated with a SRQ. Not valid (reserved) in EE context. */
pseudo_bit_t reserved34[0x00007];
@@ -983,7 +983,7 @@ struct hermonprm_queue_pair_ee_context_entry_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved48[0x000c0];
/* -------------- */
-};
+};
/* */
@@ -993,21 +993,21 @@ struct hermonprm_mcg_qp_dw_st { /* Little Endian */
pseudo_bit_t blck_lb[0x00001];
pseudo_bit_t reserved1[0x00001];
/* -------------- */
-};
+};
/* Clear Interrupt [63:0] #### michal - match to PRM */
struct hermonprm_clr_int_st { /* Little Endian */
pseudo_bit_t clr_int_h[0x00020]; /* Clear Interrupt [63:32]
- Write transactions to this register will clear (de-assert) the virtual interrupt output pins of InfiniHost-III-EX. The value to be written in this register is obtained by executing QUERY_ADAPTER command on command interface after system boot.
+ Write transactions to this register will clear (de-assert) the virtual interrupt output pins of InfiniHost-III-EX. The value to be written in this register is obtained by executing QUERY_ADAPTER command on command interface after system boot.
This register is write-only. Reading from this register will cause undefined result
*/
/* -------------- */
pseudo_bit_t clr_int_l[0x00020]; /* Clear Interrupt [31:0]
- Write transactions to this register will clear (de-assert) the virtual interrupt output pins of InfiniHost-III-EX. The value to be written in this register is obtained by executing QUERY_ADAPTER command on command interface after system boot.
+ Write transactions to this register will clear (de-assert) the virtual interrupt output pins of InfiniHost-III-EX. The value to be written in this register is obtained by executing QUERY_ADAPTER command on command interface after system boot.
This register is write-only. Reading from this register will cause undefined result */
/* -------------- */
-};
+};
/* EQ Set CI DBs Table */
@@ -1268,7 +1268,7 @@ struct hermonprm_eq_set_ci_table_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved63[0x00020];
/* -------------- */
-};
+};
/* InfiniHost-III-EX Configuration Registers #### michal - match to PRM */
@@ -1279,7 +1279,7 @@ struct hermonprm_configuration_registers_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved1[0x3fcb20];
/* -------------- */
-};
+};
/* QP_DB_Record ### michal = gdror fixed */
@@ -1287,7 +1287,7 @@ struct hermonprm_qp_db_record_st { /* Little Endian */
pseudo_bit_t receive_wqe_counter[0x00010];/* Modulo-64K counter of WQEs posted to the QP since its creation. Should be initialized to zero. */
pseudo_bit_t reserved0[0x00010];
/* -------------- */
-};
+};
/* CQ_ARM_DB_Record */
@@ -1303,7 +1303,7 @@ struct hermonprm_cq_arm_db_record_st { /* Little Endian */
pseudo_bit_t res[0x00003]; /* Must be 0x2 */
pseudo_bit_t cq_number[0x00018]; /* CQ number */
/* -------------- */
-};
+};
/* CQ_CI_DB_Record */
@@ -1314,7 +1314,7 @@ struct hermonprm_cq_ci_db_record_st { /* Little Endian */
pseudo_bit_t res[0x00003]; /* Must be 0x1 */
pseudo_bit_t cq_number[0x00018]; /* CQ number */
/* -------------- */
-};
+};
/* Virtual_Physical_Mapping */
@@ -1330,7 +1330,7 @@ struct hermonprm_virtual_physical_mapping_st { /* Little Endian */
pseudo_bit_t reserved1[0x00006];
pseudo_bit_t pa_l[0x00014]; /* Physical Address[31:12] */
/* -------------- */
-};
+};
/* MOD_STAT_CFG #### michal - gdror fix */
@@ -1518,7 +1518,7 @@ struct hermonprm_srq_context_st { /* Little Endian */
pseudo_bit_t reserved10[0x00002];
pseudo_bit_t db_record_addr_l[0x0001e];/* SRQ DB Record physical address [31:2] */
/* -------------- */
-};
+};
/* PBL */
@@ -1539,7 +1539,7 @@ struct hermonprm_pbl_st { /* Little Endian */
/* -------------- */
pseudo_bit_t mtt_3_l[0x00020]; /* Fourth MTT[31:0] */
/* -------------- */
-};
+};
/* Performance Counters #### michal - gdror fixed */
@@ -1554,7 +1554,7 @@ struct hermonprm_performance_counters_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved4[0x00620];
/* -------------- */
-};
+};
/* Transport and CI Error Counters */
@@ -1575,10 +1575,10 @@ struct hermonprm_transport_and_ci_error_counters_st { /* Little Endian */
/* -------------- */
pseudo_bit_t sq_num_lpe[0x00020]; /* Requester - number of local protection errors */
/* -------------- */
- pseudo_bit_t rq_num_wrfe[0x00020]; /* Responder - number of CQEs with error.
+ pseudo_bit_t rq_num_wrfe[0x00020]; /* Responder - number of CQEs with error.
Incremented each time a CQE with error is generated */
/* -------------- */
- pseudo_bit_t sq_num_wrfe[0x00020]; /* Requester - number of CQEs with error.
+ pseudo_bit_t sq_num_wrfe[0x00020]; /* Requester - number of CQEs with error.
Incremented each time a CQE with error is generated */
/* -------------- */
pseudo_bit_t reserved0[0x00020];
@@ -1698,7 +1698,7 @@ struct hermonprm_transport_and_ci_error_counters_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved12[0x002a0];
/* -------------- */
-};
+};
/* Event_data Field - HCR Completion Event #### michal - match PRM */
@@ -1717,7 +1717,7 @@ struct hermonprm_hcr_completion_event_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved3[0x00020];
/* -------------- */
-};
+};
/* Completion with Error CQE #### michal - gdror fixed */
@@ -1732,7 +1732,7 @@ struct hermonprm_completion_with_error_st { /* Little Endian */
0x02 - Local QP Operation Error
0x03 - Local EE Context Operation Error
0x04 - Local Protection Error
- 0x05 - Work Request Flushed Error
+ 0x05 - Work Request Flushed Error
0x06 - Memory Window Bind Error
0x10 - Bad Response Error
0x11 - Local Access Error
@@ -1752,7 +1752,7 @@ struct hermonprm_completion_with_error_st { /* Little Endian */
pseudo_bit_t wqe_counter[0x00010];
/* -------------- */
pseudo_bit_t opcode[0x00005]; /* The opcode of WQE completion is reported for.
-
+
The following values are reported in case of completion with error:
0xFE - For completion with error on Receive Queues
0xFF - For completion with error on Send Queues */
@@ -1761,7 +1761,7 @@ struct hermonprm_completion_with_error_st { /* Little Endian */
pseudo_bit_t owner[0x00001]; /* HW Flips this bit for every CQ warp around. Initialized to Zero. */
pseudo_bit_t reserved3[0x00018];
/* -------------- */
-};
+};
/* Resize CQ Input Mailbox */
@@ -1790,7 +1790,7 @@ struct hermonprm_resize_cq_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved10[0x00100];
/* -------------- */
-};
+};
/* MAD_IFC Input Modifier */
@@ -1802,14 +1802,14 @@ struct hermonprm_mad_ifc_input_modifier_st { /* Little Endian */
pseudo_bit_t rlid[0x00010]; /* Remote (source) LID from the received MAD.
This field is required for trap generation upon MKey/BKey validation. */
/* -------------- */
-};
+};
/* MAD_IFC Input Mailbox ###michal -gdror fixed */
struct hermonprm_mad_ifc_st { /* Little Endian */
pseudo_bit_t request_mad_packet[64][0x00020];/* Request MAD Packet (256bytes) */
/* -------------- */
- pseudo_bit_t my_qpn[0x00018]; /* Destination QP number from the received MAD.
+ pseudo_bit_t my_qpn[0x00018]; /* Destination QP number from the received MAD.
This field is reserved if Mad_extended_info indication in the input modifier is clear. */
pseudo_bit_t reserved0[0x00008];
/* -------------- */
@@ -1822,25 +1822,25 @@ struct hermonprm_mad_ifc_st { /* Little Endian */
pseudo_bit_t reserved3[0x00010];
pseudo_bit_t ml_path[0x00007]; /* My (destination) LID path bits from the received MAD.
This field is reserved if Mad_extended_info indication in the input modifier is clear. */
- pseudo_bit_t g[0x00001]; /* If set, the GRH field in valid.
+ pseudo_bit_t g[0x00001]; /* If set, the GRH field in valid.
This field is reserved if Mad_extended_info indication in the input modifier is clear. */
pseudo_bit_t reserved4[0x00004];
pseudo_bit_t sl[0x00004]; /* Service Level of the received MAD.
This field is reserved if Mad_extended_info indication in the input modifier is clear. */
/* -------------- */
- pseudo_bit_t pkey_indx[0x00010]; /* Index in PKey table that matches PKey of the received MAD.
+ pseudo_bit_t pkey_indx[0x00010]; /* Index in PKey table that matches PKey of the received MAD.
This field is reserved if Mad_extended_info indication in the input modifier is clear. */
pseudo_bit_t reserved5[0x00010];
/* -------------- */
pseudo_bit_t reserved6[0x00160];
/* -------------- */
- pseudo_bit_t grh[10][0x00020]; /* The GRH field of the MAD packet that was scattered to the first 40 bytes pointed to by the scatter list.
- Valid if Mad_extended_info bit (in the input modifier) and g bit are set.
+ pseudo_bit_t grh[10][0x00020]; /* The GRH field of the MAD packet that was scattered to the first 40 bytes pointed to by the scatter list.
+ Valid if Mad_extended_info bit (in the input modifier) and g bit are set.
Otherwise this field is reserved. */
/* -------------- */
pseudo_bit_t reserved7[0x004c0];
/* -------------- */
-};
+};
/* Query Debug Message #### michal - gdror fixed */
@@ -1899,7 +1899,7 @@ struct hermonprm_query_debug_msg_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved4[0x003c0];
/* -------------- */
-};
+};
/* User Access Region */
@@ -1914,7 +1914,7 @@ struct hermonprm_uar_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved1[0x03ec0];
/* -------------- */
-};
+};
/* Receive doorbell */
@@ -1928,7 +1928,7 @@ struct hermonprm_receive_doorbell_st { /* Little Endian */
pseudo_bit_t reserved3[0x00002];
pseudo_bit_t qpn[0x00018]; /* QP number or SRQ number this doorbell is rung on */
/* -------------- */
-};
+};
/* SET_IB Parameters */
@@ -1949,7 +1949,7 @@ struct hermonprm_set_ib_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved2[0x00180];
/* -------------- */
-};
+};
/* Multicast Group Member #### michal - gdror fixed */
@@ -1989,7 +1989,7 @@ struct hermonprm_mgm_entry_st { /* Little Endian */
/* -------------- */
struct hermonprm_mgmqp_st mgmqp_7; /* Multicast Group Member QP */
/* -------------- */
-};
+};
/* INIT_PORT Parameters #### michal - match PRM */
@@ -2041,7 +2041,7 @@ struct hermonprm_init_port_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved5[0x006c0];
/* -------------- */
-};
+};
/* Query Device Capablities #### michal - gdror fixed */
@@ -2267,7 +2267,7 @@ struct hermonprm_query_dev_cap_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved46[0x002c0];
/* -------------- */
-};
+};
/* QUERY_ADAPTER Parameters Block #### michal - gdror fixed */
@@ -2281,7 +2281,7 @@ struct hermonprm_query_adapter_st { /* Little Endian */
/* -------------- */
struct hermonprm_vsd_st vsd; /* ###michal- this field was replaced by 2 fields : vsd .1664; vsd(continued/psid .128; */
/* -------------- */
-};
+};
/* QUERY_FW Parameters Block #### michal - doesn't match PRM */
@@ -2298,7 +2298,7 @@ struct hermonprm_query_fw_st { /* Little Endian */
pseudo_bit_t log_max_outstanding_cmd[0x00008];/* Log2 of the maximum number of commands the HCR can support simultaneously */
pseudo_bit_t reserved1[0x00017];
pseudo_bit_t dt[0x00001]; /* Debug Trace Support
- 0 - Debug trace is not supported
+ 0 - Debug trace is not supported
1 - Debug trace is supported */
/* -------------- */
pseudo_bit_t reserved2[0x00001];
@@ -2346,7 +2346,7 @@ struct hermonprm_query_fw_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved8[0x00600];
/* -------------- */
-};
+};
/* Memory Access Parameters for UD Address Vector Table */
@@ -2358,7 +2358,7 @@ struct hermonprm_udavtable_memory_parameters_st { /* Little Endian */
pseudo_bit_t xlation_en[0x00001]; /* When cleared, address is physical address and no translation will be done. When set, address is virtual. */
pseudo_bit_t reserved1[0x00002];
/* -------------- */
-};
+};
/* INIT_HCA & QUERY_HCA Parameters Block ####michal-doesn't match PRM (see differs below) new size in bytes:0x300 */
@@ -2407,7 +2407,7 @@ struct hermonprm_init_hca_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved10[0x00600];
/* -------------- */
-};
+};
/* Event Queue Context Table Entry #### michal - gdror fixed */
@@ -2454,19 +2454,19 @@ struct hermonprm_eqc_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved12[0x00040];
/* -------------- */
- pseudo_bit_t consumer_counter[0x00018];/* Consumer counter. The counter is incremented for each EQE polled from the EQ.
- Must be 0x0 in EQ initialization.
+ pseudo_bit_t consumer_counter[0x00018];/* Consumer counter. The counter is incremented for each EQE polled from the EQ.
+ Must be 0x0 in EQ initialization.
Maintained by HW (valid for the QUERY_EQ command only). */
pseudo_bit_t reserved13[0x00008];
/* -------------- */
- pseudo_bit_t producer_counter[0x00018];/* Producer Coutner. The counter is incremented for each EQE that is written by the HW to the EQ.
+ pseudo_bit_t producer_counter[0x00018];/* Producer Coutner. The counter is incremented for each EQE that is written by the HW to the EQ.
EQ overrun is reported if Producer_counter + 1 equals to Consumer_counter and a EQE needs to be added.
Maintained by HW (valid for the QUERY_EQ command only) */
pseudo_bit_t reserved14[0x00008];
/* -------------- */
pseudo_bit_t reserved15[0x00080];
/* -------------- */
-};
+};
/* Memory Translation Table (MTT) Entry #### michal - match to PRM */
@@ -2477,7 +2477,7 @@ struct hermonprm_mtt_st { /* Little Endian */
pseudo_bit_t reserved0[0x00002];
pseudo_bit_t ptag_l[0x0001d]; /* Low-order bits of Physical tag. The size of the field depends on the page size of the region. Maximum PTAG size is 52 bits. */
/* -------------- */
-};
+};
/* Memory Protection Table (MPT) Entry ### doesn't match PRM (new fields were added). new size in bytes : 0x54 */
@@ -2547,7 +2547,7 @@ struct hermonprm_mpt_st { /* Little Endian */
pseudo_bit_t mtt_fbo[0x00015]; /* First byte offset in the zero-based region - the first byte within the first block/page start address refers to. When mtt_rep is being used, fbo points within the replicated block (i.e. block-size x 2^mtt_rep) */
pseudo_bit_t reserved10[0x0000b];
/* -------------- */
-};
+};
/* Completion Queue Context Table Entry #### michal - match PRM */
@@ -2559,7 +2559,7 @@ struct hermonprm_completion_queue_context_st { /* Little Endian */
0x6 - ARMED SOLICITED (Request Solicited Notification)
0xA - FIRED
other - reserved
-
+
Must be 0x0 in CQ initialization.
Valid for the QUERY_CQ and HW2SW_CQ commands only. */
pseudo_bit_t reserved1[0x00005];
@@ -2605,7 +2605,7 @@ struct hermonprm_completion_queue_context_st { /* Little Endian */
pseudo_bit_t reserved11[0x00008];
/* -------------- */
pseudo_bit_t solicit_producer_indx[0x00018];/* Maintained by HW.
- Valid for QUERY_CQ and HW2SW_CQ commands only.
+ Valid for QUERY_CQ and HW2SW_CQ commands only.
*/
pseudo_bit_t reserved12[0x00008];
/* -------------- */
@@ -2627,7 +2627,7 @@ struct hermonprm_completion_queue_context_st { /* Little Endian */
pseudo_bit_t reserved17[0x00003];
pseudo_bit_t db_record_addr_l[0x0001d];/* CQ DB Record physical address [31:3] */
/* -------------- */
-};
+};
/* GPIO_event_data #### michal - gdror fixed */
@@ -2640,7 +2640,7 @@ struct hermonprm_gpio_event_data_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved1[0x00020];
/* -------------- */
-};
+};
/* Event_data Field - QP/EE Events #### michal - doesn't match PRM */
@@ -2657,7 +2657,7 @@ struct hermonprm_qp_ee_event_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved4[0x00060];
/* -------------- */
-};
+};
/* InfiniHost-III-EX Type0 Configuration Header ####michal - doesn't match PRM (new fields added, see below) */
@@ -2803,19 +2803,19 @@ struct hermonprm_mt25208_type0_st { /* Little Endian */
/* -------------- */
pseudo_bit_t uncorrectable_error_status_register[0x00020];/* 0 Training Error Status
4 Data Link Protocol Error Status
- 12 Poisoned TLP Status
- 13 Flow Control Protocol Error Status
- 14 Completion Timeout Status
- 15 Completer Abort Status
- 16 Unexpected Completion Status
- 17 Receiver Overflow Status
- 18 Malformed TLP Status
- 19 ECRC Error Status
+ 12 Poisoned TLP Status
+ 13 Flow Control Protocol Error Status
+ 14 Completion Timeout Status
+ 15 Completer Abort Status
+ 16 Unexpected Completion Status
+ 17 Receiver Overflow Status
+ 18 Malformed TLP Status
+ 19 ECRC Error Status
20 Unsupported Request Error Status */
/* -------------- */
pseudo_bit_t uncorrectable_error_mask_register[0x00020];/* 0 Training Error Mask
4 Data Link Protocol Error Mask
- 12 Poisoned TLP Mask
+ 12 Poisoned TLP Mask
13 Flow Control Protocol Error Mask
14 Completion Timeout Mask
15 Completer Abort Mask
@@ -2855,7 +2855,7 @@ struct hermonprm_mt25208_type0_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved13[0x006a0];
/* -------------- */
-};
+};
/* Event Data Field - Performance Monitor */
@@ -2873,7 +2873,7 @@ struct hermonprm_performance_monitor_event_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved1[0x00040];
/* -------------- */
-};
+};
/* Event_data Field - Page Faults */
@@ -2897,7 +2897,7 @@ struct hermonprm_page_fault_event_data_st { /* Little Endian */
/* -------------- */
pseudo_bit_t prefetch_len[0x00020]; /* Indicates how many subsequent pages in the same memory region/window will be accessed by the following transaction after this page fault is resolved. measured in bytes. SW can use this information in order to page-in the subsequent pages if they are not present. */
/* -------------- */
-};
+};
/* WQE segments format */
@@ -2914,7 +2914,7 @@ struct hermonprm_wqe_segment_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved2[0x00080];
/* -------------- */
-};
+};
/* Event_data Field - Port State Change #### michal - match PRM */
@@ -2927,7 +2927,7 @@ struct hermonprm_port_state_change_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved3[0x00060];
/* -------------- */
-};
+};
/* Event_data Field - Completion Queue Error #### michal - match PRM */
@@ -2944,7 +2944,7 @@ struct hermonprm_completion_queue_error_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved3[0x00060];
/* -------------- */
-};
+};
/* Event_data Field - Completion Event #### michal - match PRM */
@@ -2954,12 +2954,12 @@ struct hermonprm_completion_event_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved1[0x000a0];
/* -------------- */
-};
+};
/* Event Queue Entry #### michal - match to PRM */
struct hermonprm_event_queue_entry_st { /* Little Endian */
- pseudo_bit_t event_sub_type[0x00008];/* Event Sub Type.
+ pseudo_bit_t event_sub_type[0x00008];/* Event Sub Type.
Defined for events which have sub types, zero elsewhere. */
pseudo_bit_t reserved0[0x00008];
pseudo_bit_t event_type[0x00008]; /* Event Type */
@@ -2968,12 +2968,12 @@ struct hermonprm_event_queue_entry_st { /* Little Endian */
pseudo_bit_t event_data[6][0x00020];/* Delivers auxilary data to handle event. */
/* -------------- */
pseudo_bit_t reserved2[0x00007];
- pseudo_bit_t owner[0x00001]; /* Owner of the entry
- 0 SW
+ pseudo_bit_t owner[0x00001]; /* Owner of the entry
+ 0 SW
1 HW */
pseudo_bit_t reserved3[0x00018];
/* -------------- */
-};
+};
/* QP/EE State Transitions Command Parameters ###michal - doesn't match PRM (field name changed) */
@@ -2986,7 +2986,7 @@ struct hermonprm_qp_ee_state_transitions_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved1[0x00800];
/* -------------- */
-};
+};
/* Completion Queue Entry Format #### michal - fixed by gdror */
@@ -3010,7 +3010,7 @@ struct hermonprm_completion_queue_entry_st { /* Little Endian */
For IPoIB (UD) and RawEth CQEs this field contains the RSS hash function value.
Otherwise, this field is reserved. */
/* -------------- */
- pseudo_bit_t srq_rqpn[0x00018]; /* For Responder UD QPs, Remote (source) QP number.
+ pseudo_bit_t srq_rqpn[0x00018]; /* For Responder UD QPs, Remote (source) QP number.
For Responder SRC QPs, SRQ number.
Otherwise, this field is reserved. */
pseudo_bit_t ml_path_mac_index[0x00007];/* For responder UD over IB CQE: These are the lower LMC bits of the DLID in an incoming UD packet, higher bits of this field, that are not part of the LMC bits are zeroed by HW. Invalid if incoming message DLID is the permissive LID or incoming message is multicast.
@@ -3028,17 +3028,17 @@ struct hermonprm_completion_queue_entry_st { /* Little Endian */
For responder UD over Ethernet and RawEth - it is VLAN-header[15:12]
Otherwise, this field is reserved. */
/* -------------- */
- pseudo_bit_t smac31_0_rawether_ipoib_status[0x00020];/* For responder UD over Ethernet - source MAC[31:0] of the packet.
- For responder RawEth and UD over IB - RawEth-IPoIB status {3 reserved, ipok,udp,tcp,ipv4opt,ipv6,ipv4vf,ipv4,rht(6),ipv6extmask(6),reserved(2),l2am,reserved(2),bfcs,reserved(2),enc}
+ pseudo_bit_t smac31_0_rawether_ipoib_status[0x00020];/* For responder UD over Ethernet - source MAC[31:0] of the packet.
+ For responder RawEth and UD over IB - RawEth-IPoIB status {3 reserved, ipok,udp,tcp,ipv4opt,ipv6,ipv4vf,ipv4,rht(6),ipv6extmask(6),reserved(2),l2am,reserved(2),bfcs,reserved(2),enc}
Otherwise, this field is reserved. */
/* -------------- */
- pseudo_bit_t byte_cnt[0x00020]; /* Byte count of data transferred. Applicable for RDMA-read, Atomic and all receive operations. completions.
+ pseudo_bit_t byte_cnt[0x00020]; /* Byte count of data transferred. Applicable for RDMA-read, Atomic and all receive operations. completions.
For Receive Queue that is subject for headers. separation, byte_cnt[31:24] specify number of bytes scattered to the first scatter entry (headers. length). Byte_cnt[23:0] specify total byte count received (including headers). */
/* -------------- */
pseudo_bit_t checksum[0x00010]; /* Valid for RawEth and IPoIB only. */
pseudo_bit_t wqe_counter[0x00010];
/* -------------- */
- pseudo_bit_t opcode[0x00005]; /* Send completions - same encoding as WQE.
+ pseudo_bit_t opcode[0x00005]; /* Send completions - same encoding as WQE.
Error coding is 0x1F
Receive:
0x0 - RDMA-Write with Immediate
@@ -3052,14 +3052,14 @@ struct hermonprm_completion_queue_entry_st { /* Little Endian */
pseudo_bit_t reserved1[0x00010];
pseudo_bit_t reserved2[0x00008];
/* -------------- */
-};
+};
/* */
struct hermonprm_mcg_qps_st { /* Little Endian */
struct hermonprm_mcg_qp_dw_st dw[128];
/* -------------- */
-};
+};
/* */
@@ -3084,7 +3084,7 @@ struct hermonprm_mcg_hdr_st { /* Little Endian */
/* -------------- */
pseudo_bit_t gid0[0x00020];
/* -------------- */
-};
+};
/* */
@@ -3096,7 +3096,7 @@ struct hermonprm_sched_queue_context_st { /* Little Endian */
pseudo_bit_t reserved0[0x00006];
pseudo_bit_t weight[0x00010]; /* Weight of this SchQ */
/* -------------- */
-};
+};
/* */
@@ -3117,7 +3117,7 @@ struct hermonprm_ecc_detect_event_data_st { /* Little Endian */
pseudo_bit_t err_ra[0x00010];
pseudo_bit_t err_ca[0x00010];
/* -------------- */
-};
+};
/* Event_data Field - ECC Detection Event */
@@ -3142,14 +3142,14 @@ struct hermonprm_scrubbing_event_st { /* Little Endian */
pseudo_bit_t err_ra[0x00010]; /* Error row address */
pseudo_bit_t err_ca[0x00010]; /* Error column address */
/* -------------- */
-};
+};
/* */
struct hermonprm_eq_cmd_doorbell_st { /* Little Endian */
pseudo_bit_t reserved0[0x00020];
/* -------------- */
-};
+};
/* 0 */
@@ -3400,5 +3400,5 @@ struct hermonprm_hermon_prm_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved64[0xffcfc0];
/* -------------- */
-};
+};
#endif /* H_prefix_hermonprm_bits_fixnames_MT25408_PRM_csp_H */
diff --git a/src/drivers/infiniband/arbel.c b/src/drivers/infiniband/arbel.c
index 98a2b6010..fbef3f8a6 100644
--- a/src/drivers/infiniband/arbel.c
+++ b/src/drivers/infiniband/arbel.c
@@ -639,8 +639,8 @@ static int arbel_create_cq ( struct ib_device *ibdev,
/* Allocate completion queue itself */
arbel_cq->cqe_size = ( cq->num_cqes * sizeof ( arbel_cq->cqe[0] ) );
- arbel_cq->cqe = malloc_dma ( arbel_cq->cqe_size,
- sizeof ( arbel_cq->cqe[0] ) );
+ arbel_cq->cqe = malloc_phys ( arbel_cq->cqe_size,
+ sizeof ( arbel_cq->cqe[0] ) );
if ( ! arbel_cq->cqe ) {
rc = -ENOMEM;
goto err_cqe;
@@ -697,7 +697,7 @@ static int arbel_create_cq ( struct ib_device *ibdev,
err_sw2hw_cq:
MLX_FILL_1 ( ci_db_rec, 1, res, ARBEL_UAR_RES_NONE );
MLX_FILL_1 ( arm_db_rec, 1, res, ARBEL_UAR_RES_NONE );
- free_dma ( arbel_cq->cqe, arbel_cq->cqe_size );
+ free_phys ( arbel_cq->cqe, arbel_cq->cqe_size );
err_cqe:
free ( arbel_cq );
err_arbel_cq:
@@ -737,7 +737,7 @@ static void arbel_destroy_cq ( struct ib_device *ibdev,
MLX_FILL_1 ( arm_db_rec, 1, res, ARBEL_UAR_RES_NONE );
/* Free memory */
- free_dma ( arbel_cq->cqe, arbel_cq->cqe_size );
+ free_phys ( arbel_cq->cqe, arbel_cq->cqe_size );
free ( arbel_cq );
/* Mark queue number as free */
@@ -873,8 +873,8 @@ static int arbel_create_send_wq ( struct arbel_send_work_queue *arbel_send_wq,
/* Allocate work queue */
arbel_send_wq->wqe_size = ( num_wqes *
sizeof ( arbel_send_wq->wqe[0] ) );
- arbel_send_wq->wqe = malloc_dma ( arbel_send_wq->wqe_size,
- sizeof ( arbel_send_wq->wqe[0] ) );
+ arbel_send_wq->wqe = malloc_phys ( arbel_send_wq->wqe_size,
+ sizeof ( arbel_send_wq->wqe[0] ) );
if ( ! arbel_send_wq->wqe )
return -ENOMEM;
memset ( arbel_send_wq->wqe, 0, arbel_send_wq->wqe_size );
@@ -914,8 +914,8 @@ static int arbel_create_recv_wq ( struct arbel_recv_work_queue *arbel_recv_wq,
/* Allocate work queue */
arbel_recv_wq->wqe_size = ( num_wqes *
sizeof ( arbel_recv_wq->wqe[0] ) );
- arbel_recv_wq->wqe = malloc_dma ( arbel_recv_wq->wqe_size,
- sizeof ( arbel_recv_wq->wqe[0] ) );
+ arbel_recv_wq->wqe = malloc_phys ( arbel_recv_wq->wqe_size,
+ sizeof ( arbel_recv_wq->wqe[0] ) );
if ( ! arbel_recv_wq->wqe ) {
rc = -ENOMEM;
goto err_alloc_wqe;
@@ -927,8 +927,8 @@ static int arbel_create_recv_wq ( struct arbel_recv_work_queue *arbel_recv_wq,
( type == IB_QPT_UD ) ) {
arbel_recv_wq->grh_size = ( num_wqes *
sizeof ( arbel_recv_wq->grh[0] ) );
- arbel_recv_wq->grh = malloc_dma ( arbel_recv_wq->grh_size,
- sizeof ( void * ) );
+ arbel_recv_wq->grh = malloc_phys ( arbel_recv_wq->grh_size,
+ sizeof ( void * ) );
if ( ! arbel_recv_wq->grh ) {
rc = -ENOMEM;
goto err_alloc_grh;
@@ -954,9 +954,9 @@ static int arbel_create_recv_wq ( struct arbel_recv_work_queue *arbel_recv_wq,
return 0;
- free_dma ( arbel_recv_wq->grh, arbel_recv_wq->grh_size );
+ free_phys ( arbel_recv_wq->grh, arbel_recv_wq->grh_size );
err_alloc_grh:
- free_dma ( arbel_recv_wq->wqe, arbel_recv_wq->wqe_size );
+ free_phys ( arbel_recv_wq->wqe, arbel_recv_wq->wqe_size );
err_alloc_wqe:
return rc;
}
@@ -1102,10 +1102,10 @@ static int arbel_create_qp ( struct ib_device *ibdev,
MLX_FILL_1 ( send_db_rec, 1, res, ARBEL_UAR_RES_NONE );
MLX_FILL_1 ( recv_db_rec, 1, res, ARBEL_UAR_RES_NONE );
err_unsupported_address_split:
- free_dma ( arbel_qp->recv.grh, arbel_qp->recv.grh_size );
- free_dma ( arbel_qp->recv.wqe, arbel_qp->recv.wqe_size );
+ free_phys ( arbel_qp->recv.grh, arbel_qp->recv.grh_size );
+ free_phys ( arbel_qp->recv.wqe, arbel_qp->recv.wqe_size );
err_create_recv_wq:
- free_dma ( arbel_qp->send.wqe, arbel_qp->send.wqe_size );
+ free_phys ( arbel_qp->send.wqe, arbel_qp->send.wqe_size );
err_create_send_wq:
free ( arbel_qp );
err_arbel_qp:
@@ -1231,9 +1231,9 @@ static void arbel_destroy_qp ( struct ib_device *ibdev,
MLX_FILL_1 ( recv_db_rec, 1, res, ARBEL_UAR_RES_NONE );
/* Free memory */
- free_dma ( arbel_qp->recv.grh, arbel_qp->recv.grh_size );
- free_dma ( arbel_qp->recv.wqe, arbel_qp->recv.wqe_size );
- free_dma ( arbel_qp->send.wqe, arbel_qp->send.wqe_size );
+ free_phys ( arbel_qp->recv.grh, arbel_qp->recv.grh_size );
+ free_phys ( arbel_qp->recv.wqe, arbel_qp->recv.wqe_size );
+ free_phys ( arbel_qp->send.wqe, arbel_qp->send.wqe_size );
free ( arbel_qp );
/* Mark queue number as free */
@@ -1758,8 +1758,8 @@ static int arbel_create_eq ( struct arbel *arbel ) {
/* Allocate event queue itself */
arbel_eq->eqe_size =
( ARBEL_NUM_EQES * sizeof ( arbel_eq->eqe[0] ) );
- arbel_eq->eqe = malloc_dma ( arbel_eq->eqe_size,
- sizeof ( arbel_eq->eqe[0] ) );
+ arbel_eq->eqe = malloc_phys ( arbel_eq->eqe_size,
+ sizeof ( arbel_eq->eqe[0] ) );
if ( ! arbel_eq->eqe ) {
rc = -ENOMEM;
goto err_eqe;
@@ -1806,7 +1806,7 @@ static int arbel_create_eq ( struct arbel *arbel ) {
err_map_eq:
arbel_cmd_hw2sw_eq ( arbel, arbel_eq->eqn, &eqctx );
err_sw2hw_eq:
- free_dma ( arbel_eq->eqe, arbel_eq->eqe_size );
+ free_phys ( arbel_eq->eqe, arbel_eq->eqe_size );
err_eqe:
memset ( arbel_eq, 0, sizeof ( *arbel_eq ) );
return rc;
@@ -1844,7 +1844,7 @@ static void arbel_destroy_eq ( struct arbel *arbel ) {
}
/* Free memory */
- free_dma ( arbel_eq->eqe, arbel_eq->eqe_size );
+ free_phys ( arbel_eq->eqe, arbel_eq->eqe_size );
memset ( arbel_eq, 0, sizeof ( *arbel_eq ) );
}
@@ -2059,7 +2059,8 @@ static int arbel_start_firmware ( struct arbel *arbel ) {
eq_set_ci_base_addr =
( ( (uint64_t) MLX_GET ( &fw, eq_set_ci_base_addr_h ) << 32 ) |
( (uint64_t) MLX_GET ( &fw, eq_set_ci_base_addr_l ) ) );
- arbel->eq_ci_doorbells = ioremap ( eq_set_ci_base_addr, 0x200 );
+ arbel->eq_ci_doorbells = pci_ioremap ( arbel->pci, eq_set_ci_base_addr,
+ 0x200 );
/* Enable locally-attached memory. Ignore failure; there may
* be no attached memory.
@@ -2454,7 +2455,7 @@ static int arbel_alloc_icm ( struct arbel *arbel,
icm_phys = user_to_phys ( arbel->icm, 0 );
/* Allocate doorbell UAR */
- arbel->db_rec = malloc_dma ( ARBEL_PAGE_SIZE, ARBEL_PAGE_SIZE );
+ arbel->db_rec = malloc_phys ( ARBEL_PAGE_SIZE, ARBEL_PAGE_SIZE );
if ( ! arbel->db_rec ) {
rc = -ENOMEM;
goto err_alloc_doorbell;
@@ -2512,7 +2513,7 @@ static int arbel_alloc_icm ( struct arbel *arbel,
err_map_icm:
arbel_cmd_unmap_icm_aux ( arbel );
err_map_icm_aux:
- free_dma ( arbel->db_rec, ARBEL_PAGE_SIZE );
+ free_phys ( arbel->db_rec, ARBEL_PAGE_SIZE );
arbel->db_rec= NULL;
err_alloc_doorbell:
err_alloc_icm:
@@ -2535,7 +2536,7 @@ static void arbel_free_icm ( struct arbel *arbel ) {
arbel_cmd_unmap_icm ( arbel, ( arbel->icm_len / ARBEL_PAGE_SIZE ),
&unmap_icm );
arbel_cmd_unmap_icm_aux ( arbel );
- free_dma ( arbel->db_rec, ARBEL_PAGE_SIZE );
+ free_phys ( arbel->db_rec, ARBEL_PAGE_SIZE );
arbel->db_rec = NULL;
}
@@ -2983,18 +2984,18 @@ static struct arbel * arbel_alloc ( void ) {
goto err_arbel;
/* Allocate space for mailboxes */
- arbel->mailbox_in = malloc_dma ( ARBEL_MBOX_SIZE, ARBEL_MBOX_ALIGN );
+ arbel->mailbox_in = malloc_phys ( ARBEL_MBOX_SIZE, ARBEL_MBOX_ALIGN );
if ( ! arbel->mailbox_in )
goto err_mailbox_in;
- arbel->mailbox_out = malloc_dma ( ARBEL_MBOX_SIZE, ARBEL_MBOX_ALIGN );
+ arbel->mailbox_out = malloc_phys ( ARBEL_MBOX_SIZE, ARBEL_MBOX_ALIGN );
if ( ! arbel->mailbox_out )
goto err_mailbox_out;
return arbel;
- free_dma ( arbel->mailbox_out, ARBEL_MBOX_SIZE );
+ free_phys ( arbel->mailbox_out, ARBEL_MBOX_SIZE );
err_mailbox_out:
- free_dma ( arbel->mailbox_in, ARBEL_MBOX_SIZE );
+ free_phys ( arbel->mailbox_in, ARBEL_MBOX_SIZE );
err_mailbox_in:
free ( arbel );
err_arbel:
@@ -3010,8 +3011,8 @@ static void arbel_free ( struct arbel *arbel ) {
ufree ( arbel->icm );
ufree ( arbel->firmware_area );
- free_dma ( arbel->mailbox_out, ARBEL_MBOX_SIZE );
- free_dma ( arbel->mailbox_in, ARBEL_MBOX_SIZE );
+ free_phys ( arbel->mailbox_out, ARBEL_MBOX_SIZE );
+ free_phys ( arbel->mailbox_in, ARBEL_MBOX_SIZE );
free ( arbel );
}
@@ -3025,6 +3026,8 @@ static void arbel_free ( struct arbel *arbel ) {
static int arbel_probe ( struct pci_device *pci ) {
struct arbel *arbel;
struct ib_device *ibdev;
+ unsigned long config;
+ unsigned long uar;
int i;
int rc;
@@ -3041,11 +3044,11 @@ static int arbel_probe ( struct pci_device *pci ) {
adjust_pci_device ( pci );
/* Map PCI BARs */
- arbel->config = ioremap ( pci_bar_start ( pci, ARBEL_PCI_CONFIG_BAR ),
- ARBEL_PCI_CONFIG_BAR_SIZE );
- arbel->uar = ioremap ( ( pci_bar_start ( pci, ARBEL_PCI_UAR_BAR ) +
- ARBEL_PCI_UAR_IDX * ARBEL_PCI_UAR_SIZE ),
- ARBEL_PCI_UAR_SIZE );
+ config = pci_bar_start ( pci, ARBEL_PCI_CONFIG_BAR );
+ arbel->config = pci_ioremap ( pci, config, ARBEL_PCI_CONFIG_BAR_SIZE );
+ uar = ( pci_bar_start ( pci, ARBEL_PCI_UAR_BAR ) +
+ ARBEL_PCI_UAR_IDX * ARBEL_PCI_UAR_SIZE );
+ arbel->uar = pci_ioremap ( pci, uar, ARBEL_PCI_UAR_SIZE );
/* Allocate Infiniband devices */
for ( i = 0 ; i < ARBEL_NUM_PORTS ; i++ ) {
@@ -3058,6 +3061,7 @@ static int arbel_probe ( struct pci_device *pci ) {
ibdev->op = &arbel_ib_operations;
ibdev->dev = &pci->dev;
ibdev->port = ( ARBEL_PORT_BASE + i );
+ ibdev->ports = ARBEL_NUM_PORTS;
ib_set_drvdata ( ibdev, arbel );
}
diff --git a/src/drivers/infiniband/flexboot_nodnic.c b/src/drivers/infiniband/flexboot_nodnic.c
index 7d039fffc..c6e19b955 100644
--- a/src/drivers/infiniband/flexboot_nodnic.c
+++ b/src/drivers/infiniband/flexboot_nodnic.c
@@ -1165,6 +1165,7 @@ flexboot_nodnic_allocate_infiniband_devices( struct flexboot_nodnic *flexboot_no
ibdev->op = &flexboot_nodnic_ib_operations;
ibdev->dev = &pci->dev;
ibdev->port = ( FLEXBOOT_NODNIC_PORT_BASE + i);
+ ibdev->ports = device_priv->device_cap.num_ports;
ib_set_drvdata(ibdev, flexboot_nodnic_priv);
}
return status;
@@ -1461,7 +1462,7 @@ static int flexboot_nodnic_alloc_uar ( struct flexboot_nodnic *flexboot_nodnic )
return -EINVAL;
}
uar->phys = ( pci_bar_start ( pci, FLEXBOOT_NODNIC_HCA_BAR ) + (mlx_uint32)uar->offset );
- uar->virt = ( void * )( ioremap ( uar->phys, FLEXBOOT_NODNIC_PAGE_SIZE ) );
+ uar->virt = ( void * )( pci_ioremap ( pci, uar->phys, FLEXBOOT_NODNIC_PAGE_SIZE ) );
return status;
}
diff --git a/src/drivers/infiniband/golan.c b/src/drivers/infiniband/golan.c
index e96ba2698..2f1ab2357 100755
--- a/src/drivers/infiniband/golan.c
+++ b/src/drivers/infiniband/golan.c
@@ -585,9 +585,9 @@ static inline int golan_set_access_reg ( struct golan *golan __attribute__ (( un
static inline void golan_cmd_uninit ( struct golan *golan )
{
- free_dma(golan->mboxes.outbox, GOLAN_PAGE_SIZE);
- free_dma(golan->mboxes.inbox, GOLAN_PAGE_SIZE);
- free_dma(golan->cmd.addr, GOLAN_PAGE_SIZE);
+ free_phys(golan->mboxes.outbox, GOLAN_PAGE_SIZE);
+ free_phys(golan->mboxes.inbox, GOLAN_PAGE_SIZE);
+ free_phys(golan->cmd.addr, GOLAN_PAGE_SIZE);
}
/**
@@ -602,17 +602,17 @@ static inline int golan_cmd_init ( struct golan *golan )
int rc = 0;
uint32_t addr_l_sz;
- if (!(golan->cmd.addr = malloc_dma(GOLAN_PAGE_SIZE , GOLAN_PAGE_SIZE))) {
+ if (!(golan->cmd.addr = malloc_phys(GOLAN_PAGE_SIZE , GOLAN_PAGE_SIZE))) {
rc = -ENOMEM;
- goto malloc_dma_failed;
+ goto malloc_phys_failed;
}
- if (!(golan->mboxes.inbox = malloc_dma(GOLAN_PAGE_SIZE , GOLAN_PAGE_SIZE))) {
+ if (!(golan->mboxes.inbox = malloc_phys(GOLAN_PAGE_SIZE , GOLAN_PAGE_SIZE))) {
rc = -ENOMEM;
- goto malloc_dma_inbox_failed;
+ goto malloc_phys_inbox_failed;
}
- if (!(golan->mboxes.outbox = malloc_dma(GOLAN_PAGE_SIZE , GOLAN_PAGE_SIZE))) {
+ if (!(golan->mboxes.outbox = malloc_phys(GOLAN_PAGE_SIZE , GOLAN_PAGE_SIZE))) {
rc = -ENOMEM;
- goto malloc_dma_outbox_failed;
+ goto malloc_phys_outbox_failed;
}
addr_l_sz = be32_to_cpu(readl(&golan->iseg->cmdq_addr_l_sz));
@@ -629,11 +629,11 @@ static inline int golan_cmd_init ( struct golan *golan )
DBGC( golan , "%s Command interface was initialized\n", __FUNCTION__);
return 0;
-malloc_dma_outbox_failed:
- free_dma(golan->mboxes.inbox, GOLAN_PAGE_SIZE);
-malloc_dma_inbox_failed:
- free_dma(golan->cmd.addr, GOLAN_PAGE_SIZE);
-malloc_dma_failed:
+malloc_phys_outbox_failed:
+ free_phys(golan->mboxes.inbox, GOLAN_PAGE_SIZE);
+malloc_phys_inbox_failed:
+ free_phys(golan->cmd.addr, GOLAN_PAGE_SIZE);
+malloc_phys_failed:
DBGC (golan ,"%s Failed to initialize command interface (rc = 0x%x)\n",
__FUNCTION__, rc);
return rc;
@@ -693,7 +693,7 @@ static inline int golan_alloc_uar(struct golan *golan)
uar->index = be32_to_cpu(out->uarn) & 0xffffff;
uar->phys = (pci_bar_start(golan->pci, GOLAN_HCA_BAR) + (uar->index << GOLAN_PAGE_SHIFT));
- uar->virt = (void *)(ioremap(uar->phys, GOLAN_PAGE_SIZE));
+ uar->virt = (void *)(pci_ioremap(golan->pci, uar->phys, GOLAN_PAGE_SIZE));
DBGC( golan , "%s: UAR allocated with index 0x%x\n", __FUNCTION__, uar->index);
return 0;
@@ -743,7 +743,7 @@ static int golan_create_eq(struct golan *golan)
eq->cons_index = 0;
eq->size = GOLAN_NUM_EQES * sizeof(eq->eqes[0]);
- eq->eqes = malloc_dma ( GOLAN_PAGE_SIZE, GOLAN_PAGE_SIZE );
+ eq->eqes = malloc_phys ( GOLAN_PAGE_SIZE, GOLAN_PAGE_SIZE );
if (!eq->eqes) {
rc = -ENOMEM;
goto err_create_eq_eqe_alloc;
@@ -781,7 +781,7 @@ static int golan_create_eq(struct golan *golan)
return 0;
err_create_eq_cmd:
- free_dma ( eq->eqes , GOLAN_PAGE_SIZE );
+ free_phys ( eq->eqes , GOLAN_PAGE_SIZE );
err_create_eq_eqe_alloc:
DBGC (golan ,"%s [%d] out\n", __FUNCTION__, rc);
return rc;
@@ -806,7 +806,7 @@ static void golan_destory_eq(struct golan *golan)
rc = send_command_and_wait(golan, DEF_CMD_IDX, NO_MBOX, NO_MBOX, __FUNCTION__);
GOLAN_PRINT_RC_AND_CMD_STATUS;
- free_dma ( golan->eq.eqes , GOLAN_PAGE_SIZE );
+ free_phys ( golan->eq.eqes , GOLAN_PAGE_SIZE );
golan->eq.eqn = 0;
DBGC( golan, "%s Event queue (0x%x) was destroyed\n", __FUNCTION__, eqn);
@@ -922,8 +922,8 @@ static inline void golan_pci_init(struct golan *golan)
adjust_pci_device ( pci );
/* Get HCA BAR */
- golan->iseg = ioremap ( pci_bar_start ( pci, GOLAN_HCA_BAR),
- GOLAN_PCI_CONFIG_BAR_SIZE );
+ golan->iseg = pci_ioremap ( pci, pci_bar_start ( pci, GOLAN_HCA_BAR),
+ GOLAN_PCI_CONFIG_BAR_SIZE );
}
static inline struct golan *golan_alloc()
@@ -962,14 +962,14 @@ static int golan_create_cq(struct ib_device *ibdev,
goto err_create_cq;
}
golan_cq->size = sizeof(golan_cq->cqes[0]) * cq->num_cqes;
- golan_cq->doorbell_record = malloc_dma(GOLAN_CQ_DB_RECORD_SIZE,
+ golan_cq->doorbell_record = malloc_phys(GOLAN_CQ_DB_RECORD_SIZE,
GOLAN_CQ_DB_RECORD_SIZE);
if (!golan_cq->doorbell_record) {
rc = -ENOMEM;
goto err_create_cq_db_alloc;
}
- golan_cq->cqes = malloc_dma ( GOLAN_PAGE_SIZE, GOLAN_PAGE_SIZE );
+ golan_cq->cqes = malloc_phys ( GOLAN_PAGE_SIZE, GOLAN_PAGE_SIZE );
if (!golan_cq->cqes) {
rc = -ENOMEM;
goto err_create_cq_cqe_alloc;
@@ -1008,9 +1008,9 @@ static int golan_create_cq(struct ib_device *ibdev,
return 0;
err_create_cq_cmd:
- free_dma( golan_cq->cqes , GOLAN_PAGE_SIZE );
+ free_phys( golan_cq->cqes , GOLAN_PAGE_SIZE );
err_create_cq_cqe_alloc:
- free_dma(golan_cq->doorbell_record, GOLAN_CQ_DB_RECORD_SIZE);
+ free_phys(golan_cq->doorbell_record, GOLAN_CQ_DB_RECORD_SIZE);
err_create_cq_db_alloc:
free ( golan_cq );
err_create_cq:
@@ -1045,8 +1045,8 @@ static void golan_destroy_cq(struct ib_device *ibdev,
cq->cqn = 0;
ib_cq_set_drvdata(cq, NULL);
- free_dma ( golan_cq->cqes , GOLAN_PAGE_SIZE );
- free_dma(golan_cq->doorbell_record, GOLAN_CQ_DB_RECORD_SIZE);
+ free_phys ( golan_cq->cqes , GOLAN_PAGE_SIZE );
+ free_phys(golan_cq->doorbell_record, GOLAN_CQ_DB_RECORD_SIZE);
free(golan_cq);
DBGC (golan, "%s CQ number 0x%x was destroyed\n", __FUNCTION__, cqn);
@@ -1138,7 +1138,7 @@ static int golan_create_qp_aux(struct ib_device *ibdev,
golan_qp->size = golan_qp->sq.size + golan_qp->rq.size;
/* allocate dma memory for WQEs (1 page is enough) - should change it */
- golan_qp->wqes = malloc_dma ( GOLAN_PAGE_SIZE, GOLAN_PAGE_SIZE );
+ golan_qp->wqes = malloc_phys ( GOLAN_PAGE_SIZE, GOLAN_PAGE_SIZE );
if (!golan_qp->wqes) {
rc = -ENOMEM;
goto err_create_qp_wqe_alloc;
@@ -1160,7 +1160,7 @@ static int golan_create_qp_aux(struct ib_device *ibdev,
data++;
}
- golan_qp->doorbell_record = malloc_dma(sizeof(struct golan_qp_db),
+ golan_qp->doorbell_record = malloc_phys(sizeof(struct golan_qp_db),
sizeof(struct golan_qp_db));
if (!golan_qp->doorbell_record) {
rc = -ENOMEM;
@@ -1213,9 +1213,9 @@ static int golan_create_qp_aux(struct ib_device *ibdev,
return 0;
err_create_qp_cmd:
- free_dma(golan_qp->doorbell_record, sizeof(struct golan_qp_db));
+ free_phys(golan_qp->doorbell_record, sizeof(struct golan_qp_db));
err_create_qp_db_alloc:
- free_dma ( golan_qp->wqes, GOLAN_PAGE_SIZE );
+ free_phys ( golan_qp->wqes, GOLAN_PAGE_SIZE );
err_create_qp_wqe_alloc:
err_create_qp_sq_size:
err_create_qp_sq_wqe_size:
@@ -1422,8 +1422,8 @@ static void golan_destroy_qp(struct ib_device *ibdev,
qp->qpn = 0;
ib_qp_set_drvdata(qp, NULL);
- free_dma(golan_qp->doorbell_record, sizeof(struct golan_qp_db));
- free_dma ( golan_qp->wqes, GOLAN_PAGE_SIZE );
+ free_phys(golan_qp->doorbell_record, sizeof(struct golan_qp_db));
+ free_phys ( golan_qp->wqes, GOLAN_PAGE_SIZE );
free(golan_qp);
DBGC( golan ,"%s QP 0x%lx was destroyed\n", __FUNCTION__, qpn);
@@ -2386,6 +2386,7 @@ static int golan_probe_normal ( struct pci_device *pci ) {
ibdev->op = &golan_ib_operations;
ibdev->dev = &pci->dev;
ibdev->port = (GOLAN_PORT_BASE + i);
+ ibdev->ports = golan->caps.num_ports;
ib_set_drvdata( ibdev, golan );
}
@@ -2642,7 +2643,10 @@ static struct pci_device_id golan_nics[] = {
PCI_ROM ( 0x15b3, 0x1019, "ConnectX-5EX", "ConnectX-5EX HCA driver, DevID 4121", 0 ),
PCI_ROM ( 0x15b3, 0x101b, "ConnectX-6", "ConnectX-6 HCA driver, DevID 4123", 0 ),
PCI_ROM ( 0x15b3, 0x101d, "ConnectX-6DX", "ConnectX-6DX HCA driver, DevID 4125", 0 ),
+ PCI_ROM ( 0x15b3, 0x101f, "ConnectX-6Lx", "ConnectX-6LX HCA driver, DevID 4127", 0 ),
+ PCI_ROM ( 0x15b3, 0x1021, "ConnectX-7", "ConnectX-7 HCA driver, DevID 4129", 0 ),
PCI_ROM ( 0x15b3, 0xa2d2, "BlueField", "BlueField integrated ConnectX-5 network controller HCA driver, DevID 41682", 0 ),
+ PCI_ROM ( 0x15b3, 0xa2d6, "BlueField-2", "BlueField-2 network controller HCA driver, DevID 41686", 0 ),
};
struct pci_driver golan_driver __pci_driver = {
diff --git a/src/drivers/infiniband/hermon.c b/src/drivers/infiniband/hermon.c
index 9675c156b..2afaaf991 100644
--- a/src/drivers/infiniband/hermon.c
+++ b/src/drivers/infiniband/hermon.c
@@ -137,13 +137,13 @@ static int hermon_cmd_wait ( struct hermon *hermon,
struct hermonprm_hca_command_register *hcr ) {
unsigned int wait;
- for ( wait = HERMON_HCR_MAX_WAIT_MS ; wait ; wait-- ) {
+ for ( wait = ( 100 * HERMON_HCR_MAX_WAIT_MS ) ; wait ; wait-- ) {
hcr->u.dwords[6] =
readl ( hermon->config + HERMON_HCR_REG ( 6 ) );
if ( ( MLX_GET ( hcr, go ) == 0 ) &&
( MLX_GET ( hcr, t ) == hermon->toggle ) )
return 0;
- mdelay ( 1 );
+ udelay ( 10 );
}
return -EBUSY;
}
@@ -175,7 +175,7 @@ static int hermon_cmd ( struct hermon *hermon, unsigned long command,
assert ( in_len <= HERMON_MBOX_SIZE );
assert ( out_len <= HERMON_MBOX_SIZE );
- DBGC2 ( hermon, "Hermon %p command %02x in %zx%s out %zx%s\n",
+ DBGC2 ( hermon, "Hermon %p command %04x in %zx%s out %zx%s\n",
hermon, opcode, in_len,
( ( command & HERMON_HCR_IN_MBOX ) ? "(mbox)" : "" ), out_len,
( ( command & HERMON_HCR_OUT_MBOX ) ? "(mbox)" : "" ) );
@@ -214,8 +214,6 @@ static int hermon_cmd ( struct hermon *hermon, unsigned long command,
opcode_modifier, op_mod,
go, 1,
t, hermon->toggle );
- DBGC ( hermon, "Hermon %p issuing command %04x\n",
- hermon, opcode );
DBGC2_HDA ( hermon, virt_to_phys ( hermon->config + HERMON_HCR_BASE ),
&hcr, sizeof ( hcr ) );
if ( in_len && ( command & HERMON_HCR_IN_MBOX ) ) {
@@ -234,8 +232,8 @@ static int hermon_cmd ( struct hermon *hermon, unsigned long command,
/* Wait for command completion */
if ( ( rc = hermon_cmd_wait ( hermon, &hcr ) ) != 0 ) {
- DBGC ( hermon, "Hermon %p timed out waiting for command:\n",
- hermon );
+ DBGC ( hermon, "Hermon %p timed out waiting for command "
+ "%04x:\n", hermon, opcode );
DBGC_HDA ( hermon,
virt_to_phys ( hermon->config + HERMON_HCR_BASE ),
&hcr, sizeof ( hcr ) );
@@ -245,8 +243,8 @@ static int hermon_cmd ( struct hermon *hermon, unsigned long command,
/* Check command status */
status = MLX_GET ( &hcr, status );
if ( status != 0 ) {
- DBGC ( hermon, "Hermon %p command failed with status %02x:\n",
- hermon, status );
+ DBGC ( hermon, "Hermon %p command %04x failed with status "
+ "%02x:\n", hermon, opcode, status );
DBGC_HDA ( hermon,
virt_to_phys ( hermon->config + HERMON_HCR_BASE ),
&hcr, sizeof ( hcr ) );
@@ -334,6 +332,13 @@ hermon_cmd_sw2hw_mpt ( struct hermon *hermon, unsigned int index,
}
static inline int
+hermon_cmd_hw2sw_mpt ( struct hermon *hermon, unsigned int index ) {
+ return hermon_cmd ( hermon,
+ HERMON_HCR_VOID_CMD ( HERMON_HCR_HW2SW_MPT ),
+ 0, NULL, index, NULL );
+}
+
+static inline int
hermon_cmd_write_mtt ( struct hermon *hermon,
const struct hermonprm_write_mtt *write_mtt ) {
return hermon_cmd ( hermon,
@@ -638,9 +643,9 @@ static int hermon_alloc_mtt ( struct hermon *hermon,
mtt_offset = hermon_bitmask_alloc ( hermon->mtt_inuse, HERMON_MAX_MTTS,
num_pages );
if ( mtt_offset < 0 ) {
- DBGC ( hermon, "Hermon %p could not allocate %d MTT entries\n",
- hermon, num_pages );
rc = mtt_offset;
+ DBGC ( hermon, "Hermon %p could not allocate %d MTT entries: "
+ "%s\n", hermon, num_pages, strerror ( rc ) );
goto err_mtt_offset;
}
mtt_base_addr = ( ( hermon->cap.reserved_mtts + mtt_offset ) *
@@ -664,8 +669,9 @@ static int hermon_alloc_mtt ( struct hermon *hermon,
ptag_l, ( addr >> 3 ) );
if ( ( rc = hermon_cmd_write_mtt ( hermon,
&write_mtt ) ) != 0 ) {
- DBGC ( hermon, "Hermon %p could not write MTT at %x\n",
- hermon, mtt_base_addr );
+ DBGC ( hermon, "Hermon %p could not write MTT at %x: "
+ "%s\n", hermon, mtt_base_addr,
+ strerror ( rc ) );
goto err_write_mtt;
}
addr += HERMON_PAGE_SIZE;
@@ -817,6 +823,11 @@ hermon_dump_cqctx ( struct hermon *hermon, struct ib_completion_queue *cq ) {
struct hermonprm_completion_queue_context cqctx;
int rc;
+ /* Do nothing unless debugging is enabled */
+ if ( ! DBG_LOG )
+ return 0;
+
+ /* Dump completion queue context */
memset ( &cqctx, 0, sizeof ( cqctx ) );
if ( ( rc = hermon_cmd_query_cq ( hermon, cq->cqn, &cqctx ) ) != 0 ) {
DBGC ( hermon, "Hermon %p CQN %#lx QUERY_CQ failed: %s\n",
@@ -859,14 +870,18 @@ static int hermon_create_cq ( struct ib_device *ibdev,
/* Allocate control structures */
hermon_cq = zalloc ( sizeof ( *hermon_cq ) );
if ( ! hermon_cq ) {
+ DBGC ( hermon, "Hermon %p CQN %#lx could not allocate CQ\n",
+ hermon, cq->cqn );
rc = -ENOMEM;
goto err_hermon_cq;
}
/* Allocate doorbell */
- hermon_cq->doorbell = malloc_dma ( sizeof ( hermon_cq->doorbell[0] ),
- sizeof ( hermon_cq->doorbell[0] ) );
+ hermon_cq->doorbell = malloc_phys ( sizeof ( hermon_cq->doorbell[0] ),
+ sizeof ( hermon_cq->doorbell[0] ) );
if ( ! hermon_cq->doorbell ) {
+ DBGC ( hermon, "Hermon %p CQN %#lx could not allocate "
+ "doorbell\n", hermon, cq->cqn );
rc = -ENOMEM;
goto err_doorbell;
}
@@ -874,9 +889,11 @@ static int hermon_create_cq ( struct ib_device *ibdev,
/* Allocate completion queue itself */
hermon_cq->cqe_size = ( cq->num_cqes * sizeof ( hermon_cq->cqe[0] ) );
- hermon_cq->cqe = malloc_dma ( hermon_cq->cqe_size,
- sizeof ( hermon_cq->cqe[0] ) );
+ hermon_cq->cqe = malloc_phys ( hermon_cq->cqe_size,
+ sizeof ( hermon_cq->cqe[0] ) );
if ( ! hermon_cq->cqe ) {
+ DBGC ( hermon, "Hermon %p CQN %#lx could not allocate CQEs\n",
+ hermon, cq->cqn );
rc = -ENOMEM;
goto err_cqe;
}
@@ -889,8 +906,11 @@ static int hermon_create_cq ( struct ib_device *ibdev,
/* Allocate MTT entries */
if ( ( rc = hermon_alloc_mtt ( hermon, hermon_cq->cqe,
hermon_cq->cqe_size,
- &hermon_cq->mtt ) ) != 0 )
+ &hermon_cq->mtt ) ) != 0 ) {
+ DBGC ( hermon, "Hermon %p CQN %#lx could not allocate MTTs: "
+ "%s\n", hermon, cq->cqn, strerror ( rc ) );
goto err_alloc_mtt;
+ }
/* Hand queue over to hardware */
memset ( &cqctx, 0, sizeof ( cqctx ) );
@@ -925,9 +945,9 @@ static int hermon_create_cq ( struct ib_device *ibdev,
err_sw2hw_cq:
hermon_free_mtt ( hermon, &hermon_cq->mtt );
err_alloc_mtt:
- free_dma ( hermon_cq->cqe, hermon_cq->cqe_size );
+ free_phys ( hermon_cq->cqe, hermon_cq->cqe_size );
err_cqe:
- free_dma ( hermon_cq->doorbell, sizeof ( hermon_cq->doorbell[0] ) );
+ free_phys ( hermon_cq->doorbell, sizeof ( hermon_cq->doorbell[0] ) );
err_doorbell:
free ( hermon_cq );
err_hermon_cq:
@@ -962,8 +982,8 @@ static void hermon_destroy_cq ( struct ib_device *ibdev,
hermon_free_mtt ( hermon, &hermon_cq->mtt );
/* Free memory */
- free_dma ( hermon_cq->cqe, hermon_cq->cqe_size );
- free_dma ( hermon_cq->doorbell, sizeof ( hermon_cq->doorbell[0] ) );
+ free_phys ( hermon_cq->cqe, hermon_cq->cqe_size );
+ free_phys ( hermon_cq->doorbell, sizeof ( hermon_cq->doorbell[0] ) );
free ( hermon_cq );
/* Mark queue number as free */
@@ -1084,16 +1104,30 @@ static uint8_t hermon_qp_st[] = {
*/
static __attribute__ (( unused )) int
hermon_dump_qpctx ( struct hermon *hermon, struct ib_queue_pair *qp ) {
+ struct hermon_queue_pair *hermon_qp = ib_qp_get_drvdata ( qp );
struct hermonprm_qp_ee_state_transitions qpctx;
+ unsigned int state;
int rc;
+ /* Do nothing unless debugging is enabled */
+ if ( ! DBG_LOG )
+ return 0;
+
+ /* Dump queue pair context */
memset ( &qpctx, 0, sizeof ( qpctx ) );
if ( ( rc = hermon_cmd_query_qp ( hermon, qp->qpn, &qpctx ) ) != 0 ) {
DBGC ( hermon, "Hermon %p QPN %#lx QUERY_QP failed: %s\n",
hermon, qp->qpn, strerror ( rc ) );
return rc;
}
- DBGC ( hermon, "Hermon %p QPN %#lx context:\n", hermon, qp->qpn );
+ state = MLX_GET ( &qpctx, qpc_eec_data.state );
+ if ( state != hermon_qp->state ) {
+ DBGC ( hermon, "Hermon %p QPN %#lx state %d unexpected "
+ "(should be %d)\n",
+ hermon, qp->qpn, state, hermon_qp->state );
+ }
+ DBGC ( hermon, "Hermon %p QPN %#lx state %d context:\n",
+ hermon, qp->qpn, state );
DBGC_HDA ( hermon, 0, &qpctx.u.dwords[2], ( sizeof ( qpctx ) - 8 ) );
return 0;
@@ -1122,15 +1156,19 @@ static int hermon_create_qp ( struct ib_device *ibdev,
/* Allocate control structures */
hermon_qp = zalloc ( sizeof ( *hermon_qp ) );
if ( ! hermon_qp ) {
+ DBGC ( hermon, "Hermon %p QPN %#lx could not allocate QP\n",
+ hermon, qp->qpn );
rc = -ENOMEM;
goto err_hermon_qp;
}
/* Allocate doorbells */
hermon_qp->recv.doorbell =
- malloc_dma ( sizeof ( hermon_qp->recv.doorbell[0] ),
- sizeof ( hermon_qp->recv.doorbell[0] ) );
+ malloc_phys ( sizeof ( hermon_qp->recv.doorbell[0] ),
+ sizeof ( hermon_qp->recv.doorbell[0] ) );
if ( ! hermon_qp->recv.doorbell ) {
+ DBGC ( hermon, "Hermon %p QPN %#lx could not allocate "
+ "doorbell\n", hermon, qp->qpn );
rc = -ENOMEM;
goto err_recv_doorbell;
}
@@ -1157,9 +1195,11 @@ static int hermon_create_qp ( struct ib_device *ibdev,
hermon_qp->wqe_size = ( hermon_qp->send.wqe_size +
hermon_qp->recv.wqe_size +
hermon_qp->recv.grh_size );
- hermon_qp->wqe = malloc_dma ( hermon_qp->wqe_size,
- sizeof ( hermon_qp->send.wqe[0] ) );
+ hermon_qp->wqe = malloc_phys ( hermon_qp->wqe_size,
+ sizeof ( hermon_qp->send.wqe[0] ) );
if ( ! hermon_qp->wqe ) {
+ DBGC ( hermon, "Hermon %p QPN %#lx could not allocate WQEs\n",
+ hermon, qp->qpn );
rc = -ENOMEM;
goto err_alloc_wqe;
}
@@ -1184,6 +1224,8 @@ static int hermon_create_qp ( struct ib_device *ibdev,
if ( ( rc = hermon_alloc_mtt ( hermon, hermon_qp->wqe,
hermon_qp->wqe_size,
&hermon_qp->mtt ) ) != 0 ) {
+ DBGC ( hermon, "Hermon %p QPN %#lx could not allocate MTTs: "
+ "%s\n", hermon, qp->qpn, strerror ( rc ) );
goto err_alloc_mtt;
}
@@ -1248,10 +1290,10 @@ static int hermon_create_qp ( struct ib_device *ibdev,
err_rst2init_qp:
hermon_free_mtt ( hermon, &hermon_qp->mtt );
err_alloc_mtt:
- free_dma ( hermon_qp->wqe, hermon_qp->wqe_size );
+ free_phys ( hermon_qp->wqe, hermon_qp->wqe_size );
err_alloc_wqe:
- free_dma ( hermon_qp->recv.doorbell,
- sizeof ( hermon_qp->recv.doorbell[0] ) );
+ free_phys ( hermon_qp->recv.doorbell,
+ sizeof ( hermon_qp->recv.doorbell[0] ) );
err_recv_doorbell:
free ( hermon_qp );
err_hermon_qp:
@@ -1363,9 +1405,9 @@ static void hermon_destroy_qp ( struct ib_device *ibdev,
hermon_free_mtt ( hermon, &hermon_qp->mtt );
/* Free memory */
- free_dma ( hermon_qp->wqe, hermon_qp->wqe_size );
- free_dma ( hermon_qp->recv.doorbell,
- sizeof ( hermon_qp->recv.doorbell[0] ) );
+ free_phys ( hermon_qp->wqe, hermon_qp->wqe_size );
+ free_phys ( hermon_qp->recv.doorbell,
+ sizeof ( hermon_qp->recv.doorbell[0] ) );
free ( hermon_qp );
/* Mark queue number as free */
@@ -1766,6 +1808,11 @@ static int hermon_complete ( struct ib_device *ibdev,
if ( is_send ) {
/* Hand off to completion handler */
ib_complete_send ( ibdev, qp, iobuf, rc );
+ } else if ( rc != 0 ) {
+ /* Dump queue state (for debugging) */
+ hermon_dump_qpctx ( hermon, qp );
+ /* Hand off to completion handler */
+ ib_complete_recv ( ibdev, qp, NULL, NULL, iobuf, rc );
} else {
/* Set received length */
len = MLX_GET ( &cqe->normal, byte_cnt );
@@ -1808,7 +1855,7 @@ static int hermon_complete ( struct ib_device *ibdev,
assert ( len <= iob_tailroom ( iobuf ) );
iob_put ( iobuf, len );
/* Hand off to completion handler */
- ib_complete_recv ( ibdev, qp, &recv_dest, source, iobuf, rc );
+ ib_complete_recv ( ibdev, qp, &recv_dest, source, iobuf, 0 );
}
return rc;
@@ -1863,6 +1910,89 @@ static void hermon_poll_cq ( struct ib_device *ibdev,
*/
/**
+ * Dump event queue context (for debugging only)
+ *
+ * @v hermon Hermon device
+ * @v hermon_eq Event queue
+ * @ret rc Return status code
+ */
+static __attribute__ (( unused )) int
+hermon_dump_eqctx ( struct hermon *hermon,
+ struct hermon_event_queue *hermon_eq ) {
+ struct hermonprm_eqc eqctx;
+ int rc;
+
+ /* Do nothing unless debugging is enabled */
+ if ( ! DBG_LOG )
+ return 0;
+
+ /* Dump event queue context */
+ memset ( &eqctx, 0, sizeof ( eqctx ) );
+ if ( ( rc = hermon_cmd_query_eq ( hermon, hermon_eq->eqn,
+ &eqctx ) ) != 0 ) {
+ DBGC ( hermon, "Hermon %p EQN %#lx QUERY_EQ failed: %s\n",
+ hermon, hermon_eq->eqn, strerror ( rc ) );
+ return rc;
+ }
+ DBGC ( hermon, "Hermon %p EQN %#lx context:\n",
+ hermon, hermon_eq->eqn );
+ DBGC_HDA ( hermon, 0, &eqctx, sizeof ( eqctx ) );
+
+ return 0;
+}
+
+/**
+ * Dump unconsumed event queue entries (for debugging only)
+ *
+ * @v hermon Hermon device
+ * @v hermon_eq Event queue
+ * @ret rc Return status code
+ */
+static __attribute__ (( unused )) int
+hermon_dump_eqes ( struct hermon *hermon,
+ struct hermon_event_queue *hermon_eq ) {
+ struct hermonprm_eqc eqctx;
+ union hermonprm_event_entry *eqe;
+ unsigned int mask;
+ unsigned int prod;
+ unsigned int cons;
+ unsigned int idx;
+ int rc;
+
+ /* Do nothing unless debugging is enabled */
+ if ( ! DBG_LOG )
+ return 0;
+
+ /* Dump event queue entries */
+ memset ( &eqctx, 0, sizeof ( eqctx ) );
+ if ( ( rc = hermon_cmd_query_eq ( hermon, hermon_eq->eqn,
+ &eqctx ) ) != 0 ) {
+ DBGC ( hermon, "Hermon %p EQN %#lx QUERY_EQ failed: %s\n",
+ hermon, hermon_eq->eqn, strerror ( rc ) );
+ return rc;
+ }
+ mask = ( HERMON_NUM_EQES - 1 );
+ prod = MLX_GET ( &eqctx, producer_counter ) & mask;
+ cons = MLX_GET ( &eqctx, consumer_counter ) & mask;
+ idx = hermon_eq->next_idx;
+ if ( ( idx & mask ) != ( cons & mask ) ) {
+ DBGC ( hermon, "Hermon %p EQN %#lx mismatch: SW %#x != HW "
+ "%#x\n", hermon, hermon_eq->eqn, idx, cons );
+ }
+ for ( ; ( idx & mask ) != ( prod & mask ) ; idx++ ) {
+ eqe = &hermon_eq->eqe[idx & mask];
+ DBGC ( hermon, "Hermon %p EQN %#lx event %#x owner %d type "
+ "%#02x:%#02x\n", hermon, hermon_eq->eqn, idx,
+ MLX_GET ( &eqe->generic, owner ),
+ MLX_GET ( &eqe->generic, event_type ),
+ MLX_GET ( &eqe->generic, event_sub_type ) );
+ DBGC_HDA ( hermon, 0, eqe, sizeof ( *eqe ) );
+ }
+
+ return 0;
+}
+
+/**
* Create event queue
*
* @v hermon Hermon device
@@ -1887,9 +2017,11 @@ static int hermon_create_eq ( struct hermon *hermon ) {
/* Allocate event queue itself */
hermon_eq->eqe_size =
( HERMON_NUM_EQES * sizeof ( hermon_eq->eqe[0] ) );
- hermon_eq->eqe = malloc_dma ( hermon_eq->eqe_size,
- sizeof ( hermon_eq->eqe[0] ) );
+ hermon_eq->eqe = malloc_phys ( hermon_eq->eqe_size,
+ sizeof ( hermon_eq->eqe[0] ) );
if ( ! hermon_eq->eqe ) {
+ DBGC ( hermon, "Hermon %p EQN %#lx could not allocate EQEs\n",
+ hermon, hermon_eq->eqn );
rc = -ENOMEM;
goto err_eqe;
}
@@ -1902,8 +2034,11 @@ static int hermon_create_eq ( struct hermon *hermon ) {
/* Allocate MTT entries */
if ( ( rc = hermon_alloc_mtt ( hermon, hermon_eq->eqe,
hermon_eq->eqe_size,
- &hermon_eq->mtt ) ) != 0 )
+ &hermon_eq->mtt ) ) != 0 ) {
+ DBGC ( hermon, "Hermon %p EQN %#lx could not allocate MTTs: "
+ "%s\n", hermon, hermon_eq->eqn, strerror ( rc ) );
goto err_alloc_mtt;
+ }
/* Hand queue over to hardware */
memset ( &eqctx, 0, sizeof ( eqctx ) );
@@ -1946,7 +2081,7 @@ static int hermon_create_eq ( struct hermon *hermon ) {
err_sw2hw_eq:
hermon_free_mtt ( hermon, &hermon_eq->mtt );
err_alloc_mtt:
- free_dma ( hermon_eq->eqe, hermon_eq->eqe_size );
+ free_phys ( hermon_eq->eqe, hermon_eq->eqe_size );
err_eqe:
memset ( hermon_eq, 0, sizeof ( *hermon_eq ) );
return rc;
@@ -1986,7 +2121,7 @@ static void hermon_destroy_eq ( struct hermon *hermon ) {
hermon_free_mtt ( hermon, &hermon_eq->mtt );
/* Free memory */
- free_dma ( hermon_eq->eqe, hermon_eq->eqe_size );
+ free_phys ( hermon_eq->eqe, hermon_eq->eqe_size );
memset ( hermon_eq, 0, sizeof ( *hermon_eq ) );
}
@@ -2020,6 +2155,32 @@ static void hermon_event_port_state_change ( struct hermon *hermon,
}
/**
+ * Handle port management event
+ *
+ * @v hermon Hermon device
+ * @v eqe Port management change event queue entry
+ */
+static void hermon_event_port_mgmnt_change ( struct hermon *hermon,
+ union hermonprm_event_entry *eqe){
+ unsigned int port;
+
+ /* Get port */
+ port = ( MLX_GET ( &eqe->port_mgmnt_change, port ) - 1 );
+ DBGC ( hermon, "Hermon %p port %d management change\n",
+ hermon, ( port + 1 ) );
+
+ /* Sanity check */
+ if ( port >= hermon->cap.num_ports ) {
+ DBGC ( hermon, "Hermon %p port %d does not exist!\n",
+ hermon, ( port + 1 ) );
+ return;
+ }
+
+ /* Update MAD parameters */
+ ib_smc_update ( hermon->port[port].ibdev, hermon_mad );
+}
+
+/**
* Poll event queue
*
* @v ibdev Infiniband device
@@ -2029,6 +2190,8 @@ static void hermon_poll_eq ( struct ib_device *ibdev ) {
struct hermon_event_queue *hermon_eq = &hermon->eq;
union hermonprm_event_entry *eqe;
union hermonprm_doorbell_register db_reg;
+ unsigned long now;
+ unsigned long elapsed;
unsigned int eqe_idx_mask;
unsigned int event_type;
@@ -2037,7 +2200,12 @@ static void hermon_poll_eq ( struct ib_device *ibdev ) {
*/
if ( ib_is_open ( ibdev ) &&
( ibdev->port_state == IB_PORT_STATE_DOWN ) ) {
- ib_smc_update ( ibdev, hermon_mad );
+ now = currticks();
+ elapsed = ( now - hermon->last_poll );
+ if ( elapsed >= HERMON_LINK_POLL_INTERVAL ) {
+ hermon->last_poll = now;
+ ib_smc_update ( ibdev, hermon_mad );
+ }
}
/* Poll event queue */
@@ -2061,10 +2229,14 @@ static void hermon_poll_eq ( struct ib_device *ibdev ) {
case HERMON_EV_PORT_STATE_CHANGE:
hermon_event_port_state_change ( hermon, eqe );
break;
+ case HERMON_EV_PORT_MGMNT_CHANGE:
+ hermon_event_port_mgmnt_change ( hermon, eqe );
+ break;
default:
DBGC ( hermon, "Hermon %p EQN %#lx unrecognised event "
- "type %#x:\n",
- hermon, hermon_eq->eqn, event_type );
+ "type %#02x:%#02x\n",
+ hermon, hermon_eq->eqn, event_type,
+ MLX_GET ( &eqe->generic, event_sub_type ) );
DBGC_HDA ( hermon, virt_to_phys ( eqe ),
eqe, sizeof ( *eqe ) );
break;
@@ -2202,6 +2374,8 @@ static int hermon_start_firmware ( struct hermon *hermon ) {
hermon->firmware_len = fw_len;
hermon->firmware_area = umalloc ( hermon->firmware_len );
if ( ! hermon->firmware_area ) {
+ DBGC ( hermon, "Hermon %p could not allocate firmware "
+ "area\n", hermon );
rc = -ENOMEM;
goto err_alloc_fa;
}
@@ -2569,6 +2743,8 @@ static int hermon_map_icm ( struct hermon *hermon,
hermon->icm_aux_len = icm_aux_len;
hermon->icm = umalloc ( hermon->icm_aux_len + hermon->icm_len );
if ( ! hermon->icm ) {
+ DBGC ( hermon, "Hermon %p could not allocate ICM\n",
+ hermon );
rc = -ENOMEM;
goto err_alloc;
}
@@ -2650,22 +2826,45 @@ static void hermon_unmap_icm ( struct hermon *hermon ) {
* Reset device
*
* @v hermon Hermon device
+ * @ret rc Return status code
*/
-static void hermon_reset ( struct hermon *hermon ) {
+static int hermon_reset ( struct hermon *hermon ) {
struct pci_device *pci = hermon->pci;
struct pci_config_backup backup;
static const uint8_t backup_exclude[] =
PCI_CONFIG_BACKUP_EXCLUDE ( 0x58, 0x5c );
+ uint16_t vendor;
+ unsigned int i;
+
+ /* Reset command interface toggle */
+ hermon->toggle = 0;
/* Perform device reset and preserve PCI configuration */
pci_backup ( pci, &backup, backup_exclude );
writel ( HERMON_RESET_MAGIC,
( hermon->config + HERMON_RESET_OFFSET ) );
- mdelay ( HERMON_RESET_WAIT_TIME_MS );
- pci_restore ( pci, &backup, backup_exclude );
- /* Reset command interface toggle */
- hermon->toggle = 0;
+ /* Wait until device starts responding to configuration cycles */
+ for ( i = 0 ; i < HERMON_RESET_MAX_WAIT_MS ; i++ ) {
+
+ /* Read PCI vendor ID */
+ pci_read_config_word ( pci, PCI_VENDOR_ID, &vendor );
+ if ( vendor == pci->vendor ) {
+
+ /* Restore PCI configuration */
+ pci_restore ( pci, &backup, backup_exclude );
+
+ DBGC ( hermon, "Hermon %p reset after %dms\n",
+ hermon, i );
+ return 0;
+ }
+
+ /* Delay */
+ mdelay ( 1 );
+ }
+
+ DBGC ( hermon, "Hermon %p timed out waiting for reset\n", hermon );
+ return -ETIMEDOUT;
}
/**
@@ -2709,6 +2908,25 @@ static int hermon_setup_mpt ( struct hermon *hermon ) {
}
/**
+ * Unmap memory protection table
+ *
+ * @v hermon Hermon device
+ * @ret rc Return status code
+ */
+static int hermon_unmap_mpt ( struct hermon *hermon ) {
+ int rc;
+
+ if ( ( rc = hermon_cmd_hw2sw_mpt ( hermon,
+ hermon->cap.reserved_mrws ) ) != 0 ){
+ DBGC ( hermon, "Hermon %p could not unmap MPT: %s\n",
+ hermon, strerror ( rc ) );
+ return rc;
+ }
+
+ return 0;
+}
+
+/**
* Configure special queue pairs
*
* @v hermon Hermon device
@@ -2784,11 +3002,13 @@ static int hermon_start ( struct hermon *hermon, int running ) {
if ( ( rc = hermon_configure_special_qps ( hermon ) ) != 0 )
goto err_conf_special_qps;
+ DBGC ( hermon, "Hermon %p device started\n", hermon );
return 0;
err_conf_special_qps:
hermon_destroy_eq ( hermon );
err_create_eq:
+ hermon_unmap_mpt ( hermon );
err_setup_mpt:
hermon_cmd_close_hca ( hermon );
err_init_hca:
@@ -2806,6 +3026,7 @@ static int hermon_start ( struct hermon *hermon, int running ) {
*/
static void hermon_stop ( struct hermon *hermon ) {
hermon_destroy_eq ( hermon );
+ hermon_unmap_mpt ( hermon );
hermon_cmd_close_hca ( hermon );
hermon_unmap_icm ( hermon );
hermon_stop_firmware ( hermon );
@@ -3080,6 +3301,9 @@ static int hermon_register_ibdev ( struct hermon *hermon,
struct ib_device *ibdev = port->ibdev;
int rc;
+ /* Use Ethernet MAC as eIPoIB local EMAC */
+ memcpy ( ibdev->lemac, port->eth_mac.raw, ETH_ALEN );
+
/* Initialise parameters using SMC */
ib_smc_init ( ibdev, hermon_mad );
@@ -3137,13 +3361,13 @@ static struct hermon_port_type hermon_port_type_ib = {
*/
/** Number of Hermon Ethernet send work queue entries */
-#define HERMON_ETH_NUM_SEND_WQES 2
+#define HERMON_ETH_NUM_SEND_WQES 16
/** Number of Hermon Ethernet receive work queue entries */
-#define HERMON_ETH_NUM_RECV_WQES 4
+#define HERMON_ETH_NUM_RECV_WQES 8
/** Number of Hermon Ethernet completion entries */
-#define HERMON_ETH_NUM_CQES 8
+#define HERMON_ETH_NUM_CQES 32
/**
* Transmit packet via Hermon Ethernet device
@@ -3396,24 +3620,10 @@ static int hermon_register_netdev ( struct hermon *hermon,
struct hermon_port *port ) {
struct net_device *netdev = port->netdev;
struct ib_device *ibdev = port->ibdev;
- struct hermonprm_query_port_cap query_port;
- union {
- uint8_t bytes[8];
- uint32_t dwords[2];
- } mac;
int rc;
- /* Retrieve MAC address */
- if ( ( rc = hermon_cmd_query_port ( hermon, ibdev->port,
- &query_port ) ) != 0 ) {
- DBGC ( hermon, "Hermon %p port %d could not query port: %s\n",
- hermon, ibdev->port, strerror ( rc ) );
- goto err_query_port;
- }
- mac.dwords[0] = htonl ( MLX_GET ( &query_port, mac_47_32 ) );
- mac.dwords[1] = htonl ( MLX_GET ( &query_port, mac_31_0 ) );
- memcpy ( netdev->hw_addr,
- &mac.bytes[ sizeof ( mac.bytes ) - ETH_ALEN ], ETH_ALEN );
+ /* Set MAC address */
+ memcpy ( netdev->hw_addr, port->eth_mac.raw, ETH_ALEN );
/* Register network device */
if ( ( rc = register_netdev ( netdev ) ) != 0 ) {
@@ -3437,7 +3647,6 @@ static int hermon_register_netdev ( struct hermon *hermon,
err_register_nvo:
unregister_netdev ( netdev );
err_register_netdev:
- err_query_port:
return rc;
}
@@ -3575,6 +3784,10 @@ static int hermon_set_port_type ( struct hermon *hermon,
( ( ib_supported && eth_supported ) ? " and" : "" ),
( eth_supported ? " Ethernet" : "" ) );
+ /* Record Ethernet MAC address */
+ port->eth_mac.part.h = htons ( MLX_GET ( &query_port, mac_47_32 ) );
+ port->eth_mac.part.l = htonl ( MLX_GET ( &query_port, mac_31_0 ) );
+
/* Sense network, if applicable */
if ( ib_supported && eth_supported ) {
@@ -3587,6 +3800,9 @@ static int hermon_set_port_type ( struct hermon *hermon,
rc = port_type;
return rc;
}
+
+ /* Avoid spamming debug output */
+ mdelay ( 50 );
} while ( ( port_type == HERMON_PORT_TYPE_UNKNOWN ) &&
( ( elapsed = ( currticks() - start ) ) <
HERMON_SENSE_PORT_TIMEOUT ) );
@@ -3736,20 +3952,20 @@ static struct hermon * hermon_alloc ( void ) {
goto err_hermon;
/* Allocate space for mailboxes */
- hermon->mailbox_in = malloc_dma ( HERMON_MBOX_SIZE,
- HERMON_MBOX_ALIGN );
+ hermon->mailbox_in = malloc_phys ( HERMON_MBOX_SIZE,
+ HERMON_MBOX_ALIGN );
if ( ! hermon->mailbox_in )
goto err_mailbox_in;
- hermon->mailbox_out = malloc_dma ( HERMON_MBOX_SIZE,
- HERMON_MBOX_ALIGN );
+ hermon->mailbox_out = malloc_phys ( HERMON_MBOX_SIZE,
+ HERMON_MBOX_ALIGN );
if ( ! hermon->mailbox_out )
goto err_mailbox_out;
return hermon;
- free_dma ( hermon->mailbox_out, HERMON_MBOX_SIZE );
+ free_phys ( hermon->mailbox_out, HERMON_MBOX_SIZE );
err_mailbox_out:
- free_dma ( hermon->mailbox_in, HERMON_MBOX_SIZE );
+ free_phys ( hermon->mailbox_in, HERMON_MBOX_SIZE );
err_mailbox_in:
free ( hermon );
err_hermon:
@@ -3765,8 +3981,8 @@ static void hermon_free ( struct hermon *hermon ) {
ufree ( hermon->icm );
ufree ( hermon->firmware_area );
- free_dma ( hermon->mailbox_out, HERMON_MBOX_SIZE );
- free_dma ( hermon->mailbox_in, HERMON_MBOX_SIZE );
+ free_phys ( hermon->mailbox_out, HERMON_MBOX_SIZE );
+ free_phys ( hermon->mailbox_in, HERMON_MBOX_SIZE );
free ( hermon );
}
@@ -3782,6 +3998,8 @@ static int hermon_probe ( struct pci_device *pci ) {
struct ib_device *ibdev;
struct net_device *netdev;
struct hermon_port *port;
+ unsigned long config;
+ unsigned long uar;
unsigned int i;
int rc;
@@ -3798,13 +4016,16 @@ static int hermon_probe ( struct pci_device *pci ) {
adjust_pci_device ( pci );
/* Map PCI BARs */
- hermon->config = ioremap ( pci_bar_start ( pci, HERMON_PCI_CONFIG_BAR ),
- HERMON_PCI_CONFIG_BAR_SIZE );
- hermon->uar = ioremap ( pci_bar_start ( pci, HERMON_PCI_UAR_BAR ),
- HERMON_UAR_NON_EQ_PAGE * HERMON_PAGE_SIZE );
+ config = pci_bar_start ( pci, HERMON_PCI_CONFIG_BAR );
+ hermon->config = pci_ioremap ( pci, config,
+ HERMON_PCI_CONFIG_BAR_SIZE );
+ uar = pci_bar_start ( pci, HERMON_PCI_UAR_BAR );
+ hermon->uar = pci_ioremap ( pci, uar,
+ HERMON_UAR_NON_EQ_PAGE * HERMON_PAGE_SIZE );
/* Reset device */
- hermon_reset ( hermon );
+ if ( ( rc = hermon_reset ( hermon ) ) != 0 )
+ goto err_reset;
/* Start firmware */
if ( ( rc = hermon_start_firmware ( hermon ) ) != 0 )
@@ -3816,7 +4037,7 @@ static int hermon_probe ( struct pci_device *pci ) {
/* Allocate Infiniband devices */
for ( i = 0 ; i < hermon->cap.num_ports ; i++ ) {
- ibdev = alloc_ibdev ( 0 );
+ ibdev = alloc_ibdev ( 0 );
if ( ! ibdev ) {
rc = -ENOMEM;
goto err_alloc_ibdev;
@@ -3825,6 +4046,7 @@ static int hermon_probe ( struct pci_device *pci ) {
ibdev->op = &hermon_ib_operations;
ibdev->dev = &pci->dev;
ibdev->port = ( HERMON_PORT_BASE + i );
+ ibdev->ports = hermon->cap.num_ports;
ib_set_drvdata ( ibdev, hermon );
}
@@ -3896,6 +4118,7 @@ static int hermon_probe ( struct pci_device *pci ) {
err_get_cap:
hermon_stop_firmware ( hermon );
err_start_firmware:
+ err_reset:
iounmap ( hermon->uar );
iounmap ( hermon->config );
hermon_free ( hermon );
@@ -3937,6 +4160,7 @@ static void hermon_remove ( struct pci_device *pci ) {
*/
static int hermon_bofm_probe ( struct pci_device *pci ) {
struct hermon *hermon;
+ unsigned long config;
int rc;
/* Allocate Hermon device */
@@ -3952,8 +4176,9 @@ static int hermon_bofm_probe ( struct pci_device *pci ) {
adjust_pci_device ( pci );
/* Map PCI BAR */
- hermon->config = ioremap ( pci_bar_start ( pci, HERMON_PCI_CONFIG_BAR ),
- HERMON_PCI_CONFIG_BAR_SIZE );
+ config = pci_bar_start ( pci, HERMON_PCI_CONFIG_BAR );
+ hermon->config = pci_ioremap ( pci, config,
+ HERMON_PCI_CONFIG_BAR_SIZE );
/* Initialise BOFM device */
bofm_init ( &hermon->bofm, pci, &hermon_bofm_operations );
@@ -3988,18 +4213,29 @@ static void hermon_bofm_remove ( struct pci_device *pci ) {
}
static struct pci_device_id hermon_nics[] = {
+ /* Mellanox ConnectX VPI (ethernet + infiniband) */
PCI_ROM ( 0x15b3, 0x6340, "mt25408", "MT25408 HCA driver", 0 ),
PCI_ROM ( 0x15b3, 0x634a, "mt25418", "MT25418 HCA driver", 0 ),
+
+ /* Mellanox ConnectX EN (ethernet only) */
+ PCI_ROM ( 0x15b3, 0x6368, "mt25448", "MT25448 HCA driver", 0 ),
+ PCI_ROM ( 0x15b3, 0x6372, "mt25458", "MT25458 HCA driver", 0 ),
+
+ /* Mellanox ConnectX-2 VPI (ethernet + infiniband) */
PCI_ROM ( 0x15b3, 0x6732, "mt26418", "MT26418 HCA driver", 0 ),
PCI_ROM ( 0x15b3, 0x673c, "mt26428", "MT26428 HCA driver", 0 ),
PCI_ROM ( 0x15b3, 0x6746, "mt26438", "MT26438 HCA driver", 0 ),
PCI_ROM ( 0x15b3, 0x6778, "mt26488", "MT26488 HCA driver", 0 ),
- PCI_ROM ( 0x15b3, 0x6368, "mt25448", "MT25448 HCA driver", 0 ),
+
+ /* Mellanox ConnectX-2 EN (ethernet only) */
PCI_ROM ( 0x15b3, 0x6750, "mt26448", "MT26448 HCA driver", 0 ),
- PCI_ROM ( 0x15b3, 0x6372, "mt25458", "MT25458 HCA driver", 0 ),
PCI_ROM ( 0x15b3, 0x675a, "mt26458", "MT26458 HCA driver", 0 ),
PCI_ROM ( 0x15b3, 0x6764, "mt26468", "MT26468 HCA driver", 0 ),
PCI_ROM ( 0x15b3, 0x676e, "mt26478", "MT26478 HCA driver", 0 ),
+
+ /* Mellanox ConnectX-3 VPI (ethernet + infiniband) */
+ PCI_ROM ( 0x15b3, 0x1003, "mt4099", "ConnectX-3 HCA driver", 0 ),
+ PCI_ROM ( 0x15b3, 0x1007, "mt4103", "ConnectX-3 Pro HCA driver", 0 ),
};
struct pci_driver hermon_driver __pci_driver = {
diff --git a/src/drivers/infiniband/hermon.h b/src/drivers/infiniband/hermon.h
index 61e285781..a952bbd81 100644
--- a/src/drivers/infiniband/hermon.h
+++ b/src/drivers/infiniband/hermon.h
@@ -34,8 +34,8 @@ FILE_LICENCE ( GPL2_OR_LATER );
/* Device reset */
#define HERMON_RESET_OFFSET 0x0f0010
-#define HERMON_RESET_MAGIC 0x01000000UL
-#define HERMON_RESET_WAIT_TIME_MS 1000
+#define HERMON_RESET_MAGIC 0x01000001UL
+#define HERMON_RESET_MAX_WAIT_MS 1000
/* Work queue entry and completion queue entry opcodes */
#define HERMON_OPCODE_NOP 0x00
@@ -52,6 +52,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
#define HERMON_HCR_CLOSE_PORT 0x000a
#define HERMON_HCR_SET_PORT 0x000c
#define HERMON_HCR_SW2HW_MPT 0x000d
+#define HERMON_HCR_HW2SW_MPT 0x000f
#define HERMON_HCR_WRITE_MTT 0x0011
#define HERMON_HCR_MAP_EQ 0x0012
#define HERMON_HCR_SW2HW_EQ 0x0013
@@ -122,6 +123,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
#define HERMON_SET_PORT_GID_TABLE 0x0500
#define HERMON_EV_PORT_STATE_CHANGE 0x09
+#define HERMON_EV_PORT_MGMNT_CHANGE 0x1d
#define HERMON_SCHED_QP0 0x3f
#define HERMON_SCHED_DEFAULT 0x83
@@ -216,6 +218,13 @@ struct hermonprm_port_state_change_event_st {
struct hermonprm_port_state_change_st data;
} __attribute__ (( packed ));
+struct hermonprm_port_mgmnt_change_event_st {
+ pseudo_bit_t reserved[0x00020];
+/* -------------- */
+ pseudo_bit_t port[0x00008];
+ pseudo_bit_t reserved0[0x00018];
+} __attribute__ (( packed ));
+
struct hermonprm_sense_port_st {
pseudo_bit_t reserved0[0x00020];
/* -------------- */
@@ -459,6 +468,7 @@ struct MLX_DECLARE_STRUCT ( hermonprm_mod_stat_cfg_input_mod );
struct MLX_DECLARE_STRUCT ( hermonprm_mpt );
struct MLX_DECLARE_STRUCT ( hermonprm_mtt );
struct MLX_DECLARE_STRUCT ( hermonprm_port_state_change_event );
+struct MLX_DECLARE_STRUCT ( hermonprm_port_mgmnt_change_event );
struct MLX_DECLARE_STRUCT ( hermonprm_qp_db_record );
struct MLX_DECLARE_STRUCT ( hermonprm_qp_ee_state_transitions );
struct MLX_DECLARE_STRUCT ( hermonprm_query_dev_cap );
@@ -529,6 +539,7 @@ union hermonprm_completion_entry {
union hermonprm_event_entry {
struct hermonprm_event_queue_entry generic;
struct hermonprm_port_state_change_event port_state_change;
+ struct hermonprm_port_mgmnt_change_event port_mgmnt_change;
} __attribute__ (( packed ));
union hermonprm_doorbell_register {
@@ -822,6 +833,15 @@ struct hermon_port_type {
struct hermon_port *port );
};
+/** A Hermon port Ethernet MAC address */
+union hermon_port_mac {
+ struct {
+ uint16_t h;
+ uint32_t l;
+ } __attribute__ (( packed )) part;
+ uint8_t raw[ETH_ALEN];
+};
+
/** A Hermon port */
struct hermon_port {
/** Infiniband device */
@@ -832,6 +852,8 @@ struct hermon_port {
struct ib_completion_queue *eth_cq;
/** Ethernet queue pair */
struct ib_queue_pair *eth_qp;
+ /** Ethernet MAC */
+ union hermon_port_mac eth_mac;
/** Port type */
struct hermon_port_type *type;
/** Non-volatile option storage */
@@ -882,6 +904,8 @@ struct hermon {
/** Event queue */
struct hermon_event_queue eq;
+ /** Last unsolicited link state poll */
+ unsigned long last_poll;
/** Unrestricted LKey
*
* Used to get unrestricted memory access.
@@ -918,6 +942,13 @@ struct hermon {
/** Memory key prefix */
#define HERMON_MKEY_PREFIX 0x77000000UL
+/** Link poll interval
+ *
+ * Used when we need to poll for link state (rather than relying upon
+ * receiving an event).
+ */
+#define HERMON_LINK_POLL_INTERVAL ( TICKS_PER_SEC / 2 )
+
/*
* HCA commands
*
@@ -925,7 +956,7 @@ struct hermon {
#define HERMON_HCR_BASE 0x80680
#define HERMON_HCR_REG(x) ( HERMON_HCR_BASE + 4 * (x) )
-#define HERMON_HCR_MAX_WAIT_MS 2000
+#define HERMON_HCR_MAX_WAIT_MS 10000
#define HERMON_MBOX_ALIGN 4096
#define HERMON_MBOX_SIZE 1024
diff --git a/src/drivers/infiniband/linda.c b/src/drivers/infiniband/linda.c
index e8d61c865..8c5912660 100644
--- a/src/drivers/infiniband/linda.c
+++ b/src/drivers/infiniband/linda.c
@@ -531,8 +531,8 @@ static int linda_init_send ( struct linda *linda ) {
linda->send_buf[i] = i;
/* Allocate space for the SendBufAvail array */
- linda->sendbufavail = malloc_dma ( sizeof ( *linda->sendbufavail ),
- LINDA_SENDBUFAVAIL_ALIGN );
+ linda->sendbufavail = malloc_phys ( sizeof ( *linda->sendbufavail ),
+ LINDA_SENDBUFAVAIL_ALIGN );
if ( ! linda->sendbufavail ) {
rc = -ENOMEM;
goto err_alloc_sendbufavail;
@@ -555,7 +555,7 @@ static int linda_init_send ( struct linda *linda ) {
return 0;
- free_dma ( linda->sendbufavail, sizeof ( *linda->sendbufavail ) );
+ free_phys ( linda->sendbufavail, sizeof ( *linda->sendbufavail ) );
err_alloc_sendbufavail:
return rc;
}
@@ -576,7 +576,7 @@ static void linda_fini_send ( struct linda *linda ) {
/* Ensure hardware has seen this disable */
linda_readq ( linda, &sendctrl, QIB_7220_SendCtrl_offset );
- free_dma ( linda->sendbufavail, sizeof ( *linda->sendbufavail ) );
+ free_phys ( linda->sendbufavail, sizeof ( *linda->sendbufavail ) );
}
/***************************************************************************
@@ -613,8 +613,8 @@ static int linda_create_recv_wq ( struct linda *linda,
linda_wq->eager_cons = 0;
/* Allocate receive header buffer */
- linda_wq->header = malloc_dma ( LINDA_RECV_HEADERS_SIZE,
- LINDA_RECV_HEADERS_ALIGN );
+ linda_wq->header = malloc_phys ( LINDA_RECV_HEADERS_SIZE,
+ LINDA_RECV_HEADERS_ALIGN );
if ( ! linda_wq->header ) {
rc = -ENOMEM;
goto err_alloc_header;
@@ -650,7 +650,7 @@ static int linda_create_recv_wq ( struct linda *linda,
virt_to_bus ( &linda_wq->header_prod ) );
return 0;
- free_dma ( linda_wq->header, LINDA_RECV_HEADERS_SIZE );
+ free_phys ( linda_wq->header, LINDA_RECV_HEADERS_SIZE );
err_alloc_header:
return rc;
}
@@ -679,7 +679,7 @@ static void linda_destroy_recv_wq ( struct linda *linda,
mb();
/* Free headers ring */
- free_dma ( linda_wq->header, LINDA_RECV_HEADERS_SIZE );
+ free_phys ( linda_wq->header, LINDA_RECV_HEADERS_SIZE );
/* Free context */
linda_free_ctx ( linda, ctx );
@@ -2330,12 +2330,13 @@ static int linda_probe ( struct pci_device *pci ) {
ibdev->op = &linda_ib_operations;
ibdev->dev = &pci->dev;
ibdev->port = 1;
+ ibdev->ports = 1;
/* Fix up PCI device */
adjust_pci_device ( pci );
/* Map PCI BARs */
- linda->regs = ioremap ( pci->membase, LINDA_BAR0_SIZE );
+ linda->regs = pci_ioremap ( pci, pci->membase, LINDA_BAR0_SIZE );
DBGC2 ( linda, "Linda %p has BAR at %08lx\n", linda, pci->membase );
/* Print some general data */
diff --git a/src/drivers/infiniband/mlx_utils_flexboot/src/mlx_memory_priv.c b/src/drivers/infiniband/mlx_utils_flexboot/src/mlx_memory_priv.c
index cb9e759bf..e368d459b 100644
--- a/src/drivers/infiniband/mlx_utils_flexboot/src/mlx_memory_priv.c
+++ b/src/drivers/infiniband/mlx_utils_flexboot/src/mlx_memory_priv.c
@@ -61,7 +61,7 @@ mlx_memory_alloc_dma_priv(
)
{
mlx_status status = MLX_SUCCESS;
- *ptr = malloc_dma(size, align);
+ *ptr = malloc_phys(size, align);
if (*ptr == NULL) {
status = MLX_OUT_OF_RESOURCES;
} else {
@@ -78,7 +78,7 @@ mlx_memory_free_dma_priv(
)
{
mlx_status status = MLX_SUCCESS;
- free_dma(ptr, size);
+ free_phys(ptr, size);
return status;
}
mlx_status
diff --git a/src/drivers/infiniband/mlx_utils_flexboot/src/mlx_pci_priv.c b/src/drivers/infiniband/mlx_utils_flexboot/src/mlx_pci_priv.c
index b474a4a63..6b42bcafc 100644
--- a/src/drivers/infiniband/mlx_utils_flexboot/src/mlx_pci_priv.c
+++ b/src/drivers/infiniband/mlx_utils_flexboot/src/mlx_pci_priv.c
@@ -115,7 +115,7 @@ mlx_pci_init_priv(
mlx_status status = MLX_SUCCESS;
adjust_pci_device ( utils->pci );
#ifdef DEVICE_CX3
- utils->config = ioremap ( pci_bar_start ( utils->pci, PCI_BASE_ADDRESS_0),
+ utils->config = pci_ioremap ( utils->pci, pci_bar_start ( utils->pci, PCI_BASE_ADDRESS_0),
0x100000 );
#endif
return status;
diff --git a/src/drivers/infiniband/nodnic_prm.h b/src/drivers/infiniband/nodnic_prm.h
index 5e0fa9890..a962c821c 100644
--- a/src/drivers/infiniband/nodnic_prm.h
+++ b/src/drivers/infiniband/nodnic_prm.h
@@ -38,10 +38,10 @@ struct nodnic_wqe_segment_data_ptr_st { /* Little Endian */
struct MLX_DECLARE_STRUCT ( nodnic_wqe_segment_data_ptr );
-#define HERMON_MAX_SCATTER 1
+#define NODNIC_MAX_SCATTER 1
struct nodnic_recv_wqe {
- struct nodnic_wqe_segment_data_ptr data[HERMON_MAX_SCATTER];
+ struct nodnic_wqe_segment_data_ptr data[NODNIC_MAX_SCATTER];
} __attribute__ (( packed ));
#endif /* SRC_DRIVERS_INFINIBAND_MLX_NODNIC_INCLUDE_PRM_NODNIC_PRM_H_ */
diff --git a/src/drivers/infiniband/qib7322.c b/src/drivers/infiniband/qib7322.c
index 18011c19a..a4b51db05 100644
--- a/src/drivers/infiniband/qib7322.c
+++ b/src/drivers/infiniband/qib7322.c
@@ -669,8 +669,8 @@ static int qib7322_init_send ( struct qib7322 *qib7322 ) {
}
/* Allocate space for the SendBufAvail array */
- qib7322->sendbufavail = malloc_dma ( sizeof ( *qib7322->sendbufavail ),
- QIB7322_SENDBUFAVAIL_ALIGN );
+ qib7322->sendbufavail = malloc_phys ( sizeof ( *qib7322->sendbufavail ),
+ QIB7322_SENDBUFAVAIL_ALIGN );
if ( ! qib7322->sendbufavail ) {
rc = -ENOMEM;
goto err_alloc_sendbufavail;
@@ -697,7 +697,7 @@ static int qib7322_init_send ( struct qib7322 *qib7322 ) {
return 0;
- free_dma ( qib7322->sendbufavail, sizeof ( *qib7322->sendbufavail ) );
+ free_phys ( qib7322->sendbufavail, sizeof ( *qib7322->sendbufavail ) );
err_alloc_sendbufavail:
qib7322_destroy_send_bufs ( qib7322, qib7322->send_bufs_vl15_port1 );
err_create_send_bufs_vl15_port1:
@@ -724,7 +724,7 @@ static void qib7322_fini_send ( struct qib7322 *qib7322 ) {
/* Ensure hardware has seen this disable */
qib7322_readq ( qib7322, &sendctrl, QIB_7322_SendCtrl_offset );
- free_dma ( qib7322->sendbufavail, sizeof ( *qib7322->sendbufavail ) );
+ free_phys ( qib7322->sendbufavail, sizeof ( *qib7322->sendbufavail ) );
qib7322_destroy_send_bufs ( qib7322, qib7322->send_bufs_vl15_port1 );
qib7322_destroy_send_bufs ( qib7322, qib7322->send_bufs_vl15_port0 );
qib7322_destroy_send_bufs ( qib7322, qib7322->send_bufs_small );
@@ -767,8 +767,8 @@ static int qib7322_create_recv_wq ( struct ib_device *ibdev,
qib7322_wq->eager_cons = 0;
/* Allocate receive header buffer */
- qib7322_wq->header = malloc_dma ( QIB7322_RECV_HEADERS_SIZE,
- QIB7322_RECV_HEADERS_ALIGN );
+ qib7322_wq->header = malloc_phys ( QIB7322_RECV_HEADERS_SIZE,
+ QIB7322_RECV_HEADERS_ALIGN );
if ( ! qib7322_wq->header ) {
rc = -ENOMEM;
goto err_alloc_header;
@@ -810,7 +810,7 @@ static int qib7322_create_recv_wq ( struct ib_device *ibdev,
virt_to_bus ( &qib7322_wq->header_prod ) );
return 0;
- free_dma ( qib7322_wq->header, QIB7322_RECV_HEADERS_SIZE );
+ free_phys ( qib7322_wq->header, QIB7322_RECV_HEADERS_SIZE );
err_alloc_header:
return rc;
}
@@ -846,7 +846,7 @@ static void qib7322_destroy_recv_wq ( struct ib_device *ibdev,
mb();
/* Free headers ring */
- free_dma ( qib7322_wq->header, QIB7322_RECV_HEADERS_SIZE );
+ free_phys ( qib7322_wq->header, QIB7322_RECV_HEADERS_SIZE );
}
/**
@@ -2297,7 +2297,7 @@ static int qib7322_probe ( struct pci_device *pci ) {
adjust_pci_device ( pci );
/* Map PCI BARs */
- qib7322->regs = ioremap ( pci->membase, QIB7322_BAR0_SIZE );
+ qib7322->regs = pci_ioremap ( pci, pci->membase, QIB7322_BAR0_SIZE );
DBGC2 ( qib7322, "QIB7322 %p has BAR at %08lx\n",
qib7322, pci->membase );
@@ -2348,6 +2348,7 @@ static int qib7322_probe ( struct pci_device *pci ) {
ibdev->dev = &pci->dev;
ibdev->op = &qib7322_ib_operations;
ibdev->port = ( QIB7322_PORT_BASE + i );
+ ibdev->ports = QIB7322_MAX_PORTS;
ibdev->link_width_enabled = ibdev->link_width_supported =
IB_LINK_WIDTH_4X; /* 1x does not work */
ibdev->link_speed_enabled = ibdev->link_speed_supported =
diff --git a/src/drivers/linux/af_packet.c b/src/drivers/linux/af_packet.c
index 65aafc5b1..9fa6ef2a5 100644
--- a/src/drivers/linux/af_packet.c
+++ b/src/drivers/linux/af_packet.c
@@ -19,7 +19,7 @@
#include <errno.h>
#include <string.h>
#include <stdio.h>
-#include <linux_api.h>
+#include <ipxe/linux_api.h>
#include <ipxe/list.h>
#include <ipxe/linux.h>
#include <ipxe/malloc.h>
diff --git a/src/drivers/linux/linux.c b/src/drivers/linux/linux.c
index 83546b27e..898f50024 100644
--- a/src/drivers/linux/linux.c
+++ b/src/drivers/linux/linux.c
@@ -130,24 +130,48 @@ struct linux_setting *linux_find_setting(char *name, struct list_head *settings)
return result;
}
-void linux_apply_settings(struct list_head *new_settings, struct settings *settings_block)
-{
- struct linux_setting *setting;
+/**
+ * Apply Linux command-line settings
+ *
+ * @v list List of command-line settings
+ * @v settings Settings block
+ */
+void linux_apply_settings ( struct list_head *list,
+ struct settings *settings ) {
+ struct linux_setting *lsetting;
+ struct settings *ignore;
+ struct setting setting;
int rc;
- list_for_each_entry(setting, new_settings, list) {
+ list_for_each_entry ( lsetting, list, list ) {
+
/* Skip already applied settings */
- if (setting->applied)
+ if ( lsetting->applied )
continue;
- struct setting *s = find_setting(setting->name);
- if (s) {
- rc = storef_setting(settings_block, find_setting(setting->name), setting->value);
- if (rc != 0)
- DBG("linux storing setting '%s' = '%s' failed\n", setting->name, setting->value);
- setting->applied = 1;
- } else {
- DBG("linux unknown setting '%s'\n", setting->name);
+ /* Parse setting name */
+ if ( ( rc = parse_setting_name ( lsetting->name,
+ find_child_settings, &ignore,
+ &setting ) ) != 0 ) {
+ DBGC ( settings, "Linux cannot parse %s: %s\n",
+ lsetting->name, strerror ( rc ) );
+ continue;
+ }
+
+ /* Apply default type if not specified */
+ if ( ! setting.type )
+ setting.type = &setting_type_string;
+
+ /* Store setting */
+ if ( ( rc = storef_setting ( settings, &setting,
+ lsetting->value ) ) != 0 ) {
+ DBGC ( settings, "Linux cannot set %s=\"%s\": %s\n",
+ lsetting->name, lsetting->value,
+ strerror ( rc ) );
+ continue;
}
+
+ /* Mark setting as applied */
+ lsetting->applied = 1;
}
}
diff --git a/src/drivers/linux/slirp.c b/src/drivers/linux/slirp.c
new file mode 100644
index 000000000..8341c9676
--- /dev/null
+++ b/src/drivers/linux/slirp.c
@@ -0,0 +1,552 @@
+/*
+ * Copyright (C) 2021 Michael Brown <mbrown@fensystems.co.uk>.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <ipxe/netdevice.h>
+#include <ipxe/ethernet.h>
+#include <ipxe/if_ether.h>
+#include <ipxe/in.h>
+#include <ipxe/timer.h>
+#include <ipxe/retry.h>
+#include <ipxe/linux.h>
+#include <ipxe/linux_api.h>
+#include <ipxe/slirp.h>
+
+/** @file
+ *
+ * Linux Slirp network driver
+ *
+ */
+
+/** Maximum number of open file descriptors */
+#define SLIRP_MAX_FDS 128
+
+/** A Slirp network interface */
+struct slirp_nic {
+ /** The libslirp device object */
+ struct Slirp *slirp;
+ /** Polling file descriptor list */
+ struct pollfd pollfds[SLIRP_MAX_FDS];
+ /** Number of file descriptors */
+ unsigned int numfds;
+};
+
+/** A Slirp alarm timer */
+struct slirp_alarm {
+ /** Slirp network interface */
+ struct slirp_nic *slirp;
+ /** Retry timer */
+ struct retry_timer timer;
+ /** Callback function */
+ void ( __asmcall * callback ) ( void *opaque );
+ /** Opaque value for callback function */
+ void *opaque;
+};
+
+/** Default MAC address */
+static const uint8_t slirp_default_mac[ETH_ALEN] =
+ { 0x52, 0x54, 0x00, 0x12, 0x34, 0x56 };
+
+/******************************************************************************
+ *
+ * Slirp interface
+ *
+ ******************************************************************************
+ */
+
+/**
+ * Send packet
+ *
+ * @v buf Data buffer
+ * @v len Length of data
+ * @v device Device opaque pointer
+ * @ret len Consumed length (or negative on error)
+ */
+static ssize_t __asmcall slirp_send_packet ( const void *buf, size_t len,
+ void *device ) {
+ struct net_device *netdev = device;
+ struct io_buffer *iobuf;
+
+ /* Allocate I/O buffer */
+ iobuf = alloc_iob ( len );
+ if ( ! iobuf )
+ return -1;
+
+ /* Populate I/O buffer */
+ memcpy ( iob_put ( iobuf, len ), buf, len );
+
+ /* Hand off to network stack */
+ netdev_rx ( netdev, iobuf );
+
+ return len;
+}
+
+/**
+ * Print an error message
+ *
+ * @v msg Error message
+ * @v device Device opaque pointer
+ */
+static void __asmcall slirp_guest_error ( const char *msg, void *device ) {
+ struct net_device *netdev = device;
+ struct slirp_nic *slirp = netdev->priv;
+
+ DBGC ( slirp, "SLIRP %p error: %s\n", slirp, msg );
+}
+
+/**
+ * Get virtual clock
+ *
+ * @v device Device opaque pointer
+ * @ret clock_ns Clock time in nanoseconds
+ */
+static int64_t __asmcall slirp_clock_get_ns ( void *device __unused ) {
+ int64_t time;
+
+ time = currticks();
+ return ( time * ( 1000000 / TICKS_PER_MS ) );
+}
+
+/**
+ * Handle timer expiry
+ *
+ * @v timer Retry timer
+ * @v over Failure indicator
+ */
+static void slirp_expired ( struct retry_timer *timer, int over __unused ) {
+ struct slirp_alarm *alarm =
+ container_of ( timer, struct slirp_alarm, timer );
+ struct slirp_nic *slirp = alarm->slirp;
+
+ /* Notify callback */
+ DBGC ( slirp, "SLIRP %p timer fired\n", slirp );
+ alarm->callback ( alarm->opaque );
+}
+
+/**
+ * Create a new timer
+ *
+ * @v callback Timer callback
+ * @v opaque Timer opaque pointer
+ * @v device Device opaque pointer
+ * @ret timer Timer
+ */
+static void * __asmcall
+slirp_timer_new ( void ( __asmcall * callback ) ( void *opaque ),
+ void *opaque, void *device ) {
+ struct net_device *netdev = device;
+ struct slirp_nic *slirp = netdev->priv;
+ struct slirp_alarm *alarm;
+
+ /* Allocate timer */
+ alarm = malloc ( sizeof ( *alarm ) );
+ if ( ! alarm ) {
+ DBGC ( slirp, "SLIRP %p could not allocate timer\n", slirp );
+ return NULL;
+ }
+
+ /* Initialise timer */
+ memset ( alarm, 0, sizeof ( *alarm ) );
+ alarm->slirp = slirp;
+ timer_init ( &alarm->timer, slirp_expired, NULL );
+ alarm->callback = callback;
+ alarm->opaque = opaque;
+ DBGC ( slirp, "SLIRP %p timer %p has callback %p (%p)\n",
+ slirp, alarm, alarm->callback, alarm->opaque );
+
+ return alarm;
+}
+
+/**
+ * Delete a timer
+ *
+ * @v timer Timer
+ * @v device Device opaque pointer
+ */
+static void __asmcall slirp_timer_free ( void *timer, void *device ) {
+ struct net_device *netdev = device;
+ struct slirp_nic *slirp = netdev->priv;
+ struct slirp_alarm *alarm = timer;
+
+ /* Ignore timers that failed to allocate */
+ if ( ! alarm )
+ return;
+
+ /* Stop timer */
+ stop_timer ( &alarm->timer );
+
+ /* Free timer */
+ free ( alarm );
+ DBGC ( slirp, "SLIRP %p timer %p freed\n", slirp, alarm );
+}
+
+/**
+ * Set timer expiry time
+ *
+ * @v timer Timer
+ * @v expire Expiry time
+ * @v device Device opaque pointer
+ */
+static void __asmcall slirp_timer_mod ( void *timer, int64_t expire,
+ void *device ) {
+ struct net_device *netdev = device;
+ struct slirp_nic *slirp = netdev->priv;
+ struct slirp_alarm *alarm = timer;
+ int64_t timeout_ms;
+ unsigned long timeout;
+
+ /* Ignore timers that failed to allocate */
+ if ( ! alarm )
+ return;
+
+ /* (Re)start timer */
+ timeout_ms = ( expire - ( currticks() / TICKS_PER_MS ) );
+ if ( timeout_ms < 0 )
+ timeout_ms = 0;
+ timeout = ( timeout_ms * TICKS_PER_MS );
+ start_timer_fixed ( &alarm->timer, timeout );
+ DBGC ( slirp, "SLIRP %p timer %p set for %ld ticks\n",
+ slirp, alarm, timeout );
+}
+
+/**
+ * Register file descriptor for polling
+ *
+ * @v fd File descriptor
+ * @v device Device opaque pointer
+ */
+static void __asmcall slirp_register_poll_fd ( int fd, void *device ) {
+ struct net_device *netdev = device;
+ struct slirp_nic *slirp = netdev->priv;
+
+ DBGC ( slirp, "SLIRP %p registered FD %d\n", slirp, fd );
+}
+
+/**
+ * Unregister file descriptor
+ *
+ * @v fd File descriptor
+ * @v device Device opaque pointer
+ */
+static void __asmcall slirp_unregister_poll_fd ( int fd, void *device ) {
+ struct net_device *netdev = device;
+ struct slirp_nic *slirp = netdev->priv;
+
+ DBGC ( slirp, "SLIRP %p unregistered FD %d\n", slirp, fd );
+}
+
+/**
+ * Notify that new events are ready
+ *
+ * @v device Device opaque pointer
+ */
+static void __asmcall slirp_notify ( void *device ) {
+ struct net_device *netdev = device;
+ struct slirp_nic *slirp = netdev->priv;
+
+ DBGC2 ( slirp, "SLIRP %p notified\n", slirp );
+}
+
+/** Slirp callbacks */
+static struct slirp_callbacks slirp_callbacks = {
+ .send_packet = slirp_send_packet,
+ .guest_error = slirp_guest_error,
+ .clock_get_ns = slirp_clock_get_ns,
+ .timer_new = slirp_timer_new,
+ .timer_free = slirp_timer_free,
+ .timer_mod = slirp_timer_mod,
+ .register_poll_fd = slirp_register_poll_fd,
+ .unregister_poll_fd = slirp_unregister_poll_fd,
+ .notify = slirp_notify,
+};
+
+/******************************************************************************
+ *
+ * Network device interface
+ *
+ ******************************************************************************
+ */
+
+/**
+ * Open network device
+ *
+ * @v netdev Network device
+ * @ret rc Return status code
+ */
+static int slirp_open ( struct net_device *netdev ) {
+ struct slirp_nic *slirp = netdev->priv;
+
+ /* Nothing to do */
+ DBGC ( slirp, "SLIRP %p opened\n", slirp );
+
+ return 0;
+}
+
+/**
+ * Close network device
+ *
+ * @v netdev Network device
+ */
+static void slirp_close ( struct net_device *netdev ) {
+ struct slirp_nic *slirp = netdev->priv;
+
+ /* Nothing to do */
+ DBGC ( slirp, "SLIRP %p closed\n", slirp );
+}
+
+/**
+ * Transmit packet
+ *
+ * @v netdev Network device
+ * @v iobuf I/O buffer
+ * @ret rc Return status code
+ */
+static int slirp_transmit ( struct net_device *netdev,
+ struct io_buffer *iobuf ) {
+ struct slirp_nic *slirp = netdev->priv;
+
+ /* Transmit packet */
+ linux_slirp_input ( slirp->slirp, iobuf->data, iob_len ( iobuf ) );
+ netdev_tx_complete ( netdev, iobuf );
+
+ return 0;
+}
+
+/**
+ * Add polling file descriptor
+ *
+ * @v fd File descriptor
+ * @v events Events of interest
+ * @v device Device opaque pointer
+ * @ret index File descriptor index
+ */
+static int __asmcall slirp_add_poll ( int fd, int events, void *device ) {
+ struct net_device *netdev = device;
+ struct slirp_nic *slirp = netdev->priv;
+ struct pollfd *pollfd;
+ unsigned int index;
+
+ /* Fail if too many descriptors are registered */
+ if ( slirp->numfds >= SLIRP_MAX_FDS ) {
+ DBGC ( slirp, "SLIRP %p too many file descriptors\n", slirp );
+ return -1;
+ }
+
+ /* Populate polling file descriptor */
+ index = slirp->numfds++;
+ pollfd = &slirp->pollfds[index];
+ pollfd->fd = fd;
+ pollfd->events = 0;
+ if ( events & SLIRP_EVENT_IN )
+ pollfd->events |= POLLIN;
+ if ( events & SLIRP_EVENT_OUT )
+ pollfd->events |= POLLOUT;
+ if ( events & SLIRP_EVENT_PRI )
+ pollfd->events |= POLLPRI;
+ if ( events & SLIRP_EVENT_ERR )
+ pollfd->events |= POLLERR;
+ if ( events & SLIRP_EVENT_HUP )
+ pollfd->events |= ( POLLHUP | POLLRDHUP );
+ DBGCP ( slirp, "SLIRP %p polling FD %d event mask %#04x(%#04x)\n",
+ slirp, fd, events, pollfd->events );
+
+ return index;
+}
+
+/**
+ * Get returned events for a file descriptor
+ *
+ * @v index File descriptor index
+ * @v device Device opaque pointer
+ * @ret events Returned events
+ */
+static int __asmcall slirp_get_revents ( int index, void *device ) {
+ struct net_device *netdev = device;
+ struct slirp_nic *slirp = netdev->priv;
+ int revents;
+ int events;
+
+ /* Ignore failed descriptors */
+ if ( index < 0 )
+ return 0;
+
+ /* Collect events */
+ revents = slirp->pollfds[index].revents;
+ events = 0;
+ if ( revents & POLLIN )
+ events |= SLIRP_EVENT_IN;
+ if ( revents & POLLOUT )
+ events |= SLIRP_EVENT_OUT;
+ if ( revents & POLLPRI )
+ events |= SLIRP_EVENT_PRI;
+ if ( revents & POLLERR )
+ events |= SLIRP_EVENT_ERR;
+ if ( revents & ( POLLHUP | POLLRDHUP ) )
+ events |= SLIRP_EVENT_HUP;
+ if ( events ) {
+ DBGC2 ( slirp, "SLIRP %p polled FD %d events %#04x(%#04x)\n",
+ slirp, slirp->pollfds[index].fd, events, revents );
+ }
+
+ return events;
+}
+
+/**
+ * Poll for completed and received packets
+ *
+ * @v netdev Network device
+ */
+static void slirp_poll ( struct net_device *netdev ) {
+ struct slirp_nic *slirp = netdev->priv;
+ uint32_t timeout = 0;
+ int ready;
+ int error;
+
+ /* Rebuild polling file descriptor list */
+ slirp->numfds = 0;
+ linux_slirp_pollfds_fill ( slirp->slirp, &timeout,
+ slirp_add_poll, netdev );
+
+ /* Poll descriptors */
+ ready = linux_poll ( slirp->pollfds, slirp->numfds, 0 );
+ error = ( ready == -1 );
+ linux_slirp_pollfds_poll ( slirp->slirp, error, slirp_get_revents,
+ netdev );
+
+ /* Record polling errors */
+ if ( error ) {
+ DBGC ( slirp, "SLIRP %p poll failed: %s\n",
+ slirp, linux_strerror ( linux_errno ) );
+ netdev_rx_err ( netdev, NULL, -ELINUX ( linux_errno ) );
+ }
+}
+
+/** Network device operations */
+static struct net_device_operations slirp_operations = {
+ .open = slirp_open,
+ .close = slirp_close,
+ .transmit = slirp_transmit,
+ .poll = slirp_poll,
+};
+
+/******************************************************************************
+ *
+ * Linux driver interface
+ *
+ ******************************************************************************
+ */
+
+/**
+ * Probe device
+ *
+ * @v linux Linux device
+ * @v request Device creation request
+ * @ret rc Return status code
+ */
+static int slirp_probe ( struct linux_device *linux,
+ struct linux_device_request *request ) {
+ struct net_device *netdev;
+ struct slirp_nic *slirp;
+ struct slirp_config config;
+ int rc;
+
+ /* Allocate device */
+ netdev = alloc_etherdev ( sizeof ( *slirp ) );
+ if ( ! netdev ) {
+ rc = -ENOMEM;
+ goto err_alloc;
+ }
+ netdev_init ( netdev, &slirp_operations );
+ linux_set_drvdata ( linux, netdev );
+ snprintf ( linux->dev.name, sizeof ( linux->dev.name ), "host" );
+ netdev->dev = &linux->dev;
+ memcpy ( netdev->hw_addr, slirp_default_mac, ETH_ALEN );
+ slirp = netdev->priv;
+ memset ( slirp, 0, sizeof ( *slirp ) );
+
+ /* Apply requested settings */
+ linux_apply_settings ( &request->settings,
+ netdev_settings ( netdev ) );
+
+ /* Initialise default configuration (matching qemu) */
+ memset ( &config, 0, sizeof ( config ) );
+ config.version = 1;
+ config.in_enabled = true;
+ config.vnetwork.s_addr = htonl ( 0x0a000200 ); /* 10.0.2.0 */
+ config.vnetmask.s_addr = htonl ( 0xffffff00 ); /* 255.255.255.0 */
+ config.vhost.s_addr = htonl ( 0x0a000202 ); /* 10.0.2.2 */
+ config.in6_enabled = true;
+ config.vdhcp_start.s_addr = htonl ( 0x0a00020f ); /* 10.0.2.15 */
+ config.vnameserver.s_addr = htonl ( 0x0a000203 ); /* 10.0.2.3 */
+
+ /* Instantiate device */
+ slirp->slirp = linux_slirp_new ( &config, &slirp_callbacks, netdev );
+ if ( ! slirp->slirp ) {
+ DBGC ( slirp, "SLIRP could not instantiate\n" );
+ rc = -ENODEV;
+ goto err_new;
+ }
+
+ /* Register network device */
+ if ( ( rc = register_netdev ( netdev ) ) != 0 )
+ goto err_register;
+
+ /* Set link up since there is no concept of link state */
+ netdev_link_up ( netdev );
+
+ return 0;
+
+ unregister_netdev ( netdev );
+ err_register:
+ linux_slirp_cleanup ( slirp->slirp );
+ err_new:
+ netdev_nullify ( netdev );
+ netdev_put ( netdev );
+ err_alloc:
+ return rc;
+}
+
+/**
+ * Remove device
+ *
+ * @v linux Linux device
+ */
+static void slirp_remove ( struct linux_device *linux ) {
+ struct net_device *netdev = linux_get_drvdata ( linux );
+ struct slirp_nic *slirp = netdev->priv;
+
+ /* Unregister network device */
+ unregister_netdev ( netdev );
+
+ /* Shut down device */
+ linux_slirp_cleanup ( slirp->slirp );
+
+ /* Free network device */
+ netdev_nullify ( netdev );
+ netdev_put ( netdev );
+}
+
+/** Slirp driver */
+struct linux_driver slirp_driver __linux_driver = {
+ .name = "slirp",
+ .probe = slirp_probe,
+ .remove = slirp_remove,
+ .can_probe = 1,
+};
diff --git a/src/drivers/linux/tap.c b/src/drivers/linux/tap.c
index db3b7955b..ff1e08bdb 100644
--- a/src/drivers/linux/tap.c
+++ b/src/drivers/linux/tap.c
@@ -19,7 +19,7 @@
#include <errno.h>
#include <string.h>
#include <stdio.h>
-#include <linux_api.h>
+#include <ipxe/linux_api.h>
#include <ipxe/list.h>
#include <ipxe/linux.h>
#include <ipxe/malloc.h>
diff --git a/src/drivers/net/3c90x.c b/src/drivers/net/3c90x.c
index 853de2b52..63e07777f 100644
--- a/src/drivers/net/3c90x.c
+++ b/src/drivers/net/3c90x.c
@@ -249,7 +249,7 @@ static int a3c90x_setup_tx_ring(struct INF_3C90X *p)
{
DBGP("a3c90x_setup_tx_ring\n");
p->tx_ring =
- malloc_dma(TX_RING_SIZE * sizeof(struct TXD), TX_RING_ALIGN);
+ malloc_phys(TX_RING_SIZE * sizeof(struct TXD), TX_RING_ALIGN);
if (!p->tx_ring) {
DBG("Could not allocate TX-ring\n");
@@ -304,7 +304,7 @@ static void a3c90x_free_tx_ring(struct INF_3C90X *p)
{
DBGP("a3c90x_free_tx_ring\n");
- free_dma(p->tx_ring, TX_RING_SIZE * sizeof(struct TXD));
+ free_phys(p->tx_ring, TX_RING_SIZE * sizeof(struct TXD));
p->tx_ring = NULL;
/* io_buffers are free()ed by netdev_tx_complete[,_err]() */
}
@@ -461,7 +461,7 @@ static int a3c90x_setup_rx_ring(struct INF_3C90X *p)
DBGP("a3c90x_setup_rx_ring\n");
p->rx_ring =
- malloc_dma(RX_RING_SIZE * sizeof(struct RXD), RX_RING_ALIGN);
+ malloc_phys(RX_RING_SIZE * sizeof(struct RXD), RX_RING_ALIGN);
if (!p->rx_ring) {
DBG("Could not allocate RX-ring\n");
@@ -491,7 +491,7 @@ static void a3c90x_free_rx_ring(struct INF_3C90X *p)
{
DBGP("a3c90x_free_rx_ring\n");
- free_dma(p->rx_ring, RX_RING_SIZE * sizeof(struct RXD));
+ free_phys(p->rx_ring, RX_RING_SIZE * sizeof(struct RXD));
p->rx_ring = NULL;
}
diff --git a/src/drivers/net/amd8111e.c b/src/drivers/net/amd8111e.c
index 693d77d1d..babd12d3c 100644
--- a/src/drivers/net/amd8111e.c
+++ b/src/drivers/net/amd8111e.c
@@ -664,7 +664,7 @@ static int amd8111e_probe(struct nic *nic, struct pci_device *pdev)
memset(lp, 0, sizeof(*lp));
lp->pdev = pdev;
lp->nic = nic;
- lp->mmio = ioremap(mmio_start, mmio_len);
+ lp->mmio = pci_ioremap(pdev, mmio_start, mmio_len);
lp->opened = 1;
adjust_pci_device(pdev);
diff --git a/src/drivers/net/ath/ath5k/ath5k.c b/src/drivers/net/ath/ath5k/ath5k.c
index a500175a7..e43eb0aaf 100644
--- a/src/drivers/net/ath/ath5k/ath5k.c
+++ b/src/drivers/net/ath/ath5k/ath5k.c
@@ -280,7 +280,7 @@ static int ath5k_probe(struct pci_device *pdev)
*/
pci_write_config_byte(pdev, 0x41, 0);
- mem = ioremap(pdev->membase, 0x10000);
+ mem = pci_ioremap(pdev, pdev->membase, 0x10000);
if (!mem) {
DBG("ath5k: cannot remap PCI memory region\n");
ret = -EIO;
@@ -877,7 +877,7 @@ ath5k_desc_alloc(struct ath5k_softc *sc)
/* allocate descriptors */
sc->desc_len = sizeof(struct ath5k_desc) * (ATH_TXBUF + ATH_RXBUF + 1);
- sc->desc = malloc_dma(sc->desc_len, ATH5K_DESC_ALIGN);
+ sc->desc = malloc_phys(sc->desc_len, ATH5K_DESC_ALIGN);
if (sc->desc == NULL) {
DBG("ath5k: can't allocate descriptors\n");
ret = -ENOMEM;
@@ -915,7 +915,7 @@ ath5k_desc_alloc(struct ath5k_softc *sc)
return 0;
err_free:
- free_dma(sc->desc, sc->desc_len);
+ free_phys(sc->desc, sc->desc_len);
err:
sc->desc = NULL;
return ret;
@@ -932,7 +932,7 @@ ath5k_desc_free(struct ath5k_softc *sc)
ath5k_rxbuf_free(sc, bf);
/* Free memory associated with all descriptors */
- free_dma(sc->desc, sc->desc_len);
+ free_phys(sc->desc, sc->desc_len);
free(sc->bufptr);
sc->bufptr = NULL;
diff --git a/src/drivers/net/ath/ath5k/ath5k_eeprom.c b/src/drivers/net/ath/ath5k/ath5k_eeprom.c
index 983d206b7..12519bc59 100644
--- a/src/drivers/net/ath/ath5k/ath5k_eeprom.c
+++ b/src/drivers/net/ath/ath5k/ath5k_eeprom.c
@@ -416,6 +416,7 @@ ath5k_eeprom_read_turbo_modes(struct ath5k_hw *ah,
if (ee->ee_version < AR5K_EEPROM_VERSION_5_0)
return 0;
+ AR5K_EEPROM_READ(o++, val);
switch (mode){
case AR5K_EEPROM_MODE_11A:
ee->ee_switch_settling_turbo[mode] = (val >> 6) & 0x7f;
diff --git a/src/drivers/net/ath/ath9k/ath9k.c b/src/drivers/net/ath/ath9k/ath9k.c
index 183aa65f6..98b7ecd5a 100644
--- a/src/drivers/net/ath/ath9k/ath9k.c
+++ b/src/drivers/net/ath/ath9k/ath9k.c
@@ -138,7 +138,7 @@ static int ath_pci_probe(struct pci_device *pdev)
if ((val & 0x0000ff00) != 0)
pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
- mem = ioremap(pdev->membase, 0x10000);
+ mem = pci_ioremap(pdev, pdev->membase, 0x10000);
if (!mem) {
DBG("ath9K: PCI memory map error\n") ;
ret = -EIO;
diff --git a/src/drivers/net/ath/ath9k/ath9k_init.c b/src/drivers/net/ath/ath9k/ath9k_init.c
index 98a0d6d59..05ed3336a 100644
--- a/src/drivers/net/ath/ath9k/ath9k_init.c
+++ b/src/drivers/net/ath/ath9k/ath9k_init.c
@@ -223,7 +223,7 @@ int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
}
/* allocate descriptors */
- dd->dd_desc = malloc_dma(dd->dd_desc_len, 16);
+ dd->dd_desc = malloc_phys(dd->dd_desc_len, 16);
if (dd->dd_desc == NULL) {
error = -ENOMEM;
goto fail;
@@ -264,7 +264,7 @@ int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
}
return 0;
fail2:
- free_dma(dd->dd_desc, dd->dd_desc_len);
+ free_phys(dd->dd_desc, dd->dd_desc_len);
fail:
memset(dd, 0, sizeof(*dd));
return error;
@@ -588,7 +588,7 @@ void ath_descdma_cleanup(struct ath_softc *sc __unused,
struct ath_descdma *dd,
struct list_head *head)
{
- free_dma(dd->dd_desc, dd->dd_desc_len);
+ free_phys(dd->dd_desc, dd->dd_desc_len);
INIT_LIST_HEAD(head);
free(dd->dd_bufptr);
diff --git a/src/drivers/net/atl1e.c b/src/drivers/net/atl1e.c
index d010d8c4a..0f0df5326 100644
--- a/src/drivers/net/atl1e.c
+++ b/src/drivers/net/atl1e.c
@@ -370,7 +370,7 @@ static void atl1e_free_ring_resources(struct atl1e_adapter *adapter)
atl1e_clean_rx_ring(adapter);
if (adapter->ring_vir_addr) {
- free_dma(adapter->ring_vir_addr, adapter->ring_size);
+ free_phys(adapter->ring_vir_addr, adapter->ring_size);
adapter->ring_vir_addr = NULL;
adapter->ring_dma = 0;
}
@@ -405,7 +405,7 @@ static int atl1e_setup_ring_resources(struct atl1e_adapter *adapter)
/* real ring DMA buffer */
size = adapter->ring_size;
- adapter->ring_vir_addr = malloc_dma(adapter->ring_size, 32);
+ adapter->ring_vir_addr = malloc_phys(adapter->ring_size, 32);
if (adapter->ring_vir_addr == NULL) {
DBG("atl1e: out of memory allocating %d bytes for %s ring\n",
diff --git a/src/drivers/net/b44.c b/src/drivers/net/b44.c
index d9aeb1b4b..eaf6d35ce 100644
--- a/src/drivers/net/b44.c
+++ b/src/drivers/net/b44.c
@@ -436,7 +436,7 @@ static void b44_free_rx_ring(struct b44_private *bp)
free_iob(bp->rx_iobuf[i]);
bp->rx_iobuf[i] = NULL;
}
- free_dma(bp->rx, B44_RX_RING_LEN_BYTES);
+ free_phys(bp->rx, B44_RX_RING_LEN_BYTES);
bp->rx = NULL;
}
}
@@ -446,11 +446,11 @@ static int b44_init_rx_ring(struct b44_private *bp)
{
b44_free_rx_ring(bp);
- bp->rx = malloc_dma(B44_RX_RING_LEN_BYTES, B44_DMA_ALIGNMENT);
+ bp->rx = malloc_phys(B44_RX_RING_LEN_BYTES, B44_DMA_ALIGNMENT);
if (!bp->rx)
return -ENOMEM;
if (!b44_address_ok(bp->rx)) {
- free_dma(bp->rx, B44_RX_RING_LEN_BYTES);
+ free_phys(bp->rx, B44_RX_RING_LEN_BYTES);
return -ENOTSUP;
}
@@ -468,7 +468,7 @@ static int b44_init_rx_ring(struct b44_private *bp)
static void b44_free_tx_ring(struct b44_private *bp)
{
if (bp->tx) {
- free_dma(bp->tx, B44_TX_RING_LEN_BYTES);
+ free_phys(bp->tx, B44_TX_RING_LEN_BYTES);
bp->tx = NULL;
}
}
@@ -478,11 +478,11 @@ static int b44_init_tx_ring(struct b44_private *bp)
{
b44_free_tx_ring(bp);
- bp->tx = malloc_dma(B44_TX_RING_LEN_BYTES, B44_DMA_ALIGNMENT);
+ bp->tx = malloc_phys(B44_TX_RING_LEN_BYTES, B44_DMA_ALIGNMENT);
if (!bp->tx)
return -ENOMEM;
if (!b44_address_ok(bp->tx)) {
- free_dma(bp->tx, B44_TX_RING_LEN_BYTES);
+ free_phys(bp->tx, B44_TX_RING_LEN_BYTES);
return -ENOTSUP;
}
@@ -673,7 +673,7 @@ static int b44_probe(struct pci_device *pci)
bp->pci = pci;
/* Map device registers */
- bp->regs = ioremap(pci->membase, B44_REGS_SIZE);
+ bp->regs = pci_ioremap(pci, pci->membase, B44_REGS_SIZE);
if (!bp->regs) {
netdev_put(netdev);
return -ENOMEM;
diff --git a/src/drivers/net/bnx2.c b/src/drivers/net/bnx2.c
index 4ebcc52a9..d5783ff99 100644
--- a/src/drivers/net/bnx2.c
+++ b/src/drivers/net/bnx2.c
@@ -2152,7 +2152,7 @@ bnx2_init_board(struct pci_device *pdev, struct nic *nic)
bnx2reg_base = pci_bar_start(pdev, PCI_BASE_ADDRESS_0);
bnx2reg_len = MB_GET_CID_ADDR(17);
- bp->regview = ioremap(bnx2reg_base, bnx2reg_len);
+ bp->regview = pci_ioremap(pdev, bnx2reg_base, bnx2reg_len);
if (!bp->regview) {
printf("Cannot map register space, aborting.\n");
diff --git a/src/drivers/net/bnxt/bnxt.c b/src/drivers/net/bnxt/bnxt.c
index e6bceb970..b8663c00a 100644
--- a/src/drivers/net/bnxt/bnxt.c
+++ b/src/drivers/net/bnxt/bnxt.c
@@ -60,7 +60,7 @@ static void *bnxt_pci_base ( struct pci_device *pdev, unsigned int reg )
reg_base = pci_bar_start ( pdev, reg );
reg_size = pci_bar_size ( pdev, reg );
- return ioremap ( reg_base, reg_size );
+ return pci_ioremap ( pdev, reg_base, reg_size );
}
static int bnxt_get_pci_info ( struct bnxt *bp )
@@ -495,39 +495,39 @@ void bnxt_free_mem ( struct bnxt *bp )
{
DBGP ( "%s\n", __func__ );
if ( bp->nq.bd_virt ) {
- free_dma ( bp->nq.bd_virt, NQ_RING_BUFFER_SIZE );
+ free_phys ( bp->nq.bd_virt, NQ_RING_BUFFER_SIZE );
bp->nq.bd_virt = NULL;
}
if ( bp->cq.bd_virt ) {
- free_dma ( bp->cq.bd_virt, CQ_RING_BUFFER_SIZE );
+ free_phys ( bp->cq.bd_virt, CQ_RING_BUFFER_SIZE );
bp->cq.bd_virt = NULL;
}
if ( bp->rx.bd_virt ) {
- free_dma ( bp->rx.bd_virt, RX_RING_BUFFER_SIZE );
+ free_phys ( bp->rx.bd_virt, RX_RING_BUFFER_SIZE );
bp->rx.bd_virt = NULL;
}
if ( bp->tx.bd_virt ) {
- free_dma ( bp->tx.bd_virt, TX_RING_BUFFER_SIZE );
+ free_phys ( bp->tx.bd_virt, TX_RING_BUFFER_SIZE );
bp->tx.bd_virt = NULL;
}
if ( bp->hwrm_addr_dma ) {
- free_dma ( bp->hwrm_addr_dma, DMA_BUFFER_SIZE );
+ free_phys ( bp->hwrm_addr_dma, DMA_BUFFER_SIZE );
bp->dma_addr_mapping = 0;
bp->hwrm_addr_dma = NULL;
}
if ( bp->hwrm_addr_resp ) {
- free_dma ( bp->hwrm_addr_resp, RESP_BUFFER_SIZE );
+ free_phys ( bp->hwrm_addr_resp, RESP_BUFFER_SIZE );
bp->resp_addr_mapping = 0;
bp->hwrm_addr_resp = NULL;
}
if ( bp->hwrm_addr_req ) {
- free_dma ( bp->hwrm_addr_req, REQ_BUFFER_SIZE );
+ free_phys ( bp->hwrm_addr_req, REQ_BUFFER_SIZE );
bp->req_addr_mapping = 0;
bp->hwrm_addr_req = NULL;
}
@@ -537,14 +537,14 @@ void bnxt_free_mem ( struct bnxt *bp )
int bnxt_alloc_mem ( struct bnxt *bp )
{
DBGP ( "%s\n", __func__ );
- bp->hwrm_addr_req = malloc_dma ( REQ_BUFFER_SIZE, BNXT_DMA_ALIGNMENT );
- bp->hwrm_addr_resp = malloc_dma ( RESP_BUFFER_SIZE,
- BNXT_DMA_ALIGNMENT );
- bp->hwrm_addr_dma = malloc_dma ( DMA_BUFFER_SIZE, BNXT_DMA_ALIGNMENT );
- bp->tx.bd_virt = malloc_dma ( TX_RING_BUFFER_SIZE, DMA_ALIGN_4K );
- bp->rx.bd_virt = malloc_dma ( RX_RING_BUFFER_SIZE, DMA_ALIGN_4K );
- bp->cq.bd_virt = malloc_dma ( CQ_RING_BUFFER_SIZE, BNXT_DMA_ALIGNMENT );
- bp->nq.bd_virt = malloc_dma ( NQ_RING_BUFFER_SIZE, BNXT_DMA_ALIGNMENT );
+ bp->hwrm_addr_req = malloc_phys ( REQ_BUFFER_SIZE, BNXT_DMA_ALIGNMENT );
+ bp->hwrm_addr_resp = malloc_phys ( RESP_BUFFER_SIZE,
+ BNXT_DMA_ALIGNMENT );
+ bp->hwrm_addr_dma = malloc_phys ( DMA_BUFFER_SIZE, BNXT_DMA_ALIGNMENT );
+ bp->tx.bd_virt = malloc_phys ( TX_RING_BUFFER_SIZE, DMA_ALIGN_4K );
+ bp->rx.bd_virt = malloc_phys ( RX_RING_BUFFER_SIZE, DMA_ALIGN_4K );
+ bp->cq.bd_virt = malloc_phys ( CQ_RING_BUFFER_SIZE, BNXT_DMA_ALIGNMENT );
+ bp->nq.bd_virt = malloc_phys ( NQ_RING_BUFFER_SIZE, BNXT_DMA_ALIGNMENT );
test_if ( bp->hwrm_addr_req &&
bp->hwrm_addr_resp &&
bp->hwrm_addr_dma &&
diff --git a/src/drivers/net/eepro100.c b/src/drivers/net/eepro100.c
index 1046cda39..1a802b590 100644
--- a/src/drivers/net/eepro100.c
+++ b/src/drivers/net/eepro100.c
@@ -93,7 +93,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
/*
* Debugging levels:
- * - DBG() is for any errors, i.e. failed alloc_iob(), malloc_dma(),
+ * - DBG() is for any errors, i.e. failed alloc_iob(), malloc_phys(),
* TX overflow, corrupted packets, ...
* - DBG2() is for successful events, like packet received,
* packet transmitted, and other general notifications.
@@ -335,7 +335,7 @@ static int ifec_net_open ( struct net_device *netdev )
ifec_mdio_setup ( netdev, options );
/* Prepare MAC address w/ Individual Address Setup (ias) command.*/
- ias = malloc_dma ( sizeof ( *ias ), CB_ALIGN );
+ ias = malloc_phys ( sizeof ( *ias ), CB_ALIGN );
if ( !ias ) {
rc = -ENOMEM;
goto error;
@@ -345,7 +345,7 @@ static int ifec_net_open ( struct net_device *netdev )
memcpy ( ias->ia, netdev->ll_addr, ETH_ALEN );
/* Prepare operating parameters w/ a configure command. */
- cfg = malloc_dma ( sizeof ( *cfg ), CB_ALIGN );
+ cfg = malloc_phys ( sizeof ( *cfg ), CB_ALIGN );
if ( !cfg ) {
rc = -ENOMEM;
goto error;
@@ -367,8 +367,8 @@ static int ifec_net_open ( struct net_device *netdev )
DBG ( "Failed to initiate!\n" );
goto error;
}
- free_dma ( ias, sizeof ( *ias ) );
- free_dma ( cfg, sizeof ( *cfg ) );
+ free_phys ( ias, sizeof ( *ias ) );
+ free_phys ( cfg, sizeof ( *cfg ) );
DBG2 ( "cfg " );
/* Enable rx by sending ring address to card */
@@ -381,8 +381,8 @@ static int ifec_net_open ( struct net_device *netdev )
return 0;
error:
- free_dma ( cfg, sizeof ( *cfg ) );
- free_dma ( ias, sizeof ( *ias ) );
+ free_phys ( cfg, sizeof ( *cfg ) );
+ free_phys ( ias, sizeof ( *ias ) );
ifec_free ( netdev );
ifec_reset ( netdev );
return rc;
@@ -703,7 +703,7 @@ static void ifec_free ( struct net_device *netdev )
}
/* free TX ring buffer */
- free_dma ( priv->tcbs, TX_RING_BYTES );
+ free_phys ( priv->tcbs, TX_RING_BYTES );
priv->tcbs = NULL;
}
@@ -1025,7 +1025,7 @@ static int ifec_tx_setup ( struct net_device *netdev )
DBGP ( "ifec_tx_setup\n" );
/* allocate tx ring */
- priv->tcbs = malloc_dma ( TX_RING_BYTES, CB_ALIGN );
+ priv->tcbs = malloc_phys ( TX_RING_BYTES, CB_ALIGN );
if ( !priv->tcbs ) {
DBG ( "TX-ring allocation failed\n" );
return -ENOMEM;
diff --git a/src/drivers/net/efi/nii.c b/src/drivers/net/efi/nii.c
index 2d87e0c63..b9f34650e 100644
--- a/src/drivers/net/efi/nii.c
+++ b/src/drivers/net/efi/nii.c
@@ -789,6 +789,20 @@ static int nii_initialise_flags ( struct nii_nic *nii, unsigned int flags ) {
}
/**
+ * Initialise UNDI with cable detection
+ *
+ * @v nii NII NIC
+ * @ret rc Return status code
+ */
+static int nii_initialise_cable ( struct nii_nic *nii ) {
+ unsigned int flags;
+
+ /* Initialise UNDI */
+ flags = PXE_OPFLAGS_INITIALIZE_DETECT_CABLE;
+ return nii_initialise_flags ( nii, flags );
+}
+
+/**
* Initialise UNDI
*
* @v nii NII NIC
@@ -961,9 +975,8 @@ static int nii_transmit ( struct net_device *netdev,
/* Construct parameter block */
memset ( &cpb, 0, sizeof ( cpb ) );
- cpb.FrameAddr = virt_to_bus ( iobuf->data );
+ cpb.FrameAddr = ( ( intptr_t ) iobuf->data );
cpb.DataLen = iob_len ( iobuf );
- cpb.MediaheaderLen = netdev->ll_protocol->ll_header_len;
/* Transmit packet */
op = NII_OP ( PXE_OPCODE_TRANSMIT,
@@ -1030,7 +1043,7 @@ static void nii_poll_rx ( struct net_device *netdev ) {
/* Construct parameter block */
memset ( &cpb, 0, sizeof ( cpb ) );
- cpb.BufferAddr = virt_to_bus ( nii->rxbuf->data );
+ cpb.BufferAddr = ( ( intptr_t ) nii->rxbuf->data );
cpb.BufferLen = iob_tailroom ( nii->rxbuf );
/* Issue command */
@@ -1122,7 +1135,6 @@ static void nii_poll ( struct net_device *netdev ) {
*/
static int nii_open ( struct net_device *netdev ) {
struct nii_nic *nii = netdev->priv;
- unsigned int flags;
int rc;
/* Initialise NIC
@@ -1140,15 +1152,21 @@ static int nii_open ( struct net_device *netdev ) {
* presence during initialisation on links that are physically
* slow to reach link-up.
*
- * Attempt to work around both of these problems by requesting
- * cable detection at this point if any only if the driver is
- * not capable of reporting link status changes at runtime via
- * PXE_OPCODE_GET_STATUS.
+ * Attempt to work around both of these problems by first
+ * attempting to initialise with cable presence detection,
+ * then falling back to initialising without cable presence
+ * detection.
*/
- flags = ( nii->media ? PXE_OPFLAGS_INITIALIZE_DO_NOT_DETECT_CABLE
- : PXE_OPFLAGS_INITIALIZE_DETECT_CABLE );
- if ( ( rc = nii_initialise_flags ( nii, flags ) ) != 0 )
- goto err_initialise;
+ if ( ( rc = nii_initialise_cable ( nii ) ) != 0 ) {
+ DBGC ( nii, "NII %s could not initialise with cable "
+ "detection: %s\n", nii->dev.name, strerror ( rc ) );
+ if ( ( rc = nii_initialise ( nii ) ) != 0 ) {
+ DBGC ( nii, "NII %s could not initialise without "
+ "cable detection: %s\n",
+ nii->dev.name, strerror ( rc ) );
+ goto err_initialise;
+ }
+ }
/* Attempt to set station address */
if ( ( rc = nii_set_station_address ( nii, netdev ) ) != 0 ) {
diff --git a/src/drivers/net/ena.c b/src/drivers/net/ena.c
index 0f25c0beb..85da1c090 100644
--- a/src/drivers/net/ena.c
+++ b/src/drivers/net/ena.c
@@ -65,35 +65,59 @@ static const char * ena_direction ( unsigned int direction ) {
*/
/**
- * Reset hardware
+ * Wait for reset operation to be acknowledged
*
* @v ena ENA device
+ * @v expected Expected reset state
* @ret rc Return status code
*/
-static int ena_reset ( struct ena_nic *ena ) {
+static int ena_reset_wait ( struct ena_nic *ena, uint32_t expected ) {
uint32_t stat;
unsigned int i;
- /* Trigger reset */
- writel ( ENA_CTRL_RESET, ( ena->regs + ENA_CTRL ) );
-
/* Wait for reset to complete */
for ( i = 0 ; i < ENA_RESET_MAX_WAIT_MS ; i++ ) {
/* Check if device is ready */
stat = readl ( ena->regs + ENA_STAT );
- if ( stat & ENA_STAT_READY )
+ if ( ( stat & ENA_STAT_RESET ) == expected )
return 0;
/* Delay */
mdelay ( 1 );
}
- DBGC ( ena, "ENA %p timed out waiting for reset (status %#08x)\n",
- ena, stat );
+ DBGC ( ena, "ENA %p timed out waiting for reset status %#08x "
+ "(got %#08x)\n", ena, expected, stat );
return -ETIMEDOUT;
}
+/**
+ * Reset hardware
+ *
+ * @v ena ENA device
+ * @ret rc Return status code
+ */
+static int ena_reset ( struct ena_nic *ena ) {
+ int rc;
+
+ /* Trigger reset */
+ writel ( ENA_CTRL_RESET, ( ena->regs + ENA_CTRL ) );
+
+ /* Wait for reset to take effect */
+ if ( ( rc = ena_reset_wait ( ena, ENA_STAT_RESET ) ) != 0 )
+ return rc;
+
+ /* Clear reset */
+ writel ( 0, ( ena->regs + ENA_CTRL ) );
+
+ /* Wait for reset to clear */
+ if ( ( rc = ena_reset_wait ( ena, 0 ) ) != 0 )
+ return rc;
+
+ return 0;
+}
+
/******************************************************************************
*
* Admin queue
@@ -164,7 +188,7 @@ static int ena_create_admin ( struct ena_nic *ena ) {
int rc;
/* Allocate admin completion queue */
- ena->acq.rsp = malloc_dma ( acq_len, acq_len );
+ ena->acq.rsp = malloc_phys ( acq_len, acq_len );
if ( ! ena->acq.rsp ) {
rc = -ENOMEM;
goto err_alloc_acq;
@@ -172,7 +196,7 @@ static int ena_create_admin ( struct ena_nic *ena ) {
memset ( ena->acq.rsp, 0, acq_len );
/* Allocate admin queue */
- ena->aq.req = malloc_dma ( aq_len, aq_len );
+ ena->aq.req = malloc_phys ( aq_len, aq_len );
if ( ! ena->aq.req ) {
rc = -ENOMEM;
goto err_alloc_aq;
@@ -196,9 +220,9 @@ static int ena_create_admin ( struct ena_nic *ena ) {
ena_clear_caps ( ena, ENA_AQ_CAPS );
ena_clear_caps ( ena, ENA_ACQ_CAPS );
- free_dma ( ena->aq.req, aq_len );
+ free_phys ( ena->aq.req, aq_len );
err_alloc_aq:
- free_dma ( ena->acq.rsp, acq_len );
+ free_phys ( ena->acq.rsp, acq_len );
err_alloc_acq:
return rc;
}
@@ -218,8 +242,8 @@ static void ena_destroy_admin ( struct ena_nic *ena ) {
wmb();
/* Free queues */
- free_dma ( ena->aq.req, aq_len );
- free_dma ( ena->acq.rsp, acq_len );
+ free_phys ( ena->aq.req, aq_len );
+ free_phys ( ena->acq.rsp, acq_len );
DBGC ( ena, "ENA %p AQ and ACQ destroyed\n", ena );
}
@@ -338,7 +362,7 @@ static int ena_create_sq ( struct ena_nic *ena, struct ena_sq *sq,
int rc;
/* Allocate submission queue entries */
- sq->sqe.raw = malloc_dma ( sq->len, ENA_ALIGN );
+ sq->sqe.raw = malloc_phys ( sq->len, ENA_ALIGN );
if ( ! sq->sqe.raw ) {
rc = -ENOMEM;
goto err_alloc;
@@ -375,7 +399,7 @@ static int ena_create_sq ( struct ena_nic *ena, struct ena_sq *sq,
return 0;
err_admin:
- free_dma ( sq->sqe.raw, sq->len );
+ free_phys ( sq->sqe.raw, sq->len );
err_alloc:
return rc;
}
@@ -403,7 +427,7 @@ static int ena_destroy_sq ( struct ena_nic *ena, struct ena_sq *sq ) {
return rc;
/* Free submission queue entries */
- free_dma ( sq->sqe.raw, sq->len );
+ free_phys ( sq->sqe.raw, sq->len );
DBGC ( ena, "ENA %p %s SQ%d destroyed\n",
ena, ena_direction ( sq->direction ), sq->id );
@@ -423,7 +447,7 @@ static int ena_create_cq ( struct ena_nic *ena, struct ena_cq *cq ) {
int rc;
/* Allocate completion queue entries */
- cq->cqe.raw = malloc_dma ( cq->len, ENA_ALIGN );
+ cq->cqe.raw = malloc_phys ( cq->len, ENA_ALIGN );
if ( ! cq->cqe.raw ) {
rc = -ENOMEM;
goto err_alloc;
@@ -461,7 +485,7 @@ static int ena_create_cq ( struct ena_nic *ena, struct ena_cq *cq ) {
return 0;
err_admin:
- free_dma ( cq->cqe.raw, cq->len );
+ free_phys ( cq->cqe.raw, cq->len );
err_alloc:
return rc;
}
@@ -488,7 +512,7 @@ static int ena_destroy_cq ( struct ena_nic *ena, struct ena_cq *cq ) {
return rc;
/* Free completion queue entries */
- free_dma ( cq->cqe.raw, cq->len );
+ free_phys ( cq->cqe.raw, cq->len );
DBGC ( ena, "ENA %p CQ%d destroyed\n", ena, cq->id );
return 0;
@@ -933,7 +957,7 @@ static int ena_probe ( struct pci_device *pci ) {
adjust_pci_device ( pci );
/* Map registers */
- ena->regs = ioremap ( pci->membase, ENA_BAR_SIZE );
+ ena->regs = pci_ioremap ( pci, pci->membase, ENA_BAR_SIZE );
if ( ! ena->regs ) {
rc = -ENODEV;
goto err_ioremap;
diff --git a/src/drivers/net/ena.h b/src/drivers/net/ena.h
index 0496fc6bd..676c5b878 100644
--- a/src/drivers/net/ena.h
+++ b/src/drivers/net/ena.h
@@ -66,7 +66,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** Device status register */
#define ENA_STAT 0x58
-#define ENA_STAT_READY 0x00000001UL /**< Ready */
+#define ENA_STAT_RESET 0x00000008UL /**< Reset in progress */
/** Admin queue entry header */
struct ena_aq_header {
diff --git a/src/drivers/net/etherfabric.c b/src/drivers/net/etherfabric.c
index 2cd41d4ca..e43d4336e 100644
--- a/src/drivers/net/etherfabric.c
+++ b/src/drivers/net/etherfabric.c
@@ -3025,7 +3025,7 @@ falcon_free_special_buffer ( void *p )
{
/* We don't bother cleaning up the buffer table entries -
* we're hardly limited */
- free_dma ( p, EFAB_BUF_ALIGN );
+ free_phys ( p, EFAB_BUF_ALIGN );
}
static void*
@@ -3038,7 +3038,7 @@ falcon_alloc_special_buffer ( struct efab_nic *efab, int bytes,
unsigned long dma_addr;
/* Allocate the buffer, aligned on a buffer address boundary */
- buffer = malloc_dma ( bytes, EFAB_BUF_ALIGN );
+ buffer = malloc_phys ( bytes, EFAB_BUF_ALIGN );
if ( ! buffer )
return NULL;
@@ -4150,7 +4150,7 @@ efab_probe ( struct pci_device *pci )
/* Get iobase/membase */
mmio_start = pci_bar_start ( pci, PCI_BASE_ADDRESS_2 );
mmio_len = pci_bar_size ( pci, PCI_BASE_ADDRESS_2 );
- efab->membase = ioremap ( mmio_start, mmio_len );
+ efab->membase = pci_ioremap ( pci, mmio_start, mmio_len );
EFAB_TRACE ( "BAR of %lx bytes at phys %lx mapped at %p\n",
mmio_len, mmio_start, efab->membase );
diff --git a/src/drivers/net/exanic.c b/src/drivers/net/exanic.c
index 287e14e8d..aaa6a28a1 100644
--- a/src/drivers/net/exanic.c
+++ b/src/drivers/net/exanic.c
@@ -800,7 +800,7 @@ static int exanic_probe ( struct pci_device *pci ) {
/* Map registers */
regs_bar_start = pci_bar_start ( pci, EXANIC_REGS_BAR );
- exanic->regs = ioremap ( regs_bar_start, EXANIC_REGS_LEN );
+ exanic->regs = pci_ioremap ( pci, regs_bar_start, EXANIC_REGS_LEN );
if ( ! exanic->regs ) {
rc = -ENODEV;
goto err_ioremap_regs;
@@ -824,14 +824,14 @@ static int exanic_probe ( struct pci_device *pci ) {
/* Map transmit region */
tx_bar_start = pci_bar_start ( pci, EXANIC_TX_BAR );
tx_bar_len = pci_bar_size ( pci, EXANIC_TX_BAR );
- exanic->tx = ioremap ( tx_bar_start, tx_bar_len );
+ exanic->tx = pci_ioremap ( pci, tx_bar_start, tx_bar_len );
if ( ! exanic->tx ) {
rc = -ENODEV;
goto err_ioremap_tx;
}
/* Allocate transmit feedback region (shared between all ports) */
- exanic->txf = malloc_dma ( EXANIC_TXF_LEN, EXANIC_ALIGN );
+ exanic->txf = malloc_phys ( EXANIC_TXF_LEN, EXANIC_ALIGN );
if ( ! exanic->txf ) {
rc = -ENOMEM;
goto err_alloc_txf;
@@ -853,7 +853,7 @@ static int exanic_probe ( struct pci_device *pci ) {
for ( i-- ; i >= 0 ; i-- )
exanic_remove_port ( exanic, i );
exanic_reset ( exanic );
- free_dma ( exanic->txf, EXANIC_TXF_LEN );
+ free_phys ( exanic->txf, EXANIC_TXF_LEN );
err_alloc_txf:
iounmap ( exanic->tx );
err_ioremap_tx:
@@ -882,7 +882,7 @@ static void exanic_remove ( struct pci_device *pci ) {
exanic_reset ( exanic );
/* Free transmit feedback region */
- free_dma ( exanic->txf, EXANIC_TXF_LEN );
+ free_phys ( exanic->txf, EXANIC_TXF_LEN );
/* Unmap transmit region */
iounmap ( exanic->tx );
diff --git a/src/drivers/net/forcedeth.c b/src/drivers/net/forcedeth.c
index 7f044b192..7fba08a08 100644
--- a/src/drivers/net/forcedeth.c
+++ b/src/drivers/net/forcedeth.c
@@ -267,7 +267,7 @@ nv_init_rings ( struct forcedeth_private *priv )
/* Allocate ring for both TX and RX */
priv->rx_ring =
- malloc_dma ( sizeof(struct ring_desc) * RXTX_RING_SIZE, 32 );
+ malloc_phys ( sizeof(struct ring_desc) * RXTX_RING_SIZE, 32 );
if ( ! priv->rx_ring )
goto err_malloc;
priv->tx_ring = &priv->rx_ring[RX_RING_SIZE];
@@ -308,7 +308,7 @@ nv_free_rxtx_resources ( struct forcedeth_private *priv )
DBGP ( "nv_free_rxtx_resources\n" );
- free_dma ( priv->rx_ring, sizeof(struct ring_desc) * RXTX_RING_SIZE );
+ free_phys ( priv->rx_ring, sizeof(struct ring_desc) * RXTX_RING_SIZE );
for ( i = 0; i < RX_RING_SIZE; i++ ) {
free_iob ( priv->rx_iobuf[i] );
@@ -1762,7 +1762,7 @@ forcedeth_map_regs ( struct forcedeth_private *priv )
}
rc = -ENOMEM;
- ioaddr = ioremap ( addr, register_size );
+ ioaddr = pci_ioremap ( priv->pci_dev, addr, register_size );
if ( ! ioaddr ) {
DBG ( "Cannot remap MMIO\n" );
goto err_ioremap;
diff --git a/src/drivers/net/icplus.c b/src/drivers/net/icplus.c
index 4bed92427..acd2e2363 100644
--- a/src/drivers/net/icplus.c
+++ b/src/drivers/net/icplus.c
@@ -343,7 +343,7 @@ static int icplus_create_ring ( struct icplus_nic *icp, struct icplus_ring *ring
struct icplus_descriptor *next;
/* Allocate descriptor ring */
- ring->entry = malloc_dma ( len, ICP_ALIGN );
+ ring->entry = malloc_phys ( len, ICP_ALIGN );
if ( ! ring->entry ) {
rc = -ENOMEM;
goto err_alloc;
@@ -369,7 +369,7 @@ static int icplus_create_ring ( struct icplus_nic *icp, struct icplus_ring *ring
( virt_to_bus ( ring->entry ) + len ) );
return 0;
- free_dma ( ring->entry, len );
+ free_phys ( ring->entry, len );
ring->entry = NULL;
err_alloc:
return rc;
@@ -386,7 +386,7 @@ static void icplus_destroy_ring ( struct icplus_nic *icp __unused,
size_t len = ( sizeof ( ring->entry[0] ) * ICP_NUM_DESC );
/* Free descriptor ring */
- free_dma ( ring->entry, len );
+ free_phys ( ring->entry, len );
ring->entry = NULL;
}
@@ -726,7 +726,7 @@ static int icplus_probe ( struct pci_device *pci ) {
adjust_pci_device ( pci );
/* Map registers */
- icp->regs = ioremap ( pci->membase, ICP_BAR_SIZE );
+ icp->regs = pci_ioremap ( pci, pci->membase, ICP_BAR_SIZE );
if ( ! icp->regs ) {
rc = -ENODEV;
goto err_ioremap;
diff --git a/src/drivers/net/igbvf/igbvf_main.c b/src/drivers/net/igbvf/igbvf_main.c
index fc7021c38..a5ed0c451 100644
--- a/src/drivers/net/igbvf/igbvf_main.c
+++ b/src/drivers/net/igbvf/igbvf_main.c
@@ -46,7 +46,7 @@ int igbvf_setup_tx_resources ( struct igbvf_adapter *adapter )
/* Allocate transmit descriptor ring memory.
It must not cross a 64K boundary because of hardware errata #23
- so we use malloc_dma() requesting a 128 byte block that is
+ so we use malloc_phys() requesting a 128 byte block that is
128 byte aligned. This should guarantee that the memory
allocated will not cross a 64K boundary, because 128 is an
even multiple of 65536 ( 65536 / 128 == 512 ), so all possible
@@ -55,7 +55,7 @@ int igbvf_setup_tx_resources ( struct igbvf_adapter *adapter )
*/
adapter->tx_base =
- malloc_dma ( adapter->tx_ring_size, adapter->tx_ring_size );
+ malloc_phys ( adapter->tx_ring_size, adapter->tx_ring_size );
if ( ! adapter->tx_base ) {
return -ENOMEM;
@@ -78,7 +78,7 @@ void igbvf_free_tx_resources ( struct igbvf_adapter *adapter )
{
DBG ( "igbvf_free_tx_resources\n" );
- free_dma ( adapter->tx_base, adapter->tx_ring_size );
+ free_phys ( adapter->tx_base, adapter->tx_ring_size );
}
/**
@@ -93,7 +93,7 @@ void igbvf_free_rx_resources ( struct igbvf_adapter *adapter )
DBG ( "igbvf_free_rx_resources\n" );
- free_dma ( adapter->rx_base, adapter->rx_ring_size );
+ free_phys ( adapter->rx_base, adapter->rx_ring_size );
for ( i = 0; i < NUM_RX_DESC; i++ ) {
free_iob ( adapter->rx_iobuf[i] );
@@ -574,7 +574,7 @@ int igbvf_setup_rx_resources ( struct igbvf_adapter *adapter )
*/
adapter->rx_base =
- malloc_dma ( adapter->rx_ring_size, adapter->rx_ring_size );
+ malloc_phys ( adapter->rx_ring_size, adapter->rx_ring_size );
if ( ! adapter->rx_base ) {
return -ENOMEM;
@@ -843,7 +843,7 @@ int igbvf_probe ( struct pci_device *pdev )
DBG ( "mmio_start: %#08lx\n", mmio_start );
DBG ( "mmio_len: %#08lx\n", mmio_len );
- adapter->hw.hw_addr = ioremap ( mmio_start, mmio_len );
+ adapter->hw.hw_addr = pci_ioremap ( pdev, mmio_start, mmio_len );
DBG ( "adapter->hw.hw_addr: %p\n", adapter->hw.hw_addr );
if ( ! adapter->hw.hw_addr ) {
diff --git a/src/drivers/net/intel.c b/src/drivers/net/intel.c
index d9b8b46b7..83492961f 100644
--- a/src/drivers/net/intel.c
+++ b/src/drivers/net/intel.c
@@ -32,7 +32,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <ipxe/ethernet.h>
#include <ipxe/if_ether.h>
#include <ipxe/iobuf.h>
-#include <ipxe/malloc.h>
+#include <ipxe/dma.h>
#include <ipxe/pci.h>
#include <ipxe/profile.h>
#include "intel.h"
@@ -504,7 +504,8 @@ int intel_create_ring ( struct intel_nic *intel, struct intel_ring *ring ) {
* prevent any possible page-crossing errors due to hardware
* errata.
*/
- ring->desc = malloc_dma ( ring->len, ring->len );
+ ring->desc = dma_alloc ( intel->dma, &ring->map, ring->len,
+ ring->len );
if ( ! ring->desc )
return -ENOMEM;
@@ -512,7 +513,7 @@ int intel_create_ring ( struct intel_nic *intel, struct intel_ring *ring ) {
memset ( ring->desc, 0, ring->len );
/* Program ring address */
- address = virt_to_bus ( ring->desc );
+ address = dma ( &ring->map, ring->desc );
writel ( ( address & 0xffffffffUL ),
( intel->regs + ring->reg + INTEL_xDBAL ) );
if ( sizeof ( physaddr_t ) > sizeof ( uint32_t ) ) {
@@ -534,9 +535,9 @@ int intel_create_ring ( struct intel_nic *intel, struct intel_ring *ring ) {
dctl |= INTEL_xDCTL_ENABLE;
writel ( dctl, intel->regs + ring->reg + INTEL_xDCTL );
- DBGC ( intel, "INTEL %p ring %05x is at [%08llx,%08llx)\n",
- intel, ring->reg, ( ( unsigned long long ) address ),
- ( ( unsigned long long ) address + ring->len ) );
+ DBGC ( intel, "INTEL %p ring %05x is at [%08lx,%08lx)\n",
+ intel, ring->reg, virt_to_phys ( ring->desc ),
+ ( virt_to_phys ( ring->desc ) + ring->len ) );
return 0;
}
@@ -553,7 +554,7 @@ void intel_destroy_ring ( struct intel_nic *intel, struct intel_ring *ring ) {
intel_reset_ring ( intel, ring->reg );
/* Free descriptor ring */
- free_dma ( ring->desc, ring->len );
+ dma_free ( &ring->map, ring->desc, ring->len );
ring->desc = NULL;
ring->prod = 0;
ring->cons = 0;
@@ -569,14 +570,13 @@ void intel_refill_rx ( struct intel_nic *intel ) {
struct io_buffer *iobuf;
unsigned int rx_idx;
unsigned int rx_tail;
- physaddr_t address;
unsigned int refilled = 0;
/* Refill ring */
while ( ( intel->rx.prod - intel->rx.cons ) < INTEL_RX_FILL ) {
/* Allocate I/O buffer */
- iobuf = alloc_iob ( INTEL_RX_MAX_LEN );
+ iobuf = alloc_rx_iob ( INTEL_RX_MAX_LEN, intel->dma );
if ( ! iobuf ) {
/* Wait for next refill */
break;
@@ -587,16 +587,15 @@ void intel_refill_rx ( struct intel_nic *intel ) {
rx = &intel->rx.desc[rx_idx];
/* Populate receive descriptor */
- address = virt_to_bus ( iobuf->data );
- intel->rx.describe ( rx, address, 0 );
+ intel->rx.describe ( rx, iob_dma ( iobuf ), 0 );
/* Record I/O buffer */
assert ( intel->rx_iobuf[rx_idx] == NULL );
intel->rx_iobuf[rx_idx] = iobuf;
- DBGC2 ( intel, "INTEL %p RX %d is [%llx,%llx)\n", intel, rx_idx,
- ( ( unsigned long long ) address ),
- ( ( unsigned long long ) address + INTEL_RX_MAX_LEN ) );
+ DBGC2 ( intel, "INTEL %p RX %d is [%lx,%lx)\n",
+ intel, rx_idx, virt_to_phys ( iobuf->data ),
+ ( virt_to_phys ( iobuf->data ) + INTEL_RX_MAX_LEN ) );
refilled++;
}
@@ -619,9 +618,10 @@ void intel_refill_rx ( struct intel_nic *intel ) {
void intel_empty_rx ( struct intel_nic *intel ) {
unsigned int i;
+ /* Discard unused receive buffers */
for ( i = 0 ; i < INTEL_NUM_RX_DESC ; i++ ) {
if ( intel->rx_iobuf[i] )
- free_iob ( intel->rx_iobuf[i] );
+ free_rx_iob ( intel->rx_iobuf[i] );
intel->rx_iobuf[i] = NULL;
}
}
@@ -742,7 +742,6 @@ int intel_transmit ( struct net_device *netdev, struct io_buffer *iobuf ) {
struct intel_descriptor *tx;
unsigned int tx_idx;
unsigned int tx_tail;
- physaddr_t address;
size_t len;
/* Get next transmit descriptor */
@@ -755,9 +754,8 @@ int intel_transmit ( struct net_device *netdev, struct io_buffer *iobuf ) {
tx = &intel->tx.desc[tx_idx];
/* Populate transmit descriptor */
- address = virt_to_bus ( iobuf->data );
len = iob_len ( iobuf );
- intel->tx.describe ( tx, address, len );
+ intel->tx.describe ( tx, iob_dma ( iobuf ), len );
wmb();
/* Notify card that there are packets ready to transmit */
@@ -766,9 +764,9 @@ int intel_transmit ( struct net_device *netdev, struct io_buffer *iobuf ) {
profile_stop ( &intel_vm_tx_profiler );
profile_exclude ( &intel_vm_tx_profiler );
- DBGC2 ( intel, "INTEL %p TX %d is [%llx,%llx)\n", intel, tx_idx,
- ( ( unsigned long long ) address ),
- ( ( unsigned long long ) address + len ) );
+ DBGC2 ( intel, "INTEL %p TX %d is [%lx,%lx)\n",
+ intel, tx_idx, virt_to_phys ( iobuf->data ),
+ ( virt_to_phys ( iobuf->data ) + len ) );
return 0;
}
@@ -959,12 +957,17 @@ static int intel_probe ( struct pci_device *pci ) {
adjust_pci_device ( pci );
/* Map registers */
- intel->regs = ioremap ( pci->membase, INTEL_BAR_SIZE );
+ intel->regs = pci_ioremap ( pci, pci->membase, INTEL_BAR_SIZE );
if ( ! intel->regs ) {
rc = -ENODEV;
goto err_ioremap;
}
+ /* Configure DMA */
+ intel->dma = &pci->dma;
+ dma_set_mask_64bit ( intel->dma );
+ netdev->dma = intel->dma;
+
/* Reset the NIC */
if ( ( rc = intel_reset ( intel ) ) != 0 )
goto err_reset;
diff --git a/src/drivers/net/intel.h b/src/drivers/net/intel.h
index 9d740efc3..4f51a80f6 100644
--- a/src/drivers/net/intel.h
+++ b/src/drivers/net/intel.h
@@ -12,6 +12,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <stdint.h>
#include <ipxe/if_ether.h>
#include <ipxe/nvs.h>
+#include <ipxe/dma.h>
/** Intel BAR size */
#define INTEL_BAR_SIZE ( 128 * 1024 )
@@ -212,6 +213,8 @@ union intel_receive_address {
struct intel_ring {
/** Descriptors */
struct intel_descriptor *desc;
+ /** Descriptor ring DMA mapping */
+ struct dma_mapping map;
/** Producer index */
unsigned int prod;
/** Consumer index */
@@ -277,6 +280,8 @@ intel_init_mbox ( struct intel_mailbox *mbox, unsigned int ctrl,
struct intel_nic {
/** Registers */
void *regs;
+ /** DMA device */
+ struct dma_device *dma;
/** Port number (for multi-port devices) */
unsigned int port;
/** Flags */
diff --git a/src/drivers/net/intelx.c b/src/drivers/net/intelx.c
index 91fb7955f..ccf6b0648 100644
--- a/src/drivers/net/intelx.c
+++ b/src/drivers/net/intelx.c
@@ -32,7 +32,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <ipxe/ethernet.h>
#include <ipxe/if_ether.h>
#include <ipxe/iobuf.h>
-#include <ipxe/malloc.h>
#include <ipxe/pci.h>
#include "intelx.h"
@@ -405,12 +404,17 @@ static int intelx_probe ( struct pci_device *pci ) {
adjust_pci_device ( pci );
/* Map registers */
- intel->regs = ioremap ( pci->membase, INTEL_BAR_SIZE );
+ intel->regs = pci_ioremap ( pci, pci->membase, INTEL_BAR_SIZE );
if ( ! intel->regs ) {
rc = -ENODEV;
goto err_ioremap;
}
+ /* Configure DMA */
+ intel->dma = &pci->dma;
+ dma_set_mask_64bit ( intel->dma );
+ netdev->dma = intel->dma;
+
/* Reset the NIC */
if ( ( rc = intelx_reset ( intel ) ) != 0 )
goto err_reset;
diff --git a/src/drivers/net/intelxl.c b/src/drivers/net/intelxl.c
index c98ba265c..ac9e37c5a 100644
--- a/src/drivers/net/intelxl.c
+++ b/src/drivers/net/intelxl.c
@@ -34,7 +34,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <ipxe/if_ether.h>
#include <ipxe/vlan.h>
#include <ipxe/iobuf.h>
-#include <ipxe/malloc.h>
#include <ipxe/pci.h>
#include <ipxe/version.h>
#include "intelxl.h"
@@ -87,15 +86,16 @@ static int intelxl_reset ( struct intelxl_nic *intelxl ) {
static int intelxl_fetch_mac ( struct intelxl_nic *intelxl,
struct net_device *netdev ) {
union intelxl_receive_address mac;
- uint32_t prtgl_sal;
+ uint32_t prtpm_sal;
+ uint32_t prtpm_sah;
uint32_t prtgl_sah;
size_t mfs;
/* Read NVM-loaded address */
- prtgl_sal = readl ( intelxl->regs + INTELXL_PRTGL_SAL );
- prtgl_sah = readl ( intelxl->regs + INTELXL_PRTGL_SAH );
- mac.reg.low = cpu_to_le32 ( prtgl_sal );
- mac.reg.high = cpu_to_le32 ( prtgl_sah );
+ prtpm_sal = readl ( intelxl->regs + INTELXL_PRTPM_SAL );
+ prtpm_sah = readl ( intelxl->regs + INTELXL_PRTPM_SAH );
+ mac.reg.low = cpu_to_le32 ( prtpm_sal );
+ mac.reg.high = cpu_to_le32 ( prtpm_sah );
/* Check that address is valid */
if ( ! is_valid_ether_addr ( mac.raw ) ) {
@@ -110,6 +110,7 @@ static int intelxl_fetch_mac ( struct intelxl_nic *intelxl,
memcpy ( netdev->hw_addr, mac.raw, ETH_ALEN );
/* Get maximum frame size */
+ prtgl_sah = readl ( intelxl->regs + INTELXL_PRTGL_SAH );
mfs = INTELXL_PRTGL_SAH_MFS_GET ( prtgl_sah );
netdev->max_pkt_len = ( mfs - 4 /* CRC */ );
@@ -134,20 +135,36 @@ int intelxl_msix_enable ( struct intelxl_nic *intelxl,
struct pci_device *pci ) {
int rc;
+ /* Map dummy target location */
+ if ( ( rc = dma_map ( intelxl->dma, &intelxl->msix.map,
+ virt_to_phys ( &intelxl->msix.msg ),
+ sizeof ( intelxl->msix.msg ), DMA_RX ) ) != 0 ) {
+ DBGC ( intelxl, "INTELXL %p could not map MSI-X target: %s\n",
+ intelxl, strerror ( rc ) );
+ goto err_map;
+ }
+
/* Enable MSI-X capability */
- if ( ( rc = pci_msix_enable ( pci, &intelxl->msix ) ) != 0 ) {
+ if ( ( rc = pci_msix_enable ( pci, &intelxl->msix.cap ) ) != 0 ) {
DBGC ( intelxl, "INTELXL %p could not enable MSI-X: %s\n",
intelxl, strerror ( rc ) );
- return rc;
+ goto err_enable;
}
/* Configure interrupt zero to write to dummy location */
- pci_msix_map ( &intelxl->msix, 0, virt_to_bus ( &intelxl->msg ), 0 );
+ pci_msix_map ( &intelxl->msix.cap, 0,
+ dma ( &intelxl->msix.map, &intelxl->msix.msg ), 0 );
/* Enable dummy interrupt zero */
- pci_msix_unmask ( &intelxl->msix, 0 );
+ pci_msix_unmask ( &intelxl->msix.cap, 0 );
return 0;
+
+ pci_msix_disable ( pci, &intelxl->msix.cap );
+ err_enable:
+ dma_unmap ( &intelxl->msix.map );
+ err_map:
+ return rc;
}
/**
@@ -160,10 +177,13 @@ void intelxl_msix_disable ( struct intelxl_nic *intelxl,
struct pci_device *pci ) {
/* Disable dummy interrupt zero */
- pci_msix_mask ( &intelxl->msix, 0 );
+ pci_msix_mask ( &intelxl->msix.cap, 0 );
/* Disable MSI-X capability */
- pci_msix_disable ( pci, &intelxl->msix );
+ pci_msix_disable ( pci, &intelxl->msix.cap );
+
+ /* Unmap dummy target location */
+ dma_unmap ( &intelxl->msix.map );
}
/******************************************************************************
@@ -195,19 +215,19 @@ static int intelxl_alloc_admin ( struct intelxl_nic *intelxl,
size_t len = ( sizeof ( admin->desc[0] ) * INTELXL_ADMIN_NUM_DESC );
/* Allocate admin queue */
- admin->buf = malloc_dma ( ( buf_len + len ), INTELXL_ALIGN );
+ admin->buf = dma_alloc ( intelxl->dma, &admin->map, ( buf_len + len ),
+ INTELXL_ALIGN );
if ( ! admin->buf )
return -ENOMEM;
admin->desc = ( ( ( void * ) admin->buf ) + buf_len );
- DBGC ( intelxl, "INTELXL %p A%cQ is at [%08llx,%08llx) buf "
- "[%08llx,%08llx)\n", intelxl,
+ DBGC ( intelxl, "INTELXL %p A%cQ is at [%08lx,%08lx) buf "
+ "[%08lx,%08lx)\n", intelxl,
( ( admin == &intelxl->command ) ? 'T' : 'R' ),
- ( ( unsigned long long ) virt_to_bus ( admin->desc ) ),
- ( ( unsigned long long ) ( virt_to_bus ( admin->desc ) + len ) ),
- ( ( unsigned long long ) virt_to_bus ( admin->buf ) ),
- ( ( unsigned long long ) ( virt_to_bus ( admin->buf ) +
- buf_len ) ) );
+ virt_to_phys ( admin->desc ),
+ ( virt_to_phys ( admin->desc ) + len ),
+ virt_to_phys ( admin->buf ),
+ ( virt_to_phys ( admin->buf ) + buf_len ) );
return 0;
}
@@ -235,7 +255,7 @@ static void intelxl_enable_admin ( struct intelxl_nic *intelxl,
admin->index = 0;
/* Program queue address */
- address = virt_to_bus ( admin->desc );
+ address = dma ( &admin->map, admin->desc );
writel ( ( address & 0xffffffffUL ), admin_regs + regs->bal );
if ( sizeof ( physaddr_t ) > sizeof ( uint32_t ) ) {
writel ( ( ( ( uint64_t ) address ) >> 32 ),
@@ -277,7 +297,7 @@ static void intelxl_free_admin ( struct intelxl_nic *intelxl __unused,
size_t len = ( sizeof ( admin->desc[0] ) * INTELXL_ADMIN_NUM_DESC );
/* Free queue */
- free_dma ( admin->buf, ( buf_len + len ) );
+ dma_free ( &admin->map, admin->buf, ( buf_len + len ) );
}
/**
@@ -330,7 +350,7 @@ static void intelxl_admin_event_init ( struct intelxl_nic *intelxl,
/* Initialise descriptor */
evt = &admin->desc[ index % INTELXL_ADMIN_NUM_DESC ];
buf = &admin->buf[ index % INTELXL_ADMIN_NUM_DESC ];
- address = virt_to_bus ( buf );
+ address = dma ( &admin->map, buf );
evt->flags = cpu_to_le16 ( INTELXL_ADMIN_FL_BUF );
evt->len = cpu_to_le16 ( sizeof ( *buf ) );
evt->params.buffer.high = cpu_to_le32 ( address >> 32 );
@@ -375,7 +395,7 @@ int intelxl_admin_command ( struct intelxl_nic *intelxl ) {
/* Populate data buffer address if applicable */
if ( cmd->flags & cpu_to_le16 ( INTELXL_ADMIN_FL_BUF ) ) {
- address = virt_to_bus ( buf );
+ address = dma ( &admin->map, buf );
cmd->params.buffer.high = cpu_to_le32 ( address >> 32 );
cmd->params.buffer.low = cpu_to_le32 ( address & 0xffffffffUL );
}
@@ -922,16 +942,15 @@ void intelxl_close_admin ( struct intelxl_nic *intelxl ) {
*/
int intelxl_alloc_ring ( struct intelxl_nic *intelxl,
struct intelxl_ring *ring ) {
- physaddr_t address;
int rc;
/* Allocate descriptor ring */
- ring->desc.raw = malloc_dma ( ring->len, INTELXL_ALIGN );
+ ring->desc.raw = dma_alloc ( intelxl->dma, &ring->map, ring->len,
+ INTELXL_ALIGN );
if ( ! ring->desc.raw ) {
rc = -ENOMEM;
goto err_alloc;
}
- address = virt_to_bus ( ring->desc.raw );
/* Initialise descriptor ring */
memset ( ring->desc.raw, 0, ring->len );
@@ -943,14 +962,14 @@ int intelxl_alloc_ring ( struct intelxl_nic *intelxl,
ring->prod = 0;
ring->cons = 0;
- DBGC ( intelxl, "INTELXL %p ring %06x is at [%08llx,%08llx)\n",
+ DBGC ( intelxl, "INTELXL %p ring %06x is at [%08lx,%08lx)\n",
intelxl, ( ring->reg + ring->tail ),
- ( ( unsigned long long ) address ),
- ( ( unsigned long long ) address + ring->len ) );
+ virt_to_phys ( ring->desc.raw ),
+ ( virt_to_phys ( ring->desc.raw ) + ring->len ) );
return 0;
- free_dma ( ring->desc.raw, ring->len );
+ dma_free ( &ring->map, ring->desc.raw, ring->len );
err_alloc:
return rc;
}
@@ -965,7 +984,7 @@ void intelxl_free_ring ( struct intelxl_nic *intelxl __unused,
struct intelxl_ring *ring ) {
/* Free descriptor ring */
- free_dma ( ring->desc.raw, ring->len );
+ dma_free ( &ring->map, ring->desc.raw, ring->len );
ring->desc.raw = NULL;
}
@@ -1241,7 +1260,7 @@ static int intelxl_create_ring ( struct intelxl_nic *intelxl,
goto err_alloc;
/* Program queue context */
- address = virt_to_bus ( ring->desc.raw );
+ address = dma ( &ring->map, ring->desc.raw );
if ( ( rc = ring->context ( intelxl, address ) ) != 0 )
goto err_context;
@@ -1289,14 +1308,13 @@ static void intelxl_refill_rx ( struct intelxl_nic *intelxl ) {
struct io_buffer *iobuf;
unsigned int rx_idx;
unsigned int rx_tail;
- physaddr_t address;
unsigned int refilled = 0;
/* Refill ring */
while ( ( intelxl->rx.prod - intelxl->rx.cons ) < INTELXL_RX_FILL ) {
/* Allocate I/O buffer */
- iobuf = alloc_iob ( intelxl->mfs );
+ iobuf = alloc_rx_iob ( intelxl->mfs, intelxl->dma );
if ( ! iobuf ) {
/* Wait for next refill */
break;
@@ -1307,17 +1325,16 @@ static void intelxl_refill_rx ( struct intelxl_nic *intelxl ) {
rx = &intelxl->rx.desc.rx[rx_idx].data;
/* Populate receive descriptor */
- address = virt_to_bus ( iobuf->data );
- rx->address = cpu_to_le64 ( address );
+ rx->address = cpu_to_le64 ( iob_dma ( iobuf ) );
rx->flags = 0;
/* Record I/O buffer */
assert ( intelxl->rx_iobuf[rx_idx] == NULL );
intelxl->rx_iobuf[rx_idx] = iobuf;
- DBGC2 ( intelxl, "INTELXL %p RX %d is [%llx,%llx)\n", intelxl,
- rx_idx, ( ( unsigned long long ) address ),
- ( ( unsigned long long ) address + intelxl->mfs ) );
+ DBGC2 ( intelxl, "INTELXL %p RX %d is [%08lx,%08lx)\n",
+ intelxl, rx_idx, virt_to_phys ( iobuf->data ),
+ ( virt_to_phys ( iobuf->data ) + intelxl->mfs ) );
refilled++;
}
@@ -1340,7 +1357,7 @@ void intelxl_empty_rx ( struct intelxl_nic *intelxl ) {
/* Discard any unused receive buffers */
for ( i = 0 ; i < INTELXL_RX_NUM_DESC ; i++ ) {
if ( intelxl->rx_iobuf[i] )
- free_iob ( intelxl->rx_iobuf[i] );
+ free_rx_iob ( intelxl->rx_iobuf[i] );
intelxl->rx_iobuf[i] = NULL;
}
}
@@ -1467,7 +1484,6 @@ int intelxl_transmit ( struct net_device *netdev, struct io_buffer *iobuf ) {
struct intelxl_tx_data_descriptor *tx;
unsigned int tx_idx;
unsigned int tx_tail;
- physaddr_t address;
size_t len;
/* Get next transmit descriptor */
@@ -1481,9 +1497,8 @@ int intelxl_transmit ( struct net_device *netdev, struct io_buffer *iobuf ) {
tx = &intelxl->tx.desc.tx[tx_idx].data;
/* Populate transmit descriptor */
- address = virt_to_bus ( iobuf->data );
len = iob_len ( iobuf );
- tx->address = cpu_to_le64 ( address );
+ tx->address = cpu_to_le64 ( iob_dma ( iobuf ) );
tx->len = cpu_to_le32 ( INTELXL_TX_DATA_LEN ( len ) );
tx->flags = cpu_to_le32 ( INTELXL_TX_DATA_DTYP | INTELXL_TX_DATA_EOP |
INTELXL_TX_DATA_RS | INTELXL_TX_DATA_JFDI );
@@ -1492,9 +1507,9 @@ int intelxl_transmit ( struct net_device *netdev, struct io_buffer *iobuf ) {
/* Notify card that there are packets ready to transmit */
writel ( tx_tail, ( intelxl->regs + intelxl->tx.tail ) );
- DBGC2 ( intelxl, "INTELXL %p TX %d is [%llx,%llx)\n", intelxl, tx_idx,
- ( ( unsigned long long ) address ),
- ( ( unsigned long long ) address + len ) );
+ DBGC2 ( intelxl, "INTELXL %p TX %d is [%08lx,%08lx)\n",
+ intelxl, tx_idx, virt_to_phys ( iobuf->data ),
+ ( virt_to_phys ( iobuf->data ) + len ) );
return 0;
}
@@ -1641,6 +1656,7 @@ static struct net_device_operations intelxl_operations = {
static int intelxl_probe ( struct pci_device *pci ) {
struct net_device *netdev;
struct intelxl_nic *intelxl;
+ uint32_t pffunc_rid;
uint32_t pfgen_portnum;
uint32_t pflan_qalloc;
int rc;
@@ -1656,7 +1672,6 @@ static int intelxl_probe ( struct pci_device *pci ) {
pci_set_drvdata ( pci, netdev );
netdev->dev = &pci->dev;
memset ( intelxl, 0, sizeof ( *intelxl ) );
- intelxl->pf = PCI_FUNC ( pci->busdevfn );
intelxl->intr = INTELXL_PFINT_DYN_CTL0;
intelxl_init_admin ( &intelxl->command, INTELXL_ADMIN_CMD,
&intelxl_admin_offsets );
@@ -1673,17 +1688,24 @@ static int intelxl_probe ( struct pci_device *pci ) {
adjust_pci_device ( pci );
/* Map registers */
- intelxl->regs = ioremap ( pci->membase, INTELXL_BAR_SIZE );
+ intelxl->regs = pci_ioremap ( pci, pci->membase, INTELXL_BAR_SIZE );
if ( ! intelxl->regs ) {
rc = -ENODEV;
goto err_ioremap;
}
+ /* Configure DMA */
+ intelxl->dma = &pci->dma;
+ dma_set_mask_64bit ( intelxl->dma );
+ netdev->dma = intelxl->dma;
+
/* Reset the NIC */
if ( ( rc = intelxl_reset ( intelxl ) ) != 0 )
goto err_reset;
- /* Get port number and base queue number */
+ /* Get function number, port number and base queue number */
+ pffunc_rid = readl ( intelxl->regs + INTELXL_PFFUNC_RID );
+ intelxl->pf = INTELXL_PFFUNC_RID_FUNC_NUM ( pffunc_rid );
pfgen_portnum = readl ( intelxl->regs + INTELXL_PFGEN_PORTNUM );
intelxl->port = INTELXL_PFGEN_PORTNUM_PORT_NUM ( pfgen_portnum );
pflan_qalloc = readl ( intelxl->regs + INTELXL_PFLAN_QALLOC );
diff --git a/src/drivers/net/intelxl.h b/src/drivers/net/intelxl.h
index 80586cef0..a4a776d28 100644
--- a/src/drivers/net/intelxl.h
+++ b/src/drivers/net/intelxl.h
@@ -12,6 +12,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <stdint.h>
#include <ipxe/if_ether.h>
#include <ipxe/pcimsix.h>
+#include <ipxe/dma.h>
struct intelxl_nic;
@@ -562,6 +563,8 @@ struct intelxl_admin {
struct intelxl_admin_descriptor *desc;
/** Data buffers */
union intelxl_admin_buffer *buf;
+ /** DMA mapping */
+ struct dma_mapping map;
/** Queue index */
unsigned int index;
@@ -866,6 +869,8 @@ struct intelxl_ring {
/** Raw data */
void *raw;
} desc;
+ /** Descriptor ring DMA mapping */
+ struct dma_mapping map;
/** Producer index */
unsigned int prod;
/** Consumer index */
@@ -985,6 +990,11 @@ intelxl_init_ring ( struct intelxl_ring *ring, unsigned int count, size_t len,
/** Time to delay for device reset, in milliseconds */
#define INTELXL_RESET_DELAY_MS 100
+/** Function Requester ID Information Register */
+#define INTELXL_PFFUNC_RID 0x09c000
+#define INTELXL_PFFUNC_RID_FUNC_NUM(x) \
+ ( ( (x) >> 0 ) & 0x3 ) /**< Function number */
+
/** PF Queue Allocation Register */
#define INTELXL_PFLAN_QALLOC 0x1c0400
#define INTELXL_PFLAN_QALLOC_FIRSTQ(x) \
@@ -1005,6 +1015,12 @@ intelxl_init_ring ( struct intelxl_ring *ring, unsigned int count, size_t len,
#define INTELXL_PRTGL_SAH_MFS_GET(x) ( (x) >> 16 ) /**< Max frame size */
#define INTELXL_PRTGL_SAH_MFS_SET(x) ( (x) << 16 ) /**< Max frame size */
+/** Physical Function MAC Address Low Register */
+#define INTELXL_PRTPM_SAL 0x1e4440
+
+/** Physical Function MAC Address High Register */
+#define INTELXL_PRTPM_SAH 0x1e44c0
+
/** Receive address */
union intelxl_receive_address {
struct {
@@ -1014,10 +1030,22 @@ union intelxl_receive_address {
uint8_t raw[ETH_ALEN];
};
+/** MSI-X interrupt */
+struct intelxl_msix {
+ /** PCI capability */
+ struct pci_msix cap;
+ /** MSI-X dummy interrupt target */
+ uint32_t msg;
+ /** DMA mapping for dummy interrupt target */
+ struct dma_mapping map;
+};
+
/** An Intel 40Gigabit network card */
struct intelxl_nic {
/** Registers */
void *regs;
+ /** DMA device */
+ struct dma_device *dma;
/** Maximum frame size */
size_t mfs;
@@ -1035,12 +1063,10 @@ struct intelxl_nic {
unsigned int qset;
/** Interrupt control register */
unsigned int intr;
- /** MSI-X capability */
- struct pci_msix msix;
- /** MSI-X dummy interrupt target */
- uint32_t msg;
/** PCI Express capability offset */
unsigned int exp;
+ /** MSI-X interrupt */
+ struct intelxl_msix msix;
/** Admin command queue */
struct intelxl_admin command;
diff --git a/src/drivers/net/intelxlvf.c b/src/drivers/net/intelxlvf.c
index 8f76daf3d..752de7815 100644
--- a/src/drivers/net/intelxlvf.c
+++ b/src/drivers/net/intelxlvf.c
@@ -298,9 +298,9 @@ void intelxlvf_admin_event ( struct net_device *netdev,
if ( intelxl->vret != 0 ) {
DBGC ( intelxl, "INTELXL %p admin VF command %#x "
"error %d\n", intelxl, vopcode, intelxl->vret );
- DBGC_HDA ( intelxl, virt_to_bus ( evt ), evt,
+ DBGC_HDA ( intelxl, virt_to_phys ( evt ), evt,
sizeof ( *evt ) );
- DBGC_HDA ( intelxl, virt_to_bus ( buf ), buf,
+ DBGC_HDA ( intelxl, virt_to_phys ( buf ), buf,
le16_to_cpu ( evt->len ) );
}
return;
@@ -314,8 +314,10 @@ void intelxlvf_admin_event ( struct net_device *netdev,
default:
DBGC ( intelxl, "INTELXL %p unrecognised VF event %#x:\n",
intelxl, vopcode );
- DBGC_HDA ( intelxl, 0, evt, sizeof ( *evt ) );
- DBGC_HDA ( intelxl, 0, buf, le16_to_cpu ( evt->len ) );
+ DBGC_HDA ( intelxl, virt_to_phys ( evt ), evt,
+ sizeof ( *evt ) );
+ DBGC_HDA ( intelxl, virt_to_phys ( buf ), buf,
+ le16_to_cpu ( evt->len ) );
break;
}
}
@@ -378,12 +380,14 @@ static int intelxlvf_admin_configure ( struct net_device *netdev ) {
buf->cfg.count = cpu_to_le16 ( 1 );
buf->cfg.tx.vsi = cpu_to_le16 ( intelxl->vsi );
buf->cfg.tx.count = cpu_to_le16 ( INTELXL_TX_NUM_DESC );
- buf->cfg.tx.base = cpu_to_le64 ( virt_to_bus ( intelxl->tx.desc.raw ) );
+ buf->cfg.tx.base = cpu_to_le64 ( dma ( &intelxl->tx.map,
+ intelxl->tx.desc.raw ) );
buf->cfg.rx.vsi = cpu_to_le16 ( intelxl->vsi );
buf->cfg.rx.count = cpu_to_le32 ( INTELXL_RX_NUM_DESC );
buf->cfg.rx.len = cpu_to_le32 ( intelxl->mfs );
buf->cfg.rx.mfs = cpu_to_le32 ( intelxl->mfs );
- buf->cfg.rx.base = cpu_to_le64 ( virt_to_bus ( intelxl->rx.desc.raw ) );
+ buf->cfg.rx.base = cpu_to_le64 ( dma ( &intelxl->rx.map,
+ intelxl->rx.desc.raw ) );
/* Issue command */
if ( ( rc = intelxlvf_admin_command ( netdev ) ) != 0 )
@@ -612,12 +616,17 @@ static int intelxlvf_probe ( struct pci_device *pci ) {
adjust_pci_device ( pci );
/* Map registers */
- intelxl->regs = ioremap ( pci->membase, INTELXLVF_BAR_SIZE );
+ intelxl->regs = pci_ioremap ( pci, pci->membase, INTELXLVF_BAR_SIZE );
if ( ! intelxl->regs ) {
rc = -ENODEV;
goto err_ioremap;
}
+ /* Configure DMA */
+ intelxl->dma = &pci->dma;
+ dma_set_mask_64bit ( intelxl->dma );
+ netdev->dma = intelxl->dma;
+
/* Locate PCI Express capability */
intelxl->exp = pci_find_capability ( pci, PCI_CAP_ID_EXP );
if ( ! intelxl->exp ) {
diff --git a/src/drivers/net/intelxvf.c b/src/drivers/net/intelxvf.c
index 2caeec27e..f0ba091d5 100644
--- a/src/drivers/net/intelxvf.c
+++ b/src/drivers/net/intelxvf.c
@@ -456,12 +456,17 @@ static int intelxvf_probe ( struct pci_device *pci ) {
adjust_pci_device ( pci );
/* Map registers */
- intel->regs = ioremap ( pci->membase, INTELVF_BAR_SIZE );
+ intel->regs = pci_ioremap ( pci, pci->membase, INTELVF_BAR_SIZE );
if ( ! intel->regs ) {
rc = -ENODEV;
goto err_ioremap;
}
+ /* Configure DMA */
+ intel->dma = &pci->dma;
+ dma_set_mask_64bit ( intel->dma );
+ netdev->dma = intel->dma;
+
/* Reset the function */
intelxvf_reset ( intel );
diff --git a/src/drivers/net/iphone.c b/src/drivers/net/iphone.c
new file mode 100644
index 000000000..7d0eb4b64
--- /dev/null
+++ b/src/drivers/net/iphone.c
@@ -0,0 +1,2268 @@
+/*
+ * Copyright (C) 2020 Michael Brown <mbrown@fensystems.co.uk>.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+
+#include <stdint.h>
+#include <string.h>
+#include <stdio.h>
+#include <errno.h>
+#include <ipxe/netdevice.h>
+#include <ipxe/ethernet.h>
+#include <ipxe/if_ether.h>
+#include <ipxe/profile.h>
+#include <ipxe/base64.h>
+#include <ipxe/sha256.h>
+#include <ipxe/rsa.h>
+#include <ipxe/x509.h>
+#include <ipxe/pem.h>
+#include <ipxe/xfer.h>
+#include <ipxe/tls.h>
+#include <ipxe/usb.h>
+#include "iphone.h"
+
+/** @file
+ *
+ * iPhone USB Ethernet driver
+ *
+ */
+
+/* Disambiguate the various error causes */
+#define EPIPE_NO_MUX __einfo_error ( EINFO_EPIPE_NO_MUX )
+#define EINFO_EPIPE_NO_MUX \
+ __einfo_uniqify ( EINFO_EPIPE, 0x01, \
+ "No USB multiplexer" )
+#define EINPROGRESS_PAIRING __einfo_error ( EINFO_EINPROGRESS_PAIRING )
+#define EINFO_EINPROGRESS_PAIRING \
+ __einfo_uniqify ( EINFO_EINPROGRESS, 0x01, \
+ "Pairing in progress" )
+#define ENOTCONN_DISABLED __einfo_error ( EINFO_ENOTCONN_DISABLED )
+#define EINFO_ENOTCONN_DISABLED \
+ __einfo_uniqify ( EINFO_ENOTCONN, IPHONE_LINK_DISABLED, \
+ "Personal Hotspot disabled" )
+#define ENOTCONN_STATUS( status ) \
+ EUNIQ ( EINFO_ENOTCONN, ( (status) & 0x1f ), \
+ ENOTCONN_DISABLED )
+
+static int ipair_create ( struct interface *xfer, unsigned int flags );
+
+/** Bulk IN completion profiler */
+static struct profiler iphone_in_profiler __profiler =
+ { .name = "iphone.in" };
+
+/** Bulk OUT profiler */
+static struct profiler iphone_out_profiler __profiler =
+ { .name = "iphone.out" };
+
+/** List of USB multiplexers */
+static LIST_HEAD ( imuxes );
+
+/** List of iPhone network devices */
+static LIST_HEAD ( iphones );
+
+/******************************************************************************
+ *
+ * iPhone pairing certificates
+ *
+ ******************************************************************************
+ */
+
+/** iPhone root certificate fingerprint */
+static uint8_t icert_root_fingerprint[SHA256_DIGEST_SIZE];
+
+/** Root of trust for iPhone certificates */
+static struct x509_root icert_root = {
+ .refcnt = REF_INIT ( ref_no_free ),
+ .digest = &sha256_algorithm,
+ .count = 1,
+ .fingerprints = icert_root_fingerprint,
+};
+
+/** Single zero byte used in constructed certificates */
+static const uint8_t icert_nul[] = { 0x00 };
+
+/** "RSA algorithm" identifier used in constructed certificates */
+static const uint8_t icert_rsa[] = {
+ /* algorithm */
+ ASN1_SHORT ( ASN1_SEQUENCE,
+ ASN1_SHORT ( ASN1_OID, ASN1_OID_RSAENCRYPTION ),
+ ASN1_NULL, 0x00 )
+};
+
+/** "SHA-256 with RSA algorithm" identifier used in constructed certificates */
+static const uint8_t icert_sha256_rsa[] = {
+ ASN1_SHORT ( ASN1_SEQUENCE,
+ ASN1_SHORT ( ASN1_OID, ASN1_OID_SHA256WITHRSAENCRYPTION ),
+ ASN1_NULL, 0x00 ),
+};
+
+/** Extensions used in constructed root certificate */
+static const uint8_t icert_root_exts_data[] = {
+ /* extensions */
+ ASN1_SHORT ( ASN1_EXPLICIT_TAG ( 3 ), ASN1_SHORT ( ASN1_SEQUENCE,
+ /* basicConstraints */
+ ASN1_SHORT ( ASN1_SEQUENCE,
+ /* extnID */
+ ASN1_SHORT ( ASN1_OID, ASN1_OID_BASICCONSTRAINTS ),
+ /* critical */
+ ASN1_SHORT ( ASN1_BOOLEAN, 0xff ),
+ /* extnValue */
+ ASN1_SHORT ( ASN1_OCTET_STRING,
+ ASN1_SHORT ( ASN1_SEQUENCE,
+ ASN1_SHORT ( ASN1_BOOLEAN,
+ 0xff ) ) ) ) ) )
+};
+
+/** Extensions used in constructed root certificate */
+static struct asn1_cursor icert_root_exts =
+ ASN1_CURSOR ( icert_root_exts_data );
+
+/** Extensions used in constructed leaf certificates */
+static const uint8_t icert_leaf_exts_data[] = {
+ /* extensions */
+ ASN1_SHORT ( ASN1_EXPLICIT_TAG ( 3 ), ASN1_SHORT ( ASN1_SEQUENCE,
+ /* basicConstraints */
+ ASN1_SHORT ( ASN1_SEQUENCE,
+ /* extnID */
+ ASN1_SHORT ( ASN1_OID, ASN1_OID_BASICCONSTRAINTS ),
+ /* critical */
+ ASN1_SHORT ( ASN1_BOOLEAN, 0xff ),
+ /* extnValue */
+ ASN1_SHORT ( ASN1_OCTET_STRING,
+ ASN1_SHORT ( ASN1_SEQUENCE,
+ ASN1_SHORT ( ASN1_BOOLEAN,
+ 0x00 ) ) ) ),
+ /* keyUsage */
+ ASN1_SHORT ( ASN1_SEQUENCE,
+ /* extnID */
+ ASN1_SHORT ( ASN1_OID, ASN1_OID_KEYUSAGE ),
+ /* critical */
+ ASN1_SHORT ( ASN1_BOOLEAN, 0xff ),
+ /* extnValue */
+ ASN1_SHORT ( ASN1_OCTET_STRING,
+ ASN1_SHORT ( ASN1_BIT_STRING, 0x07,
+ ( X509_DIGITAL_SIGNATURE |
+ X509_KEY_ENCIPHERMENT ),
+ 0x00 ) ) ) ) )
+};
+
+/** Extensions used in constructed leaf certificates */
+static struct asn1_cursor icert_leaf_exts =
+ ASN1_CURSOR ( icert_leaf_exts_data );
+
+/** "TBSCertificate" prefix in constructed certificates */
+static const uint8_t icert_tbs_prefix[] = {
+ /* version */
+ ASN1_SHORT ( ASN1_EXPLICIT_TAG ( 0 ), ASN1_SHORT ( ASN1_INTEGER, 2 ) ),
+ /* serialNumber */
+ ASN1_SHORT ( ASN1_INTEGER, 0 ),
+ /* signature */
+ ASN1_SHORT ( ASN1_SEQUENCE,
+ ASN1_SHORT ( ASN1_OID, ASN1_OID_SHA256WITHRSAENCRYPTION ),
+ ASN1_NULL, 0x00 )
+};
+
+/** Validity period in constructed certificates */
+static const uint8_t icert_validity[] = {
+ /* validity */
+ ASN1_SHORT ( ASN1_SEQUENCE,
+ /* notBefore */
+ ASN1_SHORT ( ASN1_GENERALIZED_TIME,
+ '1', '9', '7', '8', '1', '2', '1', '0',
+ '2', '2', '0', '0', '0', '0', 'Z' ),
+ /* notAfter */
+ ASN1_SHORT ( ASN1_GENERALIZED_TIME,
+ '2', '9', '9', '9', '0', '1', '0', '1',
+ '0', '0', '0', '0', '0', '0', 'Z' ) )
+};
+
+/** "Root" subject name */
+static const uint8_t icert_name_root_data[] = {
+ ASN1_SHORT ( ASN1_SEQUENCE, ASN1_SHORT ( ASN1_SET,
+ ASN1_SHORT ( ASN1_SEQUENCE,
+ ASN1_SHORT ( ASN1_OID, ASN1_OID_COMMON_NAME ),
+ ASN1_SHORT ( ASN1_UTF8_STRING, 'R', 'o', 'o', 't' ) ) ) )
+};
+
+/** "Root" subject name */
+static struct asn1_cursor icert_name_root =
+ ASN1_CURSOR ( icert_name_root_data );
+
+/** "iPXE" subject name */
+static const uint8_t icert_name_ipxe_data[] = {
+ ASN1_SHORT ( ASN1_SEQUENCE, ASN1_SHORT ( ASN1_SET,
+ ASN1_SHORT ( ASN1_SEQUENCE,
+ ASN1_SHORT ( ASN1_OID, ASN1_OID_COMMON_NAME ),
+ ASN1_SHORT ( ASN1_UTF8_STRING, 'i', 'P', 'X', 'E' ) ) ) )
+};
+
+/** "iPXE" subject name */
+static struct asn1_cursor icert_name_ipxe =
+ ASN1_CURSOR ( icert_name_ipxe_data );
+
+/** "iPhone" subject name */
+static const uint8_t icert_name_iphone_data[] = {
+ ASN1_SHORT ( ASN1_SEQUENCE, ASN1_SHORT ( ASN1_SET,
+ ASN1_SHORT ( ASN1_SEQUENCE,
+ ASN1_SHORT ( ASN1_OID, ASN1_OID_COMMON_NAME ),
+ ASN1_SHORT ( ASN1_UTF8_STRING,
+ 'i', 'P', 'h', 'o', 'n', 'e' ) ) ) )
+};
+
+/** "iPhone" subject name */
+static struct asn1_cursor icert_name_iphone =
+ ASN1_CURSOR ( icert_name_iphone_data );
+
+/** Public key(s) used for pairing */
+static const uint8_t icert_public_a[] __unused = {
+ 0x02, 0x81, 0x81, 0x00, 0xc9, 0xc0, 0xdd, 0xa6, 0xd5, 0xf9, 0x05, 0x3e,
+ 0x1d, 0xcb, 0x67, 0x08, 0xa8, 0x50, 0x27, 0x63, 0x95, 0x87, 0x42, 0x7e,
+ 0xfb, 0xff, 0x55, 0x55, 0xb8, 0xc0, 0x6f, 0x13, 0xcb, 0xf7, 0xc5, 0x1b,
+ 0xda, 0x44, 0x3c, 0xbc, 0x1a, 0xe1, 0x15, 0x1e, 0xab, 0x56, 0x74, 0x02,
+ 0x8b, 0xb3, 0xcd, 0x42, 0x56, 0xcd, 0x9c, 0xc3, 0x15, 0xe2, 0x33, 0x97,
+ 0x6d, 0x77, 0xdd, 0x20, 0x3a, 0x74, 0xb1, 0x4c, 0xee, 0xeb, 0xe8, 0xaa,
+ 0x20, 0x71, 0x5a, 0xa2, 0x5b, 0xf8, 0x1a, 0xcb, 0xd2, 0x7b, 0x96, 0xb6,
+ 0x42, 0xb4, 0x7c, 0x7a, 0x13, 0xec, 0x55, 0xd3, 0x36, 0x8b, 0xe3, 0x17,
+ 0xc5, 0xc4, 0xcc, 0xe0, 0x27, 0x8c, 0xed, 0xa1, 0x4c, 0x8a, 0x50, 0x4a,
+ 0x1c, 0xc4, 0x58, 0xf6, 0xcd, 0xcc, 0xc3, 0x5f, 0xe6, 0x3c, 0xff, 0x97,
+ 0x51, 0xed, 0xf5, 0xaa, 0x89, 0xcc, 0x3f, 0x63, 0x67, 0x46, 0x9f, 0xbf,
+ 0x02, 0x03, 0x01, 0x00, 0x01
+};
+static const uint8_t icert_public_b[] __unused = {
+ 0x02, 0x81, 0x81, 0x00, 0xcd, 0x96, 0x81, 0x78, 0xbb, 0x2e, 0x64, 0xda,
+ 0xd3, 0x7e, 0xd7, 0x3a, 0xac, 0x3f, 0x00, 0xe5, 0x41, 0x65, 0x56, 0xac,
+ 0x2d, 0x77, 0xc0, 0x1a, 0xad, 0x32, 0xca, 0x0c, 0x72, 0xae, 0xdb, 0x57,
+ 0xc1, 0xc7, 0x79, 0xef, 0xc6, 0x71, 0x9f, 0xad, 0x82, 0x14, 0x94, 0x4b,
+ 0xf9, 0xd8, 0x78, 0xf1, 0xca, 0x99, 0xf5, 0x71, 0x07, 0x88, 0xd7, 0x55,
+ 0xc7, 0xcb, 0x36, 0x5d, 0xdb, 0x84, 0x46, 0xac, 0x05, 0xea, 0xf1, 0xe1,
+ 0xbe, 0x91, 0x50, 0x85, 0x1e, 0x64, 0xab, 0x02, 0x82, 0xab, 0xba, 0x42,
+ 0x06, 0x5a, 0xe3, 0xc3, 0x25, 0xd0, 0x95, 0x04, 0x54, 0xb4, 0x44, 0x40,
+ 0x5a, 0x42, 0x06, 0x04, 0x7d, 0x3b, 0x9e, 0xaf, 0x2e, 0xe9, 0xc8, 0xad,
+ 0x46, 0x3a, 0xff, 0xe2, 0x39, 0xc8, 0x48, 0x0a, 0x49, 0xaa, 0xfe, 0x1f,
+ 0x6c, 0x91, 0x5d, 0x1d, 0xd6, 0xb0, 0x04, 0xd1, 0x6c, 0xb2, 0x43, 0xaf,
+ 0x02, 0x03, 0x01, 0x00, 0x01
+};
+
+/**
+ * "Private" key(s) used for pairing
+ *
+ * Yes, this publicly visible "private" key completely obviates any
+ * nominal security provided by the pairing process. Looked at
+ * another way, this modifies the iPhone to behave like every other
+ * USB tethering device: if the cable is physically connected and
+ * tethering is enabled then the device will Just Work.
+ *
+ * Unlike Android, the iPhone seems to have no meaningful permissions
+ * model: any device that is trusted to use the phone for tethering
+ * seems to also be trusted to use the iPhone for any other purpose
+ * (e.g. accessing files, reading messages, etc). Apple should
+ * probably fix this at some point, e.g. via defining extended key
+ * usages in the root and host certificates.
+ */
+static const uint8_t icert_private_a[] __unused = {
+ 0x02, 0x81, 0x80, 0x1d, 0x60, 0xb7, 0x25, 0xdf, 0x0c, 0x76, 0xc5, 0xf7,
+ 0xc2, 0xb1, 0x8b, 0x22, 0x2f, 0x21, 0xbd, 0x2f, 0x7d, 0xd5, 0xa1, 0xf6,
+ 0x01, 0xd5, 0x24, 0x39, 0x55, 0xd4, 0x16, 0xd6, 0xe1, 0x8a, 0x53, 0x26,
+ 0xf2, 0x3e, 0xc1, 0xc9, 0x4c, 0x33, 0x2e, 0x17, 0x16, 0xec, 0xa7, 0x9e,
+ 0x3e, 0x1d, 0x4a, 0x66, 0xa7, 0x64, 0x07, 0x48, 0x3d, 0x7a, 0xf3, 0xb6,
+ 0xdd, 0xf8, 0x56, 0x04, 0x0d, 0x0f, 0xef, 0xf8, 0xbd, 0xbc, 0x73, 0xe2,
+ 0xc2, 0xae, 0x1b, 0x87, 0x90, 0x18, 0x2a, 0x68, 0xff, 0xae, 0x49, 0xdf,
+ 0x7c, 0xff, 0xe8, 0x44, 0xa8, 0x3e, 0x4e, 0x4f, 0xf5, 0xfa, 0x51, 0x96,
+ 0xb8, 0x08, 0xf3, 0x18, 0xd6, 0x52, 0xdf, 0x3a, 0x8a, 0xed, 0xda, 0xcd,
+ 0xb4, 0x06, 0x99, 0x41, 0xcb, 0x23, 0x17, 0xaf, 0xc3, 0x3e, 0xfe, 0xdf,
+ 0x97, 0xf3, 0xd6, 0x18, 0x7e, 0x03, 0xaf, 0x62, 0xb2, 0xc8, 0xc9
+};
+static const uint8_t icert_private_b[] __unused = {
+ 0x02, 0x81, 0x80, 0x45, 0xbd, 0xc0, 0xbe, 0x0c, 0x01, 0x79, 0x05, 0x22,
+ 0xa9, 0xec, 0xa9, 0x62, 0xb5, 0x1c, 0xc0, 0xa8, 0xa6, 0x8f, 0xf8, 0x68,
+ 0x94, 0x2e, 0xfe, 0xdd, 0xb2, 0x55, 0x08, 0x53, 0xff, 0x2d, 0x39, 0x5f,
+ 0xeb, 0x23, 0x5a, 0x4b, 0x9f, 0x4f, 0xe3, 0xb4, 0x34, 0xf6, 0xf9, 0xaf,
+ 0x0f, 0xd8, 0x37, 0x6d, 0xdb, 0x3c, 0x7f, 0xd3, 0x66, 0x80, 0x66, 0x01,
+ 0x18, 0xd6, 0xa0, 0x90, 0x4f, 0x17, 0x09, 0xb8, 0x68, 0x44, 0xf0, 0xde,
+ 0x16, 0x4a, 0x8a, 0x0d, 0xa7, 0x5f, 0xb5, 0x4c, 0x53, 0xcc, 0x21, 0xdd,
+ 0x4f, 0x05, 0x64, 0xa5, 0xc5, 0xac, 0x2c, 0xd8, 0x0a, 0x7b, 0xf5, 0xa4,
+ 0x63, 0x32, 0xb0, 0x2c, 0xf8, 0xef, 0x8c, 0xf8, 0x2c, 0xba, 0x1c, 0x2c,
+ 0xc7, 0x0a, 0xf3, 0xe9, 0x8f, 0xfb, 0x0a, 0x61, 0x1b, 0x3a, 0xdd, 0x9f,
+ 0x74, 0x7d, 0xb3, 0x42, 0x59, 0x52, 0x07, 0x59, 0x8e, 0xb7, 0x41
+};
+
+/** Key pair selection
+ *
+ * This exists only to allow for testing of the process for handling a
+ * failed TLS negotiation.
+ */
+#define icert_key_suffix a
+#define icert_key_variable( prefix ) _C2 ( prefix, icert_key_suffix )
+#define icert_public icert_key_variable ( icert_public_ )
+#define icert_private icert_key_variable ( icert_private_ )
+
+/** PEM certificate prefix */
+static const char icert_begin[] = "-----BEGIN CERTIFICATE-----\n";
+
+/** PEM certificate suffix */
+static const char icert_end[] = "\n-----END CERTIFICATE-----\n";
+
+/**
+ * Free pairing certificates
+ *
+ * @v icert Pairing certificates
+ */
+static void icert_free ( struct icert *icert ) {
+
+ privkey_put ( icert->key );
+ x509_put ( icert->root );
+ x509_put ( icert->host );
+ x509_put ( icert->device );
+ memset ( icert, 0, sizeof ( *icert ) );
+}
+
+/**
+ * Construct certificate
+ *
+ * @v icert Pairing certificates
+ * @v subject Subject name
+ * @v issuer Issuer name
+ * @v private Private key
+ * @v public Public key
+ * @v exts Certificate extensions
+ * @v cert Certificate to fill in
+ * @ret rc Return status code
+ *
+ * On success, the caller is responsible for eventually calling
+ * x509_put() on the allocated encoded certificate.
+ */
+static int icert_cert ( struct icert *icert, struct asn1_cursor *subject,
+ struct asn1_cursor *issuer, struct asn1_cursor *private,
+ struct asn1_cursor *public, struct asn1_cursor *exts,
+ struct x509_certificate **cert ) {
+ struct digest_algorithm *digest = &sha256_algorithm;
+ struct pubkey_algorithm *pubkey = &rsa_algorithm;
+ struct asn1_builder spki = { NULL, 0 };
+ struct asn1_builder tbs = { NULL, 0 };
+ struct asn1_builder raw = { NULL, 0 };
+ uint8_t digest_ctx[SHA256_CTX_SIZE];
+ uint8_t digest_out[SHA256_DIGEST_SIZE];
+ uint8_t pubkey_ctx[RSA_CTX_SIZE];
+ int len;
+ int rc;
+
+ /* Initialise "private" key */
+ if ( ( rc = pubkey_init ( pubkey, pubkey_ctx, private->data,
+ private->len ) ) != 0 ) {
+ DBGC ( icert, "ICERT %p could not initialise private key: "
+ "%s\n", icert, strerror ( rc ) );
+ goto err_pubkey_init;
+ }
+
+ /* Construct subjectPublicKeyInfo */
+ if ( ( rc = ( asn1_prepend_raw ( &spki, public->data, public->len ),
+ asn1_prepend_raw ( &spki, icert_nul,
+ sizeof ( icert_nul ) ),
+ asn1_wrap ( &spki, ASN1_BIT_STRING ),
+ asn1_prepend_raw ( &spki, icert_rsa,
+ sizeof ( icert_rsa ) ),
+ asn1_wrap ( &spki, ASN1_SEQUENCE ) ) ) != 0 ) {
+ DBGC ( icert, "ICERT %p could not build subjectPublicKeyInfo: "
+ "%s\n", icert, strerror ( rc ) );
+ goto err_spki;
+ }
+
+ /* Construct tbsCertificate */
+ if ( ( rc = ( asn1_prepend_raw ( &tbs, exts->data, exts->len ),
+ asn1_prepend_raw ( &tbs, spki.data, spki.len ),
+ asn1_prepend_raw ( &tbs, subject->data, subject->len ),
+ asn1_prepend_raw ( &tbs, icert_validity,
+ sizeof ( icert_validity ) ),
+ asn1_prepend_raw ( &tbs, issuer->data, issuer->len ),
+ asn1_prepend_raw ( &tbs, icert_tbs_prefix,
+ sizeof ( icert_tbs_prefix ) ),
+ asn1_wrap ( &tbs, ASN1_SEQUENCE ) ) ) != 0 ) {
+ DBGC ( icert, "ICERT %p could not build tbsCertificate: %s\n",
+ icert, strerror ( rc ) );
+ goto err_tbs;
+ }
+
+ /* Calculate certificate digest */
+ digest_init ( digest, digest_ctx );
+ digest_update ( digest, digest_ctx, tbs.data, tbs.len );
+ digest_final ( digest, digest_ctx, digest_out );
+
+ /* Construct signature */
+ if ( ( rc = asn1_grow ( &raw, pubkey_max_len ( pubkey,
+ pubkey_ctx ) ) ) != 0 ) {
+ DBGC ( icert, "ICERT %p could not build signature: %s\n",
+ icert, strerror ( rc ) );
+ goto err_grow;
+ }
+ if ( ( len = pubkey_sign ( pubkey, pubkey_ctx, digest, digest_out,
+ raw.data ) ) < 0 ) {
+ rc = len;
+ DBGC ( icert, "ICERT %p could not sign: %s\n",
+ icert, strerror ( rc ) );
+ goto err_pubkey_sign;
+ }
+ assert ( ( ( size_t ) len ) == raw.len );
+
+ /* Construct raw certificate data */
+ if ( ( rc = ( asn1_prepend_raw ( &raw, icert_nul,
+ sizeof ( icert_nul ) ),
+ asn1_wrap ( &raw, ASN1_BIT_STRING ),
+ asn1_prepend_raw ( &raw, icert_sha256_rsa,
+ sizeof ( icert_sha256_rsa ) ),
+ asn1_prepend_raw ( &raw, tbs.data, tbs.len ),
+ asn1_wrap ( &raw, ASN1_SEQUENCE ) ) ) != 0 ) {
+ DBGC ( icert, "ICERT %p could not build certificate: %s\n",
+ icert, strerror ( rc ) );
+ goto err_raw;
+ }
+
+ /* Parse certificate */
+ if ( ( rc = x509_certificate ( raw.data, raw.len, cert ) ) != 0 ) {
+ DBGC ( icert, "ICERT %p invalid certificate: %s\n",
+ icert, strerror ( rc ) );
+ DBGC_HDA ( icert, 0, raw.data, raw.len );
+ goto err_x509;
+ }
+
+ err_x509:
+ err_raw:
+ err_pubkey_sign:
+ free ( raw.data );
+ err_grow:
+ free ( tbs.data );
+ err_tbs:
+ free ( spki.data );
+ err_spki:
+ pubkey_final ( pubkey, pubkey_ctx );
+ err_pubkey_init:
+ return rc;
+}
+
+/**
+ * Construct certificates
+ *
+ * @v icert Certificate set
+ * @v pubkey Device public key
+ * @ret rc Return status code
+ */
+static int icert_certs ( struct icert *icert, struct asn1_cursor *key ) {
+ struct digest_algorithm *digest = icert_root.digest;
+ struct asn1_builder public = { NULL, 0 };
+ struct asn1_builder *private;
+ int rc;
+
+ /* Free any existing key and certificates */
+ icert_free ( icert );
+
+ /* Allocate "private" key */
+ icert->key = zalloc ( sizeof ( *icert->key ) );
+ if ( ! icert->key ) {
+ rc = -ENOMEM;
+ goto error;
+ }
+ privkey_init ( icert->key );
+ private = &icert->key->builder;
+
+ /* Construct our "private" key */
+ if ( ( rc = ( asn1_prepend_raw ( private, icert_private,
+ sizeof ( icert_private ) ),
+ asn1_prepend_raw ( private, icert_public,
+ sizeof ( icert_public ) ),
+ asn1_prepend ( private, ASN1_INTEGER, icert_nul,
+ sizeof ( icert_nul ) ),
+ asn1_wrap ( private, ASN1_SEQUENCE ) ) ) != 0 ) {
+ DBGC ( icert, "ICERT %p could not build private key: %s\n",
+ icert, strerror ( rc ) );
+ goto error;
+ }
+
+ /* Construct our own public key */
+ if ( ( rc = ( asn1_prepend_raw ( &public, icert_public,
+ sizeof ( icert_public ) ),
+ asn1_wrap ( &public, ASN1_SEQUENCE ) ) ) != 0 ) {
+ DBGC ( icert, "ICERT %p could not build public key: %s\n",
+ icert, strerror ( rc ) );
+ goto error;
+ }
+
+ /* Construct root certificate */
+ if ( ( rc = icert_cert ( icert, &icert_name_root, &icert_name_root,
+ asn1_built ( private ), asn1_built ( &public ),
+ &icert_root_exts, &icert->root ) ) != 0 )
+ goto error;
+
+ /* Construct host certificate */
+ if ( ( rc = icert_cert ( icert, &icert_name_ipxe, &icert_name_root,
+ asn1_built ( private ), asn1_built ( &public ),
+ &icert_leaf_exts, &icert->host ) ) != 0 )
+ goto error;
+
+ /* Construct device certificate */
+ if ( ( rc = icert_cert ( icert, &icert_name_iphone, &icert_name_root,
+ asn1_built ( private ), key,
+ &icert_leaf_exts, &icert->device ) ) != 0 )
+ goto error;
+
+ /* Construct root of trust */
+ assert ( digest->digestsize == sizeof ( icert_root_fingerprint ) );
+ x509_fingerprint ( icert->root, digest, icert_root_fingerprint );
+
+ /* Free constructed keys */
+ free ( public.data );
+ return 0;
+
+ error:
+ icert_free ( icert );
+ free ( public.data );
+ return rc;
+}
+
+/**
+ * Construct doubly base64-encoded certificate
+ *
+ * @v icert Pairing certificates
+ * @v cert X.509 certificate
+ * @v encenc Doubly base64-encoded certificate to construct
+ * @ret rc Return status code
+ *
+ * On success, the caller is responsible for eventually calling free()
+ * on the allocated doubly encoded encoded certificate.
+ */
+static int icert_encode ( struct icert *icert, struct x509_certificate *cert,
+ char **encenc ) {
+ size_t encencoded_len;
+ size_t encoded_len;
+ size_t pem_len;
+ char *pem;
+ int rc;
+
+ /* Sanity check */
+ assert ( cert != NULL );
+
+ /* Create PEM */
+ encoded_len = ( base64_encoded_len ( cert->raw.len ) + 1 /* NUL */ );
+ pem_len = ( ( sizeof ( icert_begin ) - 1 /* NUL */ ) +
+ ( encoded_len - 1 /* NUL */ ) +
+ ( sizeof ( icert_end ) - 1 /* NUL */ ) +
+ 1 /* NUL */ );
+ pem = malloc ( pem_len );
+ if ( ! pem ) {
+ rc = -ENOMEM;
+ goto err_alloc_pem;
+ }
+ strcpy ( pem, icert_begin );
+ base64_encode ( cert->raw.data, cert->raw.len,
+ ( pem + sizeof ( icert_begin ) - 1 /* NUL */ ),
+ encoded_len );
+ strcpy ( ( pem +
+ ( sizeof ( icert_begin ) - 1 /* NUL */ ) +
+ ( encoded_len - 1 /* NUL */ ) ), icert_end );
+ DBGC2 ( icert, "ICERT %p \"%s\" certificate:\n%s",
+ icert, x509_name ( cert ), pem );
+
+ /* Base64-encode the PEM (sic) */
+ encencoded_len = ( base64_encoded_len ( pem_len - 1 /* NUL */ )
+ + 1 /* NUL */ );
+ *encenc = malloc ( encencoded_len );
+ if ( ! *encenc ) {
+ rc = -ENOMEM;
+ goto err_alloc_encenc;
+ }
+ base64_encode ( pem, ( pem_len - 1 /* NUL */ ), *encenc,
+ encencoded_len );
+
+ /* Success */
+ rc = 0;
+
+ err_alloc_encenc:
+ free ( pem );
+ err_alloc_pem:
+ return rc;
+}
+
+/******************************************************************************
+ *
+ * iPhone USB multiplexer
+ *
+ ******************************************************************************
+ *
+ * The iPhone USB multiplexer speaks a protocol that is almost, but
+ * not quite, entirely unlike TCP.
+ *
+ */
+
+/**
+ * Transmit message
+ *
+ * @v imux USB multiplexer
+ * @v iobuf I/O buffer
+ * @ret rc Return status code
+ */
+static int imux_tx ( struct imux *imux, struct io_buffer *iobuf ) {
+ struct imux_header *hdr = iobuf->data;
+ size_t len = iob_len ( iobuf );
+ int rc;
+
+ /* Populate header */
+ assert ( len >= sizeof ( *hdr ) );
+ hdr->len = htonl ( len );
+ hdr->in_seq = htons ( imux->in_seq );
+ hdr->out_seq = htons ( imux->out_seq );
+ DBGCP ( imux, "IMUX %p transmitting:\n", imux );
+ DBGCP_HDA ( imux, 0, hdr, len );
+
+ /* Transmit message */
+ if ( ( rc = usb_stream ( &imux->usbnet.out, iobuf, 1 ) ) != 0 )
+ goto err;
+
+ /* Increment sequence number */
+ imux->out_seq++;
+
+ return 0;
+
+ err:
+ free_iob ( iobuf );
+ return rc;
+}
+
+/**
+ * Transmit version message
+ *
+ * @v imux USB multiplexer
+ * @ret rc Return status code
+ */
+static int imux_tx_version ( struct imux *imux ) {
+ struct io_buffer *iobuf;
+ struct imux_header_version *vers;
+ int rc;
+
+ /* Allocate I/O buffer */
+ iobuf = alloc_iob ( sizeof ( *vers ) );
+ if ( ! iobuf )
+ return -ENOMEM;
+ vers = iob_put ( iobuf, sizeof ( *vers ) );
+
+ /* Construct version message */
+ memset ( vers, 0, sizeof ( *vers ) );
+ vers->hdr.protocol = htonl ( IMUX_VERSION );
+
+ /* Transmit message */
+ if ( ( rc = imux_tx ( imux, iob_disown ( iobuf ) ) ) != 0 )
+ return rc;
+
+ return 0;
+}
+
+/**
+ * Transmit pseudo-TCP message
+ *
+ * @v imux USB multiplexer
+ * @v iobuf I/O buffer
+ * @ret rc Return status code
+ */
+static int imux_tx_tcp ( struct imux *imux, struct io_buffer *iobuf ) {
+ struct imux_header_tcp *tcp = iobuf->data;
+ size_t len = iob_len ( iobuf );
+ int rc;
+
+ /* Populate TCP header */
+ assert ( len >= sizeof ( *tcp ) );
+ tcp->hdr.protocol = htonl ( IMUX_TCP );
+ tcp->tcp.src = htons ( imux->port );
+ tcp->tcp.dest = htons ( IMUX_PORT_LOCKDOWND );
+ tcp->tcp.seq = htonl ( imux->tcp_seq );
+ tcp->tcp.ack = htonl ( imux->tcp_ack );
+ tcp->tcp.hlen = ( ( sizeof ( tcp->tcp ) / 4 ) << 4 );
+ tcp->tcp.win = htons ( IMUX_WINDOW );
+
+ /* Transmit message */
+ if ( ( rc = imux_tx ( imux, iob_disown ( iobuf ) ) ) != 0 )
+ return rc;
+
+ /* Update TCP sequence */
+ imux->tcp_seq += ( len - sizeof ( *tcp ) );
+
+ return 0;
+}
+
+/**
+ * Transmit pseudo-TCP SYN
+ *
+ * @v imux USB multiplexer
+ * @ret rc Return status code
+ */
+static int imux_tx_syn ( struct imux *imux ) {
+ struct io_buffer *iobuf;
+ struct imux_header_tcp *syn;
+ int rc;
+
+ /* Allocate I/O buffer */
+ iobuf = alloc_iob ( sizeof ( *syn ) );
+ if ( ! iobuf )
+ return -ENOMEM;
+ syn = iob_put ( iobuf, sizeof ( *syn ) );
+
+ /* Construct TCP SYN message */
+ memset ( syn, 0, sizeof ( *syn ) );
+ syn->tcp.flags = TCP_SYN;
+
+ /* Transmit message */
+ if ( ( rc = imux_tx_tcp ( imux, iob_disown ( iobuf ) ) ) != 0 )
+ return rc;
+
+ /* Increment TCP sequence to compensate for SYN */
+ imux->tcp_seq++;
+
+ return 0;
+}
+
+/**
+ * Open pairing client
+ *
+ * @v imux USB multiplexer
+ * @ret rc Return status code
+ */
+static int imux_start_pair ( struct imux *imux ) {
+ int rc;
+
+ /* Disconnect any existing pairing client */
+ intf_restart ( &imux->tcp, -EPIPE );
+
+ /* Create pairing client */
+ if ( ( rc = ipair_create ( &imux->tcp, imux->flags ) ) != 0 )
+ return rc;
+
+ return 0;
+}
+
+/**
+ * Receive version message
+ *
+ * @v imux USB multiplexer
+ */
+static void imux_rx_version ( struct imux *imux ) {
+
+ /* Reset output sequence */
+ imux->out_seq = 0;
+
+ /* Send TCP SYN */
+ imux->action = imux_tx_syn;
+}
+
+/**
+ * Receive log message
+ *
+ * @v imux USB multiplexer
+ * @v hdr Message header
+ * @v len Length of message
+ */
+static void imux_rx_log ( struct imux *imux, struct imux_header *hdr,
+ size_t len ) {
+ struct imux_header_log *log =
+ container_of ( hdr, struct imux_header_log, hdr );
+ unsigned int level;
+ size_t msg_len;
+ char *tmp;
+
+ /* Sanity check */
+ if ( len < sizeof ( *log ) ) {
+ DBGC ( imux, "IMUX %p malformed log message:\n", imux );
+ DBGC_HDA ( imux, 0, log, len );
+ return;
+ }
+
+ /* First byte is the log level, followed by a printable
+ * message with no NUL terminator. Extract the log level,
+ * then shuffle the message down within the buffer and append
+ * a NUL terminator.
+ */
+ msg_len = ( len - sizeof ( *hdr ) );
+ level = log->level;
+ tmp = ( ( void * ) &log->level );
+ memmove ( tmp, &log->msg, msg_len );
+ tmp[msg_len] = '\0';
+
+ /* Print log message */
+ DBGC ( imux, "IMUX %p <%d>: %s\n", imux, level, tmp );
+}
+
+/**
+ * Receive pseudo-TCP SYN+ACK
+ *
+ * @v imux USB multiplexer
+ */
+static void imux_rx_syn ( struct imux *imux ) {
+
+ /* Increment TCP acknowledgement to compensate for SYN */
+ imux->tcp_ack++;
+
+ /* Start pairing client */
+ imux->action = imux_start_pair;
+}
+
+/**
+ * Receive pseudo-TCP message
+ *
+ * @v imux USB multiplexer
+ * @v iobuf I/O buffer
+ */
+static void imux_rx_tcp ( struct imux *imux, struct io_buffer *iobuf ) {
+ struct imux_header_tcp *tcp = iobuf->data;
+ size_t len = iob_len ( iobuf );
+ int rc;
+
+ /* Sanity check */
+ if ( len < sizeof ( *tcp ) ) {
+ DBGC ( imux, "IMUX %p malformed TCP message:\n", imux );
+ DBGC_HDA ( imux, 0, tcp, len );
+ goto error;
+ }
+
+ /* Ignore unexpected packets */
+ if ( tcp->tcp.dest != htons ( imux->port ) ) {
+ DBGC ( imux, "IMUX %p ignoring unexpected TCP port %d:\n",
+ imux, ntohs ( tcp->tcp.dest ) );
+ DBGC_HDA ( imux, 0, tcp, len );
+ goto error;
+ }
+
+ /* Ignore resets */
+ if ( tcp->tcp.flags & TCP_RST ) {
+ DBGC ( imux, "IMUX %p ignoring TCP RST\n", imux );
+ DBGC2_HDA ( imux, 0, tcp, len );
+ goto error;
+ }
+
+ /* Record ACK number */
+ imux->tcp_ack = ( ntohl ( tcp->tcp.seq ) + len - sizeof ( *tcp ) );
+
+ /* Handle received message */
+ if ( tcp->tcp.flags & TCP_SYN ) {
+
+ /* Received SYN+ACK */
+ imux_rx_syn ( imux );
+
+ } else {
+
+ /* Strip header */
+ iob_pull ( iobuf, sizeof ( *tcp ) );
+
+ /* Deliver via socket */
+ if ( ( rc = xfer_deliver_iob ( &imux->tcp,
+ iob_disown ( iobuf ) ) ) != 0 )
+ goto error;
+ }
+
+ error:
+ free_iob ( iobuf );
+}
+
+/**
+ * Complete bulk IN transfer
+ *
+ * @v ep USB endpoint
+ * @v iobuf I/O buffer
+ * @v rc Completion status code
+ */
+static void imux_in_complete ( struct usb_endpoint *ep,
+ struct io_buffer *iobuf, int rc ) {
+ struct imux *imux = container_of ( ep, struct imux, usbnet.in );
+ struct imux_header *hdr = iobuf->data;
+ size_t len = iob_len ( iobuf );
+
+ /* Ignore packets cancelled when the endpoint closes */
+ if ( ! ep->open )
+ goto drop;
+
+ /* Report USB errors */
+ if ( rc != 0 ) {
+ DBGC ( imux, "IMUX %p bulk IN failed: %s\n",
+ imux, strerror ( rc ) );
+ goto drop;
+ }
+
+ /* Sanity check */
+ if ( len < sizeof ( *hdr ) ) {
+ DBGC ( imux, "IMUX %p malformed message:\n", imux );
+ DBGC_HDA ( imux, 0, hdr, len );
+ goto drop;
+ }
+
+ /* Record input sequence */
+ imux->in_seq = ntohs ( hdr->in_seq );
+
+ /* Handle according to protocol */
+ DBGCP ( imux, "IMUX %p received:\n", imux );
+ DBGCP_HDA ( imux, 0, hdr, len );
+ switch ( hdr->protocol ) {
+ case htonl ( IMUX_VERSION ):
+ imux_rx_version ( imux );
+ break;
+ case htonl ( IMUX_LOG ):
+ imux_rx_log ( imux, hdr, len );
+ break;
+ case htonl ( IMUX_TCP ):
+ imux_rx_tcp ( imux, iob_disown ( iobuf ) );
+ break;
+ default:
+ DBGC ( imux, "IMUX %p unknown message type %d:\n",
+ imux, ntohl ( hdr->protocol ) );
+ DBGC_HDA ( imux, 0, hdr, len );
+ break;
+ }
+
+ drop:
+ free_iob ( iobuf );
+}
+
+/** Bulk IN endpoint operations */
+static struct usb_endpoint_driver_operations imux_in_operations = {
+ .complete = imux_in_complete,
+};
+
+/**
+ * Complete bulk OUT transfer
+ *
+ * @v ep USB endpoint
+ * @v iobuf I/O buffer
+ * @v rc Completion status code
+ */
+static void imux_out_complete ( struct usb_endpoint *ep,
+ struct io_buffer *iobuf, int rc ) {
+ struct imux *imux = container_of ( ep, struct imux, usbnet.out );
+
+ /* Report USB errors */
+ if ( rc != 0 ) {
+ DBGC ( imux, "IMUX %p bulk OUT failed: %s\n",
+ imux, strerror ( rc ) );
+ goto error;
+ }
+
+ error:
+ free_iob ( iobuf );
+}
+
+/** Bulk OUT endpoint operations */
+static struct usb_endpoint_driver_operations imux_out_operations = {
+ .complete = imux_out_complete,
+};
+
+/**
+ * Shut down USB multiplexer
+ *
+ * @v imux USB multiplexer
+ */
+static void imux_shutdown ( struct imux *imux ) {
+
+ /* Shut down interfaces */
+ intf_shutdown ( &imux->tcp, -ECANCELED );
+
+ /* Close USB network device, if open */
+ if ( process_running ( &imux->process ) ) {
+ process_del ( &imux->process );
+ usbnet_close ( &imux->usbnet );
+ }
+}
+
+/**
+ * Close USB multiplexer
+ *
+ * @v imux USB multiplexer
+ * @v rc Reason for close
+ */
+static void imux_close ( struct imux *imux, int rc ) {
+ struct iphone *iphone;
+
+ /* Restart interfaces */
+ intf_restart ( &imux->tcp, rc );
+
+ /* Record pairing status */
+ imux->rc = rc;
+
+ /* Trigger link check on any associated iPhones */
+ list_for_each_entry ( iphone, &iphones, list ) {
+ if ( iphone->usb == imux->usb )
+ start_timer_nodelay ( &iphone->timer );
+ }
+
+ /* Retry pairing on any error */
+ if ( rc != 0 ) {
+
+ /* Increment port number */
+ imux->port++;
+
+ /* Request pairing on any retry attempt */
+ imux->flags = IPAIR_REQUEST;
+
+ /* Send new pseudo-TCP SYN */
+ imux->action = imux_tx_syn;
+
+ DBGC ( imux, "IMUX %p retrying pairing: %s\n",
+ imux, strerror ( rc ) );
+ return;
+ }
+
+ /* Shut down multiplexer on pairing success */
+ imux_shutdown ( imux );
+}
+
+/**
+ * Allocate I/O buffer for pseudo-TCP socket
+ *
+ * @v imux USB multiplexer
+ * @v len I/O buffer payload length
+ * @ret iobuf I/O buffer
+ */
+static struct io_buffer * imux_alloc_iob ( struct imux *imux __unused,
+ size_t len ) {
+ struct imux_header_tcp *tcp;
+ struct io_buffer *iobuf;
+
+ /* Allocate I/O buffer */
+ iobuf = alloc_iob ( sizeof ( *tcp ) + len );
+ if ( ! iobuf )
+ return NULL;
+
+ /* Reserve space for pseudo-TCP message header */
+ iob_reserve ( iobuf, sizeof ( *tcp ) );
+
+ return iobuf;
+}
+
+/**
+ * Transmit packet via pseudo-TCP socket
+ *
+ * @v imux USB multiplexer
+ * @v iobuf I/O buffer
+ * @v meta Data transfer metadata
+ * @ret rc Return status code
+ */
+static int imux_deliver ( struct imux *imux, struct io_buffer *iobuf,
+ struct xfer_metadata *meta __unused ) {
+ struct imux_header_tcp *tcp;
+
+ /* Prepend pseudo-TCP header */
+ tcp = iob_push ( iobuf, sizeof ( *tcp ) );
+ memset ( tcp, 0, sizeof ( *tcp ) );
+ tcp->tcp.flags = TCP_ACK;
+
+ /* Transmit pseudo-TCP packet */
+ return imux_tx_tcp ( imux, iob_disown ( iobuf ) );
+}
+
+/** Pseudo-TCP socket interface operations */
+static struct interface_operation imux_tcp_operations[] = {
+ INTF_OP ( xfer_deliver, struct imux *, imux_deliver ),
+ INTF_OP ( xfer_alloc_iob, struct imux *, imux_alloc_iob ),
+ INTF_OP ( intf_close, struct imux *, imux_close ),
+};
+
+/** Pseudo-TCP socket interface descriptor */
+static struct interface_descriptor imux_tcp_desc =
+ INTF_DESC ( struct imux, tcp, imux_tcp_operations );
+
+/**
+ * Multiplexer process
+ *
+ * @v imux USB multiplexer
+ */
+static void imux_step ( struct imux *imux ) {
+ int rc;
+
+ /* Poll USB bus */
+ usb_poll ( imux->bus );
+
+ /* Do nothing more if multiplexer has been closed */
+ if ( ! process_running ( &imux->process ) )
+ return;
+
+ /* Refill endpoints */
+ if ( ( rc = usbnet_refill ( &imux->usbnet ) ) != 0 ) {
+ /* Wait for next poll */
+ return;
+ }
+
+ /* Perform pending action, if any */
+ if ( imux->action ) {
+ if ( ( rc = imux->action ( imux ) ) != 0 )
+ imux_close ( imux, rc );
+ imux->action = NULL;
+ }
+}
+
+/** Multiplexer process descriptor */
+static struct process_descriptor imux_process_desc =
+ PROC_DESC ( struct imux, process, imux_step );
+
+/**
+ * Probe device
+ *
+ * @v func USB function
+ * @v config Configuration descriptor
+ * @ret rc Return status code
+ */
+static int imux_probe ( struct usb_function *func,
+ struct usb_configuration_descriptor *config ) {
+ struct usb_device *usb = func->usb;
+ struct imux *imux;
+ int rc;
+
+ /* Allocate and initialise structure */
+ imux = zalloc ( sizeof ( *imux ) );
+ if ( ! imux ) {
+ rc = -ENOMEM;
+ goto err_alloc;
+ }
+ ref_init ( &imux->refcnt, NULL );
+ imux->usb = usb;
+ imux->bus = usb->port->hub->bus;
+ usbnet_init ( &imux->usbnet, func, NULL, &imux_in_operations,
+ &imux_out_operations );
+ usb_refill_init ( &imux->usbnet.in, 0, IMUX_IN_MTU, IMUX_IN_MAX_FILL );
+ process_init ( &imux->process, &imux_process_desc, &imux->refcnt );
+ imux->action = imux_tx_version;
+ imux->port = IMUX_PORT_LOCAL;
+ intf_init ( &imux->tcp, &imux_tcp_desc, &imux->refcnt );
+ imux->rc = -EINPROGRESS_PAIRING;
+
+ /* Describe USB network device */
+ if ( ( rc = usbnet_describe ( &imux->usbnet, config ) ) != 0 ) {
+ DBGC ( imux, "IMUX %p could not describe: %s\n",
+ imux, strerror ( rc ) );
+ goto err_describe;
+ }
+
+ /* Open USB network device */
+ if ( ( rc = usbnet_open ( &imux->usbnet ) ) != 0 ) {
+ DBGC ( imux, "IMUX %p could not open: %s\n",
+ imux, strerror ( rc ) );
+ goto err_open;
+ }
+
+ /* Start polling process */
+ process_add ( &imux->process );
+
+ /* Add to list of multiplexers */
+ list_add ( &imux->list, &imuxes );
+
+ usb_func_set_drvdata ( func, imux );
+ return 0;
+
+ list_del ( &imux->list );
+ imux_shutdown ( imux );
+ err_open:
+ err_describe:
+ ref_put ( &imux->refcnt );
+ err_alloc:
+ return rc;
+}
+
+/**
+ * Remove device
+ *
+ * @v func USB function
+ */
+static void imux_remove ( struct usb_function *func ) {
+ struct imux *imux = usb_func_get_drvdata ( func );
+
+ list_del ( &imux->list );
+ imux_shutdown ( imux );
+ ref_put ( &imux->refcnt );
+}
+
+/** USB multiplexer device IDs */
+static struct usb_device_id imux_ids[] = {
+ {
+ .name = "imux",
+ .vendor = 0x05ac,
+ .product = USB_ANY_ID,
+ },
+};
+
+/** USB multiplexer driver */
+struct usb_driver imux_driver __usb_driver = {
+ .ids = imux_ids,
+ .id_count = ( sizeof ( imux_ids ) / sizeof ( imux_ids[0] ) ),
+ .class = USB_CLASS_ID ( 0xff, 0xfe, 0x02 ),
+ .score = USB_SCORE_NORMAL,
+ .probe = imux_probe,
+ .remove = imux_remove,
+};
+
+/******************************************************************************
+ *
+ * iPhone pairing client
+ *
+ ******************************************************************************
+ */
+
+/** Common prefix for all pairing messages */
+static const char ipair_prefix[] =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" "
+ "\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
+ "<plist version=\"1.0\">\n"
+ "<dict>\n"
+ "<key>Label</key>\n"
+ "<string>iPXE</string>\n"
+ "<key>Request</key>\n";
+
+/** Common suffix for all pairing messages */
+static const char ipair_suffix[] =
+ "</dict>\n"
+ "</plist>\n";
+
+/** Arbitrary system BUID used for pairing */
+static const char ipair_system_buid[] = "E4DB92D2-248A-469A-AC34-92045D07E695";
+
+/** Arbitrary host ID used for pairing */
+static const char ipair_host_id[] = "93CEBC27-8457-4804-9108-F42549DF6143";
+
+static int ipair_tx_pubkey ( struct ipair *ipair );
+static int ipair_rx_pubkey ( struct ipair *ipair, char *msg );
+static int ipair_tx_pair ( struct ipair *ipair );
+static int ipair_rx_pair ( struct ipair *ipair, char *msg );
+static int ipair_tx_session ( struct ipair *ipair );
+static int ipair_rx_session ( struct ipair *ipair, char *msg );
+
+/**
+ * Free pairing client
+ *
+ * @v refcnt Reference counter
+ */
+static void ipair_free ( struct refcnt *refcnt ) {
+ struct ipair *ipair = container_of ( refcnt, struct ipair, refcnt );
+
+ icert_free ( &ipair->icert );
+ free ( ipair );
+}
+
+/**
+ * Shut down pairing client
+ *
+ * @v ipair Pairing client
+ * @v rc Reason for close
+ */
+static void ipair_close ( struct ipair *ipair, int rc ) {
+
+ /* Shut down interfaces */
+ intf_shutdown ( &ipair->xfer, rc );
+
+ /* Stop timer */
+ stop_timer ( &ipair->timer );
+}
+
+/**
+ * Transmit XML message
+ *
+ * @v ipair Pairing client
+ * @v fmt Format string
+ * @v ... Arguments
+ * @ret rc Return status code
+ */
+static int __attribute__ (( format ( printf, 2, 3 ) ))
+ipair_tx ( struct ipair *ipair, const char *fmt, ... ) {
+ struct io_buffer *iobuf;
+ struct ipair_header *hdr;
+ va_list args;
+ size_t len;
+ char *msg;
+ int rc;
+
+ /* Calculate length of formatted string */
+ va_start ( args, fmt );
+ len = ( vsnprintf ( NULL, 0, fmt, args ) + 1 /* NUL */ );
+ va_end ( args );
+
+ /* Allocate I/O buffer */
+ iobuf = xfer_alloc_iob ( &ipair->xfer, ( sizeof ( *hdr ) + len ) );
+ if ( ! iobuf )
+ return -ENOMEM;
+ hdr = iob_put ( iobuf, sizeof ( *hdr ) );
+
+ /* Construct XML message */
+ memset ( hdr, 0, sizeof ( *hdr ) );
+ hdr->len = htonl ( len );
+ msg = iob_put ( iobuf, len );
+ vsnprintf ( msg, len, fmt, args );
+ DBGC2 ( ipair, "IPAIR %p transmitting:\n%s\n", ipair, msg );
+
+ /* Transmit message */
+ if ( ( rc = xfer_deliver_iob ( &ipair->xfer,
+ iob_disown ( iobuf ) ) ) != 0 )
+ return rc;
+
+ return 0;
+}
+
+/**
+ * Receive XML message payload
+ *
+ * @v ipair Pairing client
+ * @v msg Message payload
+ * @v len Length of message
+ * @ret rc Return status code
+ */
+static int ipair_rx ( struct ipair *ipair, char *msg, size_t len ) {
+ int ( * rx ) ( struct ipair *ipair, char *msg );
+ int rc;
+
+ /* Ignore empty messages */
+ if ( ! len )
+ return 0;
+
+ /* Sanity check */
+ if ( ( msg[ len - 1 ] != '\0' ) && ( msg[ len - 1 ] != '\n' ) ) {
+ DBGC ( ipair, "IPAIR %p malformed XML:\n", ipair );
+ DBGC_HDA ( ipair, 0, msg, len );
+ return -EPROTO;
+ }
+
+ /* Add NUL terminator (potentially overwriting final newline) */
+ msg[ len - 1 ] = '\0';
+ DBGC2 ( ipair, "IPAIR %p received:\n%s\n\n", ipair, msg );
+
+ /* Handle according to current state */
+ rx = ipair->rx;
+ if ( ! rx ) {
+ DBGC ( ipair, "IPAIR %p unexpected XML:\n%s\n", ipair, msg );
+ return -EPROTO;
+ }
+ ipair->rx = NULL;
+ if ( ( rc = rx ( ipair, msg ) ) != 0 )
+ return rc;
+
+ return 0;
+}
+
+/**
+ * Locate XML tag
+ *
+ * @v ipair Pairing client
+ * @v msg XML message
+ * @v tag Tag name
+ * @ret start Start of tag content
+ * @ret end End of tag content
+ * @ret rc Return status code
+ */
+static int ipair_tag ( struct ipair *ipair, const char *msg, const char *tag,
+ char **start, char **end ) {
+ char buf[ 2 /* "</" */ + strlen ( tag ) + 1 /* ">" */ + 1 /* NUL */ ];
+
+ /* Locate opening tag */
+ sprintf ( buf, "<%s>", tag );
+ *start = strstr ( msg, buf );
+ if ( ! *start )
+ return -ENOENT;
+ *start += strlen ( buf );
+
+ /* Locate closing tag */
+ sprintf ( buf, "</%s>", tag );
+ *end = strstr ( *start, buf );
+ if ( ! *end ) {
+ DBGC ( ipair, "IPAIR %p missing closing tag %s in:\n%s\n",
+ ipair, buf, msg );
+ return -ENOENT;
+ }
+
+ return 0;
+}
+
+/**
+ * Locate XML property list dictionary value
+ *
+ * @v ipair Pairing client
+ * @v msg XML message
+ * @v key Key name
+ * @v type Key type
+ * @ret start Start of value content
+ * @ret end End of value content
+ * @ret rc Return status code
+ */
+static int ipair_key ( struct ipair *ipair, const char *msg, const char *key,
+ const char *type, char **start, char **end ) {
+ int rc;
+
+ /* Iterate over keys */
+ while ( 1 ) {
+
+ /* Locate key */
+ if ( ( rc = ipair_tag ( ipair, msg, "key", start,
+ end ) ) != 0 )
+ return rc;
+ msg = *end;
+
+ /* Check key name */
+ if ( memcmp ( *start, key, ( *end - *start ) ) != 0 )
+ continue;
+
+ /* Locate value */
+ return ipair_tag ( ipair, msg, type, start, end );
+ }
+}
+
+/**
+ * Transmit DevicePublicKey message
+ *
+ * @v ipair Pairing client
+ * @ret rc Return status code
+ */
+static int ipair_tx_pubkey ( struct ipair *ipair ) {
+ int rc;
+
+ /* Transmit message */
+ if ( ( rc = ipair_tx ( ipair,
+ "%s"
+ "<string>GetValue</string>\n"
+ "<key>Key</key>\n"
+ "<string>DevicePublicKey</string>\n"
+ "%s",
+ ipair_prefix, ipair_suffix ) ) != 0 )
+ return rc;
+
+ return 0;
+}
+
+/**
+ * Receive DevicePublicKey message
+ *
+ * @v ipair Pairing client
+ * @v msg XML message
+ * @ret rc Return status code
+ */
+static int ipair_rx_pubkey ( struct ipair *ipair, char *msg ) {
+ struct asn1_cursor *key;
+ char *data;
+ char *end;
+ char *decoded;
+ size_t max_len;
+ int len;
+ int next;
+ int rc;
+
+ /* Locate "Value" value */
+ if ( ( rc = ipair_key ( ipair, msg, "Value", "data", &data,
+ &end ) ) != 0 ) {
+ DBGC ( ipair, "IPAIR %p unexpected public key message:\n%s\n",
+ ipair, msg );
+ goto err_tag;
+ }
+ *end = '\0';
+
+ /* Decode outer layer of Base64 */
+ max_len = base64_decoded_max_len ( data );
+ decoded = malloc ( max_len );
+ if ( ! decoded ) {
+ rc = -ENOMEM;
+ goto err_alloc;
+ }
+ len = base64_decode ( data, decoded, max_len );
+ if ( len < 0 ) {
+ rc = len;
+ DBGC ( ipair, "IPAIR %p invalid outer public key:\n%s\n",
+ ipair, data );
+ goto err_decode;
+ }
+
+ /* Decode inner layer of Base64 */
+ next = pem_asn1 ( virt_to_user ( decoded ), len, 0, &key );
+ if ( next < 0 ) {
+ rc = next;
+ DBGC ( ipair, "IPAIR %p invalid inner public key:\n%s\n",
+ ipair, decoded );
+ goto err_asn1;
+ }
+ DBGC ( ipair, "IPAIR %p received public key\n", ipair );
+ DBGC2_HDA ( ipair, 0, key->data, key->len );
+
+ /* Construct certificates */
+ if ( ( rc = icert_certs ( &ipair->icert, key ) ) != 0 )
+ goto err_certs;
+
+ /* Send session request or pair request as applicable */
+ if ( ipair->flags & IPAIR_REQUEST ) {
+ ipair->tx = ipair_tx_pair;
+ ipair->rx = ipair_rx_pair;
+ } else {
+ ipair->tx = ipair_tx_session;
+ ipair->rx = ipair_rx_session;
+ }
+ start_timer_nodelay ( &ipair->timer );
+
+ /* Free key */
+ free ( key );
+
+ /* Free intermediate Base64 */
+ free ( decoded );
+
+ return 0;
+
+ err_certs:
+ free ( key );
+ err_asn1:
+ err_decode:
+ free ( decoded );
+ err_alloc:
+ err_tag:
+ return rc;
+}
+
+/**
+ * Transmit Pair message
+ *
+ * @v ipair Pairing client
+ * @ret rc Return status code
+ */
+static int ipair_tx_pair ( struct ipair *ipair ) {
+ char *root;
+ char *host;
+ char *device;
+ int rc;
+
+ /* Construct doubly encoded certificates */
+ if ( ( rc = icert_encode ( &ipair->icert, ipair->icert.root,
+ &root ) ) != 0 )
+ goto err_root;
+ if ( ( rc = icert_encode ( &ipair->icert, ipair->icert.host,
+ &host ) ) != 0 )
+ goto err_host;
+ if ( ( rc = icert_encode ( &ipair->icert, ipair->icert.device,
+ &device ) ) != 0 )
+ goto err_device;
+
+ /* Transmit message */
+ if ( ( rc = ipair_tx ( ipair,
+ "%s"
+ "<string>Pair</string>\n"
+ "<key>PairRecord</key>\n"
+ "<dict>\n"
+ "<key>RootCertificate</key>\n"
+ "<data>%s</data>\n"
+ "<key>HostCertificate</key>\n"
+ "<data>%s</data>\n"
+ "<key>DeviceCertificate</key>\n"
+ "<data>%s</data>\n"
+ "<key>SystemBUID</key>\n"
+ "<string>%s</string>\n"
+ "<key>HostID</key>\n"
+ "<string>%s</string>\n"
+ "</dict>\n"
+ "<key>ProtocolVersion</key>\n"
+ "<string>2</string>\n"
+ "<key>PairingOptions</key>\n"
+ "<dict>\n"
+ "<key>ExtendedPairingErrors</key>\n"
+ "<true/>\n"
+ "</dict>\n"
+ "%s",
+ ipair_prefix, root, host, device,
+ ipair_system_buid, ipair_host_id,
+ ipair_suffix
+ ) ) != 0 )
+ goto err_tx;
+
+ err_tx:
+ free ( device );
+ err_device:
+ free ( host );
+ err_host:
+ free ( root );
+ err_root:
+ return rc;
+}
+
+/**
+ * Receive Pair message error
+ *
+ * @v ipair Pairing client
+ * @v error Pairing error
+ * @ret rc Return status code
+ */
+static int ipair_rx_pair_error ( struct ipair *ipair, char *error ) {
+
+ /* Check for actual errors */
+ if ( strcmp ( error, "PairingDialogResponsePending" ) != 0 ) {
+ DBGC ( ipair, "IPAIR %p pairing error \"%s\"\n", ipair, error );
+ return -EPERM;
+ }
+
+ /* Retransmit pairing request */
+ ipair->tx = ipair_tx_pair;
+ ipair->rx = ipair_rx_pair;
+ start_timer_fixed ( &ipair->timer, IPAIR_RETRY_DELAY );
+
+ DBGC ( ipair, "IPAIR %p waiting for pairing dialog\n", ipair );
+ return 0;
+}
+
+/**
+ * Receive Pair message
+ *
+ * @v ipair Pairing client
+ * @v msg XML message
+ * @ret rc Return status code
+ */
+static int ipair_rx_pair ( struct ipair *ipair, char *msg ) {
+ char *error;
+ char *escrow;
+ char *end;
+ int rc;
+
+ /* Check for pairing errors */
+ if ( ( rc = ipair_key ( ipair, msg, "Error", "string", &error,
+ &end ) ) == 0 ) {
+ *end = '\0';
+ return ipair_rx_pair_error ( ipair, error );
+ }
+
+ /* Get EscrowBag */
+ if ( ( rc = ipair_key ( ipair, msg, "EscrowBag", "data", &escrow,
+ &end ) ) != 0 ) {
+ DBGC ( ipair, "IPAIR %p unexpected pairing response:\n%s\n",
+ ipair, msg );
+ return rc;
+ }
+ DBGC ( ipair, "IPAIR %p pairing successful\n", ipair );
+
+ /* Send session request */
+ ipair->tx = ipair_tx_session;
+ ipair->rx = ipair_rx_session;
+ start_timer_nodelay ( &ipair->timer );
+
+ return 0;
+}
+
+/**
+ * Transmit StartSession message
+ *
+ * @v ipair Pairing client
+ * @ret rc Return status code
+ */
+static int ipair_tx_session ( struct ipair *ipair ) {
+ int rc;
+
+ /* Transmit message */
+ if ( ( rc = ipair_tx ( ipair,
+ "%s"
+ "<string>StartSession</string>\n"
+ "<key>SystemBUID</key>\n"
+ "<string>%s</string>\n"
+ "<key>HostID</key>\n"
+ "<string>%s</string>\n"
+ "%s",
+ ipair_prefix, ipair_system_buid,
+ ipair_host_id, ipair_suffix
+ ) ) != 0 )
+ return rc;
+
+ return 0;
+}
+
+/**
+ * Receive StartSession message error
+ *
+ * @v ipair Pairing client
+ * @v error Pairing error
+ * @ret rc Return status code
+ */
+static int ipair_rx_session_error ( struct ipair *ipair, char *error ) {
+
+ /* Check for actual errors */
+ if ( strcmp ( error, "InvalidHostID" ) != 0 ) {
+ DBGC ( ipair, "IPAIR %p session error \"%s\"\n", ipair, error );
+ return -EPERM;
+ }
+
+ /* Transmit pairing request */
+ ipair->tx = ipair_tx_pair;
+ ipair->rx = ipair_rx_pair;
+ start_timer_nodelay ( &ipair->timer );
+
+ DBGC ( ipair, "IPAIR %p unknown host: requesting pairing\n", ipair );
+ return 0;
+}
+
+/**
+ * Receive StartSession message
+ *
+ * @v ipair Pairing client
+ * @v msg XML message
+ * @ret rc Return status code
+ */
+static int ipair_rx_session ( struct ipair *ipair, char *msg ) {
+ char *error;
+ char *session;
+ char *end;
+ int rc;
+
+ /* Check for session errors */
+ if ( ( rc = ipair_key ( ipair, msg, "Error", "string", &error,
+ &end ) ) == 0 ) {
+ *end = '\0';
+ return ipair_rx_session_error ( ipair, error );
+ }
+
+ /* Check for session ID */
+ if ( ( rc = ipair_key ( ipair, msg, "SessionID", "string", &session,
+ &end ) ) != 0 ) {
+ DBGC ( ipair, "IPAIR %p unexpected session response:\n%s\n",
+ ipair, msg );
+ return rc;
+ }
+ *end = '\0';
+ DBGC ( ipair, "IPAIR %p starting session \"%s\"\n", ipair, session );
+
+ /* Start TLS */
+ if ( ( rc = add_tls ( &ipair->xfer, "iPhone", &icert_root,
+ ipair->icert.key ) ) != 0 ) {
+ DBGC ( ipair, "IPAIR %p could not start TLS: %s\n",
+ ipair, strerror ( rc ) );
+ return rc;
+ }
+
+ /* Record that TLS has been started */
+ ipair->flags |= IPAIR_TLS;
+
+ return 0;
+}
+
+/**
+ * Handle window change notification
+ *
+ * @v ipair Pairing client
+ */
+static void ipair_window_changed ( struct ipair *ipair ) {
+
+ /* Report pairing as complete once TLS session has been established */
+ if ( ( ipair->flags & IPAIR_TLS ) && xfer_window ( &ipair->xfer ) ) {
+
+ /* Sanity checks */
+ assert ( x509_is_valid ( ipair->icert.root, &icert_root ) );
+ assert ( x509_is_valid ( ipair->icert.device, &icert_root ) );
+ assert ( ! x509_is_valid ( ipair->icert.root, NULL ) );
+ assert ( ! x509_is_valid ( ipair->icert.host, NULL ) );
+ assert ( ! x509_is_valid ( ipair->icert.device, NULL ) );
+
+ /* Report pairing as complete */
+ DBGC ( ipair, "IPAIR %p established TLS session\n", ipair );
+ ipair_close ( ipair, 0 );
+ return;
+ }
+}
+
+/**
+ * Handle received data
+ *
+ * @v ipair Pairing client
+ * @v iobuf I/O buffer
+ * @v meta Data transfer metadata
+ * @ret rc Return status code
+ */
+static int ipair_deliver ( struct ipair *ipair, struct io_buffer *iobuf,
+ struct xfer_metadata *meta __unused ) {
+ struct ipair_header *hdr;
+ int rc;
+
+ /* Strip header (which may appear in a separate packet) */
+ if ( ( ! ( ipair->flags & IPAIR_RX_LEN ) ) &&
+ ( iob_len ( iobuf ) >= sizeof ( *hdr ) ) ) {
+ iob_pull ( iobuf, sizeof ( *hdr ) );
+ ipair->flags |= IPAIR_RX_LEN;
+ }
+
+ /* Clear received header flag if we have a message */
+ if ( iob_len ( iobuf ) )
+ ipair->flags &= ~IPAIR_RX_LEN;
+
+ /* Receive message */
+ if ( ( rc = ipair_rx ( ipair, iobuf->data, iob_len ( iobuf ) ) ) != 0 )
+ goto error;
+
+ /* Free I/O buffer */
+ free_iob ( iobuf );
+
+ return 0;
+
+ error:
+ ipair_close ( ipair, rc );
+ free_iob ( iobuf );
+ return rc;
+}
+
+/**
+ * Pairing transmission timer
+ *
+ * @v timer Retransmission timer
+ * @v over Failure indicator
+ */
+static void ipair_expired ( struct retry_timer *timer, int over __unused ) {
+ struct ipair *ipair = container_of ( timer, struct ipair, timer );
+ int ( * tx ) ( struct ipair *ipair );
+ int rc;
+
+ /* Sanity check */
+ tx = ipair->tx;
+ assert ( tx != NULL );
+
+ /* Clear pending transmission */
+ ipair->tx = NULL;
+
+ /* Transmit data, if applicable */
+ if ( ( rc = tx ( ipair ) ) != 0 )
+ ipair_close ( ipair, rc );
+}
+
+/** Pairing client interface operations */
+static struct interface_operation ipair_xfer_operations[] = {
+ INTF_OP ( xfer_deliver, struct ipair *, ipair_deliver ),
+ INTF_OP ( xfer_window_changed, struct ipair *, ipair_window_changed ),
+ INTF_OP ( intf_close, struct ipair *, ipair_close ),
+};
+
+/** Pairing client interface descriptor */
+static struct interface_descriptor ipair_xfer_desc =
+ INTF_DESC ( struct ipair, xfer, ipair_xfer_operations );
+
+/**
+ * Create a pairing client
+ *
+ * @v xfer Data transfer interface
+ * @v flags Initial state flags
+ * @ret rc Return status code
+ */
+static int ipair_create ( struct interface *xfer, unsigned int flags ) {
+ struct ipair *ipair;
+ int rc;
+
+ /* Allocate and initialise structure */
+ ipair = zalloc ( sizeof ( *ipair ) );
+ if ( ! ipair ) {
+ rc = -ENOMEM;
+ goto err_alloc;
+ }
+ ref_init ( &ipair->refcnt, ipair_free );
+ intf_init ( &ipair->xfer, &ipair_xfer_desc, &ipair->refcnt );
+ timer_init ( &ipair->timer, ipair_expired, &ipair->refcnt );
+ ipair->tx = ipair_tx_pubkey;
+ ipair->rx = ipair_rx_pubkey;
+ ipair->flags = flags;
+
+ /* Schedule initial transmission */
+ start_timer_nodelay ( &ipair->timer );
+
+ /* Attach to parent interface, mortalise self, and return */
+ intf_plug_plug ( &ipair->xfer, xfer );
+ ref_put ( &ipair->refcnt );
+ return 0;
+
+ ref_put ( &ipair->refcnt );
+ err_alloc:
+ return rc;
+}
+
+/******************************************************************************
+ *
+ * iPhone USB networking
+ *
+ ******************************************************************************
+ */
+
+/**
+ * Complete bulk IN transfer
+ *
+ * @v ep USB endpoint
+ * @v iobuf I/O buffer
+ * @v rc Completion status code
+ */
+static void iphone_in_complete ( struct usb_endpoint *ep,
+ struct io_buffer *iobuf, int rc ) {
+ struct iphone *iphone = container_of ( ep, struct iphone, usbnet.in );
+ struct net_device *netdev = iphone->netdev;
+
+ /* Profile receive completions */
+ profile_start ( &iphone_in_profiler );
+
+ /* Ignore packets cancelled when the endpoint closes */
+ if ( ! ep->open )
+ goto ignore;
+
+ /* Record USB errors against the network device */
+ if ( rc != 0 ) {
+ DBGC ( iphone, "IPHONE %p bulk IN failed: %s\n",
+ iphone, strerror ( rc ) );
+ goto error;
+ }
+
+ /* Strip padding */
+ if ( iob_len ( iobuf ) < IPHONE_IN_PAD ) {
+ DBGC ( iphone, "IPHONE %p malformed bulk IN:\n", iphone );
+ DBGC_HDA ( iphone, 0, iobuf->data, iob_len ( iobuf ) );
+ rc = -EINVAL;
+ goto error;
+ }
+ iob_pull ( iobuf, IPHONE_IN_PAD );
+
+ /* Hand off to network stack */
+ netdev_rx ( netdev, iob_disown ( iobuf ) );
+
+ profile_stop ( &iphone_in_profiler );
+ return;
+
+ error:
+ netdev_rx_err ( netdev, iob_disown ( iobuf ), rc );
+ ignore:
+ free_iob ( iobuf );
+}
+
+/** Bulk IN endpoint operations */
+static struct usb_endpoint_driver_operations iphone_in_operations = {
+ .complete = iphone_in_complete,
+};
+
+/**
+ * Transmit packet
+ *
+ * @v iphone iPhone device
+ * @v iobuf I/O buffer
+ * @ret rc Return status code
+ */
+static int iphone_out_transmit ( struct iphone *iphone,
+ struct io_buffer *iobuf ) {
+ int rc;
+
+ /* Profile transmissions */
+ profile_start ( &iphone_out_profiler );
+
+ /* Enqueue I/O buffer */
+ if ( ( rc = usb_stream ( &iphone->usbnet.out, iobuf, 1 ) ) != 0 )
+ return rc;
+
+ profile_stop ( &iphone_out_profiler );
+ return 0;
+}
+
+/**
+ * Complete bulk OUT transfer
+ *
+ * @v ep USB endpoint
+ * @v iobuf I/O buffer
+ * @v rc Completion status code
+ */
+static void iphone_out_complete ( struct usb_endpoint *ep,
+ struct io_buffer *iobuf, int rc ) {
+ struct iphone *iphone = container_of ( ep, struct iphone, usbnet.out );
+ struct net_device *netdev = iphone->netdev;
+
+ /* Report TX completion */
+ netdev_tx_complete_err ( netdev, iobuf, rc );
+}
+
+/** Bulk OUT endpoint operations */
+static struct usb_endpoint_driver_operations iphone_out_operations = {
+ .complete = iphone_out_complete,
+};
+
+/**
+ * Check pairing status
+ *
+ * @v iphone iPhone device
+ * @ret rc Return status code
+ */
+static int iphone_check_pair ( struct iphone *iphone ) {
+ struct imux *imux;
+
+ /* Find corresponding USB multiplexer */
+ list_for_each_entry ( imux, &imuxes, list ) {
+ if ( imux->usb == iphone->usb )
+ return imux->rc;
+ }
+
+ return -EPIPE_NO_MUX;
+}
+
+/**
+ * Check link status
+ *
+ * @v netdev Network device
+ */
+static void iphone_check_link ( struct net_device *netdev ) {
+ struct iphone *iphone = netdev->priv;
+ struct usb_device *usb = iphone->usb;
+ uint8_t status;
+ int rc;
+
+ /* Check pairing status */
+ if ( ( rc = iphone_check_pair ( iphone ) ) != 0 )
+ goto err_pair;
+
+ /* Get link status */
+ if ( ( rc = usb_control ( usb, IPHONE_GET_LINK, 0, 0, &status,
+ sizeof ( status ) ) ) != 0 ) {
+ DBGC ( iphone, "IPHONE %p could not get link status: %s\n",
+ iphone, strerror ( rc ) );
+ goto err_control;
+ }
+
+ /* Check link status */
+ if ( status != IPHONE_LINK_UP ) {
+ rc = -ENOTCONN_STATUS ( status );
+ goto err_status;
+ }
+
+ /* Success */
+ rc = 0;
+
+ err_status:
+ err_control:
+ err_pair:
+ /* Report link status. Since we have to check the link
+ * periodically (due to an absence of an interrupt endpoint),
+ * do this only if the link status has actually changed.
+ */
+ if ( rc != netdev->link_rc ) {
+ if ( rc == 0 ) {
+ DBGC ( iphone, "IPHONE %p link up\n", iphone );
+ } else {
+ DBGC ( iphone, "IPHONE %p link down: %s\n",
+ iphone, strerror ( rc ) );
+ }
+ netdev_link_err ( netdev, rc );
+ }
+}
+
+/**
+ * Periodically update link status
+ *
+ * @v timer Link status timer
+ * @v over Failure indicator
+ */
+static void iphone_expired ( struct retry_timer *timer, int over __unused ) {
+ struct iphone *iphone = container_of ( timer, struct iphone, timer );
+ struct net_device *netdev = iphone->netdev;
+
+ /* Check link status */
+ iphone_check_link ( netdev );
+
+ /* Restart timer, if device is open */
+ if ( netdev_is_open ( netdev ) )
+ start_timer_fixed ( timer, IPHONE_LINK_CHECK_INTERVAL );
+}
+
+/**
+ * Open network device
+ *
+ * @v netdev Network device
+ * @ret rc Return status code
+ */
+static int iphone_open ( struct net_device *netdev ) {
+ struct iphone *iphone = netdev->priv;
+ int rc;
+
+ /* Open USB network device */
+ if ( ( rc = usbnet_open ( &iphone->usbnet ) ) != 0 ) {
+ DBGC ( iphone, "IPHONE %p could not open: %s\n",
+ iphone, strerror ( rc ) );
+ goto err_open;
+ }
+
+ /* Start the link status check timer */
+ start_timer_nodelay ( &iphone->timer );
+
+ return 0;
+
+ usbnet_close ( &iphone->usbnet );
+ err_open:
+ return rc;
+}
+
+/**
+ * Close network device
+ *
+ * @v netdev Network device
+ */
+static void iphone_close ( struct net_device *netdev ) {
+ struct iphone *iphone = netdev->priv;
+
+ /* Stop the link status check timer */
+ stop_timer ( &iphone->timer );
+
+ /* Close USB network device */
+ usbnet_close ( &iphone->usbnet );
+}
+
+/**
+ * Transmit packet
+ *
+ * @v netdev Network device
+ * @v iobuf I/O buffer
+ * @ret rc Return status code
+ */
+static int iphone_transmit ( struct net_device *netdev,
+ struct io_buffer *iobuf ) {
+ struct iphone *iphone = netdev->priv;
+ int rc;
+
+ /* Transmit packet */
+ if ( ( rc = iphone_out_transmit ( iphone, iobuf ) ) != 0 )
+ return rc;
+
+ return 0;
+}
+
+/**
+ * Poll for completed and received packets
+ *
+ * @v netdev Network device
+ */
+static void iphone_poll ( struct net_device *netdev ) {
+ struct iphone *iphone = netdev->priv;
+ int rc;
+
+ /* Poll USB bus */
+ usb_poll ( iphone->bus );
+
+ /* Refill endpoints */
+ if ( ( rc = usbnet_refill ( &iphone->usbnet ) ) != 0 )
+ netdev_rx_err ( netdev, NULL, rc );
+}
+
+/** iPhone network device operations */
+static struct net_device_operations iphone_operations = {
+ .open = iphone_open,
+ .close = iphone_close,
+ .transmit = iphone_transmit,
+ .poll = iphone_poll,
+};
+
+/**
+ * Probe device
+ *
+ * @v func USB function
+ * @v config Configuration descriptor
+ * @ret rc Return status code
+ */
+static int iphone_probe ( struct usb_function *func,
+ struct usb_configuration_descriptor *config ) {
+ struct usb_device *usb = func->usb;
+ struct net_device *netdev;
+ struct iphone *iphone;
+ int rc;
+
+ /* Allocate and initialise structure */
+ netdev = alloc_etherdev ( sizeof ( *iphone ) );
+ if ( ! netdev ) {
+ rc = -ENOMEM;
+ goto err_alloc;
+ }
+ netdev_init ( netdev, &iphone_operations );
+ netdev->dev = &func->dev;
+ iphone = netdev->priv;
+ memset ( iphone, 0, sizeof ( *iphone ) );
+ iphone->usb = usb;
+ iphone->bus = usb->port->hub->bus;
+ iphone->netdev = netdev;
+ usbnet_init ( &iphone->usbnet, func, NULL, &iphone_in_operations,
+ &iphone_out_operations );
+ usb_refill_init ( &iphone->usbnet.in, 0, IPHONE_IN_MTU,
+ IPHONE_IN_MAX_FILL );
+ timer_init ( &iphone->timer, iphone_expired, &netdev->refcnt );
+ DBGC ( iphone, "IPHONE %p on %s\n", iphone, func->name );
+
+ /* Describe USB network device */
+ if ( ( rc = usbnet_describe ( &iphone->usbnet, config ) ) != 0 ) {
+ DBGC ( iphone, "IPHONE %p could not describe: %s\n",
+ iphone, strerror ( rc ) );
+ goto err_describe;
+ }
+
+ /* Fetch MAC address */
+ if ( ( rc = usb_control ( usb, IPHONE_GET_MAC, 0, 0, netdev->hw_addr,
+ ETH_ALEN ) ) != 0 ) {
+ DBGC ( iphone, "IPHONE %p could not fetch MAC address: %s\n",
+ iphone, strerror ( rc ) );
+ goto err_fetch_mac;
+ }
+
+ /* Register network device */
+ if ( ( rc = register_netdev ( netdev ) ) != 0 )
+ goto err_register;
+
+ /* Set initial link status */
+ iphone_check_link ( netdev );
+
+ /* Add to list of iPhone network devices */
+ list_add ( &iphone->list, &iphones );
+
+ usb_func_set_drvdata ( func, iphone );
+ return 0;
+
+ list_del ( &iphone->list );
+ unregister_netdev ( netdev );
+ err_register:
+ err_fetch_mac:
+ err_describe:
+ netdev_nullify ( netdev );
+ netdev_put ( netdev );
+ err_alloc:
+ return rc;
+}
+
+/**
+ * Remove device
+ *
+ * @v func USB function
+ */
+static void iphone_remove ( struct usb_function *func ) {
+ struct iphone *iphone = usb_func_get_drvdata ( func );
+ struct net_device *netdev = iphone->netdev;
+
+ list_del ( &iphone->list );
+ unregister_netdev ( netdev );
+ netdev_nullify ( netdev );
+ netdev_put ( netdev );
+}
+
+/** iPhone device IDs */
+static struct usb_device_id iphone_ids[] = {
+ {
+ .name = "iphone",
+ .vendor = 0x05ac,
+ .product = USB_ANY_ID,
+ },
+};
+
+/** iPhone driver */
+struct usb_driver iphone_driver __usb_driver = {
+ .ids = iphone_ids,
+ .id_count = ( sizeof ( iphone_ids ) / sizeof ( iphone_ids[0] ) ),
+ .class = USB_CLASS_ID ( 0xff, 0xfd, 0x01 ),
+ .score = USB_SCORE_NORMAL,
+ .probe = iphone_probe,
+ .remove = iphone_remove,
+};
+
+/* Drag in objects via iphone_driver */
+REQUIRING_SYMBOL ( iphone_driver );
+
+/* Drag in RSA-with-SHA256 OID prefixes */
+REQUIRE_OBJECT ( rsa_sha256 );
diff --git a/src/drivers/net/iphone.h b/src/drivers/net/iphone.h
new file mode 100644
index 000000000..2db6da7bd
--- /dev/null
+++ b/src/drivers/net/iphone.h
@@ -0,0 +1,291 @@
+#ifndef _IPHONE_H
+#define _IPHONE_H
+
+/** @file
+ *
+ * iPhone USB Ethernet driver
+ *
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+
+#include <stdint.h>
+#include <ipxe/usb.h>
+#include <ipxe/usbnet.h>
+#include <ipxe/process.h>
+#include <ipxe/timer.h>
+#include <ipxe/retry.h>
+#include <ipxe/tcp.h>
+#include <ipxe/x509.h>
+#include <ipxe/privkey.h>
+
+/******************************************************************************
+ *
+ * iPhone pairing certificates
+ *
+ ******************************************************************************
+ */
+
+/** An iPhone pairing certificate set */
+struct icert {
+ /** "Private" key */
+ struct private_key *key;
+ /** Root certificate */
+ struct x509_certificate *root;
+ /** Host certificate */
+ struct x509_certificate *host;
+ /** Device certificate */
+ struct x509_certificate *device;
+};
+
+/******************************************************************************
+ *
+ * iPhone USB multiplexer
+ *
+ ******************************************************************************
+ */
+
+/** An iPhone USB multiplexed packet header */
+struct imux_header {
+ /** Protocol */
+ uint32_t protocol;
+ /** Length (including this header) */
+ uint32_t len;
+ /** Reserved */
+ uint32_t reserved;
+ /** Output sequence number */
+ uint16_t out_seq;
+ /** Input sequence number */
+ uint16_t in_seq;
+} __attribute__ (( packed ));
+
+/** iPhone USB multiplexer protocols */
+enum imux_protocol {
+ /** Version number */
+ IMUX_VERSION = 0,
+ /** Log message */
+ IMUX_LOG = 1,
+ /** TCP packet */
+ IMUX_TCP = IP_TCP,
+};
+
+/** An iPhone USB multiplexed version message header */
+struct imux_header_version {
+ /** Multiplexed packet header */
+ struct imux_header hdr;
+ /** Reserved */
+ uint32_t reserved;
+} __attribute__ (( packed ));
+
+/** An iPhone USB multiplexed log message header */
+struct imux_header_log {
+ /** Multiplexed packet header */
+ struct imux_header hdr;
+ /** Log level */
+ uint8_t level;
+ /** Message */
+ char msg[0];
+} __attribute__ (( packed ));
+
+/** An iPhone USB multiplexed pseudo-TCP message header */
+struct imux_header_tcp {
+ /** Multiplexed packet header */
+ struct imux_header hdr;
+ /** Pseudo-TCP header */
+ struct tcp_header tcp;
+} __attribute__ (( packed ));
+
+/** Local port number
+ *
+ * This is a policy decision.
+ */
+#define IMUX_PORT_LOCAL 0x18ae
+
+/** Lockdown daemon port number */
+#define IMUX_PORT_LOCKDOWND 62078
+
+/** Advertised TCP window
+ *
+ * This is a policy decision.
+ */
+#define IMUX_WINDOW 0x0200
+
+/** An iPhone USB multiplexer */
+struct imux {
+ /** Reference counter */
+ struct refcnt refcnt;
+ /** USB device */
+ struct usb_device *usb;
+ /** USB bus */
+ struct usb_bus *bus;
+ /** USB network device */
+ struct usbnet_device usbnet;
+ /** List of USB multiplexers */
+ struct list_head list;
+
+ /** Polling process */
+ struct process process;
+ /** Pending action
+ *
+ * @v imux USB multiplexer
+ * @ret rc Return status code
+ */
+ int ( * action ) ( struct imux *imux );
+
+ /** Input sequence */
+ uint16_t in_seq;
+ /** Output sequence */
+ uint16_t out_seq;
+ /** Pseudo-TCP sequence number */
+ uint32_t tcp_seq;
+ /** Pseudo-TCP acknowledgement number */
+ uint32_t tcp_ack;
+ /** Pseudo-TCP local port number */
+ uint16_t port;
+
+ /** Pseudo-TCP lockdown socket interface */
+ struct interface tcp;
+ /** Pairing flags */
+ unsigned int flags;
+ /** Pairing status */
+ int rc;
+};
+
+/** Multiplexer bulk IN maximum fill level
+ *
+ * This is a policy decision.
+ */
+#define IMUX_IN_MAX_FILL 1
+
+/** Multiplexer bulk IN buffer size
+ *
+ * This is a policy decision.
+ */
+#define IMUX_IN_MTU 4096
+
+/******************************************************************************
+ *
+ * iPhone pairing client
+ *
+ ******************************************************************************
+ */
+
+/** An iPhone USB multiplexed pseudo-TCP XML message header */
+struct ipair_header {
+ /** Message length */
+ uint32_t len;
+ /** Message */
+ char msg[0];
+} __attribute__ (( packed ));
+
+/** An iPhone pairing client */
+struct ipair {
+ /** Reference counter */
+ struct refcnt refcnt;
+ /** Data transfer interface */
+ struct interface xfer;
+
+ /** Pairing timer */
+ struct retry_timer timer;
+ /** Transmit message
+ *
+ * @v ipair Pairing client
+ * @ret rc Return status code
+ */
+ int ( * tx ) ( struct ipair *ipair );
+ /** Receive message
+ *
+ * @v ipair Pairing client
+ * @v msg XML message
+ * @ret rc Return status code
+ */
+ int ( * rx ) ( struct ipair *ipair, char *msg );
+ /** State flags */
+ unsigned int flags;
+
+ /** Pairing certificates */
+ struct icert icert;
+};
+
+/** Pairing client state flags */
+enum ipair_flags {
+ /** Request a new pairing */
+ IPAIR_REQUEST = 0x0001,
+ /** Standalone length has been received */
+ IPAIR_RX_LEN = 0x0002,
+ /** TLS session has been started */
+ IPAIR_TLS = 0x0004,
+};
+
+/** Pairing retry delay
+ *
+ * This is a policy decision.
+ */
+#define IPAIR_RETRY_DELAY ( 1 * TICKS_PER_SEC )
+
+/******************************************************************************
+ *
+ * iPhone USB networking
+ *
+ ******************************************************************************
+ */
+
+/** Get MAC address */
+#define IPHONE_GET_MAC \
+ ( USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE | \
+ USB_REQUEST_TYPE ( 0x00 ) )
+
+/** Get link status */
+#define IPHONE_GET_LINK \
+ ( USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE | \
+ USB_REQUEST_TYPE ( 0x45 ) )
+
+/** An iPhone link status */
+enum iphone_link_status {
+ /** Personal Hotspot is disabled */
+ IPHONE_LINK_DISABLED = 0x03,
+ /** Link up */
+ IPHONE_LINK_UP = 0x04,
+ /** Link not yet determined */
+ IPHONE_LINK_UNKNOWN = -1U,
+};
+
+/** An iPhone network device */
+struct iphone {
+ /** USB device */
+ struct usb_device *usb;
+ /** USB bus */
+ struct usb_bus *bus;
+ /** Network device */
+ struct net_device *netdev;
+ /** USB network device */
+ struct usbnet_device usbnet;
+
+ /** List of iPhone network devices */
+ struct list_head list;
+ /** Link status check timer */
+ struct retry_timer timer;
+};
+
+/** Bulk IN padding */
+#define IPHONE_IN_PAD 2
+
+/** Bulk IN buffer size
+ *
+ * This is a policy decision.
+ */
+#define IPHONE_IN_MTU ( ETH_FRAME_LEN + IPHONE_IN_PAD )
+
+/** Bulk IN maximum fill level
+ *
+ * This is a policy decision.
+ */
+#define IPHONE_IN_MAX_FILL 8
+
+/** Link check interval
+ *
+ * This is a policy decision.
+ */
+#define IPHONE_LINK_CHECK_INTERVAL ( 5 * TICKS_PER_SEC )
+
+#endif /* _IPHONE_H */
diff --git a/src/drivers/net/jme.c b/src/drivers/net/jme.c
index 29694b699..c7307728d 100644
--- a/src/drivers/net/jme.c
+++ b/src/drivers/net/jme.c
@@ -262,7 +262,7 @@ jme_free_tx_resources(struct jme_adapter *jme)
sizeof(struct io_buffer *) * jme->tx_ring_size);
free(txring->bufinf);
}
- free_dma(txring->desc, jme->tx_ring_size * TX_DESC_SIZE);
+ free_phys(txring->desc, jme->tx_ring_size * TX_DESC_SIZE);
txring->desc = NULL;
txring->dma = 0;
txring->bufinf = NULL;
@@ -277,7 +277,7 @@ jme_alloc_tx_resources(struct jme_adapter *jme)
{
struct jme_ring *txring = &jme->txring;
- txring->desc = malloc_dma(jme->tx_ring_size * TX_DESC_SIZE,
+ txring->desc = malloc_phys(jme->tx_ring_size * TX_DESC_SIZE,
RING_DESC_ALIGN);
if (!txring->desc) {
DBG("Can not allocate transmit ring descriptors.\n");
@@ -442,7 +442,7 @@ jme_free_rx_resources(struct jme_adapter *jme)
free(rxring->bufinf);
}
- free_dma(rxring->desc, jme->rx_ring_size * RX_DESC_SIZE);
+ free_phys(rxring->desc, jme->rx_ring_size * RX_DESC_SIZE);
rxring->desc = NULL;
rxring->dma = 0;
rxring->bufinf = NULL;
@@ -458,7 +458,7 @@ jme_alloc_rx_resources(struct jme_adapter *jme)
struct jme_ring *rxring = &jme->rxring;
struct io_buffer **bufinf;
- rxring->desc = malloc_dma(jme->rx_ring_size * RX_DESC_SIZE,
+ rxring->desc = malloc_phys(jme->rx_ring_size * RX_DESC_SIZE,
RING_DESC_ALIGN);
if (!rxring->desc) {
DBG("Can not allocate receive ring descriptors.\n");
@@ -1191,7 +1191,7 @@ jme_probe(struct pci_device *pci)
jme = netdev->priv;
pci_set_drvdata(pci, netdev);
netdev->dev = &pci->dev;
- jme->regs = ioremap(pci->membase, JME_REGS_SIZE);
+ jme->regs = pci_ioremap(pci, pci->membase, JME_REGS_SIZE);
if (!(jme->regs)) {
DBG("Mapping PCI resource region error.\n");
rc = -ENOMEM;
diff --git a/src/drivers/net/myri10ge.c b/src/drivers/net/myri10ge.c
index ae6b6c21e..6d0f723f2 100644
--- a/src/drivers/net/myri10ge.c
+++ b/src/drivers/net/myri10ge.c
@@ -66,7 +66,7 @@ FILE_LICENCE ( GPL2_ONLY );
/*
* Debugging levels:
- * - DBG() is for any errors, i.e. failed alloc_iob(), malloc_dma(),
+ * - DBG() is for any errors, i.e. failed alloc_iob(), malloc_phys(),
* TX overflow, corrupted packets, ...
* - DBG2() is for successful events, like packet received,
* packet transmitted, and other general notifications.
@@ -918,7 +918,7 @@ static void myri10ge_net_close ( struct net_device *netdev )
/* Release DMAable memory. */
- free_dma ( priv->dma, sizeof ( *priv->dma ) );
+ free_phys ( priv->dma, sizeof ( *priv->dma ) );
/* Erase all state from the open. */
@@ -988,7 +988,7 @@ static int myri10ge_net_open ( struct net_device *netdev )
/* Allocate cleared DMAable buffers. */
- priv->dma = malloc_dma ( sizeof ( *priv->dma ) , 128 );
+ priv->dma = malloc_phys ( sizeof ( *priv->dma ) , 128 );
if ( !priv->dma ) {
rc = -ENOMEM;
dbg = "DMA";
@@ -1152,7 +1152,7 @@ abort_with_receives_posted:
free_iob ( priv->receive_iob[priv->receives_posted] );
abort_with_dma:
/* Because the link is not up, we don't have to reset the NIC here. */
- free_dma ( priv->dma, sizeof ( *priv->dma ) );
+ free_phys ( priv->dma, sizeof ( *priv->dma ) );
abort_with_nothing:
/* Erase all signs of the failed open. */
memset ( priv, 0, sizeof ( *priv ) );
diff --git a/src/drivers/net/myson.c b/src/drivers/net/myson.c
index 84a550596..4ab2bf345 100644
--- a/src/drivers/net/myson.c
+++ b/src/drivers/net/myson.c
@@ -165,7 +165,7 @@ static int myson_create_ring ( struct myson_nic *myson,
int rc;
/* Allocate descriptor ring */
- ring->desc = malloc_dma ( len, MYSON_RING_ALIGN );
+ ring->desc = malloc_phys ( len, MYSON_RING_ALIGN );
if ( ! ring->desc ) {
rc = -ENOMEM;
goto err_alloc;
@@ -197,7 +197,7 @@ static int myson_create_ring ( struct myson_nic *myson,
return 0;
err_64bit:
- free_dma ( ring->desc, len );
+ free_phys ( ring->desc, len );
ring->desc = NULL;
err_alloc:
return rc;
@@ -217,7 +217,7 @@ static void myson_destroy_ring ( struct myson_nic *myson,
writel ( 0, myson->regs + ring->reg );
/* Free descriptor ring */
- free_dma ( ring->desc, len );
+ free_phys ( ring->desc, len );
ring->desc = NULL;
ring->prod = 0;
ring->cons = 0;
@@ -606,7 +606,7 @@ static int myson_probe ( struct pci_device *pci ) {
adjust_pci_device ( pci );
/* Map registers */
- myson->regs = ioremap ( pci->membase, MYSON_BAR_SIZE );
+ myson->regs = pci_ioremap ( pci, pci->membase, MYSON_BAR_SIZE );
if ( ! myson->regs ) {
rc = -ENODEV;
goto err_ioremap;
diff --git a/src/drivers/net/natsemi.c b/src/drivers/net/natsemi.c
index 9f2c3029c..ba99bc2fe 100644
--- a/src/drivers/net/natsemi.c
+++ b/src/drivers/net/natsemi.c
@@ -408,7 +408,7 @@ static int natsemi_create_ring ( struct natsemi_nic *natsemi,
* ensure that it can't possibly cross the boundary of 32-bit
* address space.
*/
- ring->desc = malloc_dma ( len, len );
+ ring->desc = malloc_phys ( len, len );
if ( ! ring->desc ) {
rc = -ENOMEM;
goto err_alloc;
@@ -454,7 +454,7 @@ static int natsemi_create_ring ( struct natsemi_nic *natsemi,
return 0;
err_64bit:
- free_dma ( ring->desc, len );
+ free_phys ( ring->desc, len );
ring->desc = NULL;
err_alloc:
return rc;
@@ -476,7 +476,7 @@ static void natsemi_destroy_ring ( struct natsemi_nic *natsemi,
writel ( 0, natsemi->regs + ring->reg + 4 );
/* Free descriptor ring */
- free_dma ( ring->desc, len );
+ free_phys ( ring->desc, len );
ring->desc = NULL;
ring->prod = 0;
ring->cons = 0;
@@ -853,7 +853,7 @@ static int natsemi_probe ( struct pci_device *pci ) {
adjust_pci_device ( pci );
/* Map registers */
- natsemi->regs = ioremap ( pci->membase, NATSEMI_BAR_SIZE );
+ natsemi->regs = pci_ioremap ( pci, pci->membase, NATSEMI_BAR_SIZE );
if ( ! natsemi->regs ) {
rc = -ENODEV;
goto err_ioremap;
diff --git a/src/drivers/net/ncm.c b/src/drivers/net/ncm.c
index 1837291f7..cc07a4388 100644
--- a/src/drivers/net/ncm.c
+++ b/src/drivers/net/ncm.c
@@ -558,6 +558,8 @@ static int ncm_probe ( struct usb_function *func,
struct usb_interface_descriptor *comms;
struct ecm_ethernet_descriptor *ethernet;
struct ncm_ntb_parameters params;
+ unsigned int remainder;
+ unsigned int divisor;
int rc;
/* Allocate and initialise structure */
@@ -616,14 +618,15 @@ static int ncm_probe ( struct usb_function *func,
DBGC2 ( ncm, "NCM %p maximum IN size is %zd bytes\n", ncm, ncm->mtu );
/* Calculate transmit padding */
- ncm->padding = ( ( le16_to_cpu ( params.out.remainder ) -
- sizeof ( struct ncm_ntb_header ) - ETH_HLEN ) &
- ( le16_to_cpu ( params.out.divisor ) - 1 ) );
+ divisor = ( params.out.divisor ?
+ le16_to_cpu ( params.out.divisor ) : 1 );
+ remainder = le16_to_cpu ( params.out.remainder );
+ ncm->padding = ( ( remainder - sizeof ( struct ncm_ntb_header ) -
+ ETH_HLEN ) & ( divisor - 1 ) );
DBGC2 ( ncm, "NCM %p using %zd-byte transmit padding\n",
ncm, ncm->padding );
assert ( ( ( sizeof ( struct ncm_ntb_header ) + ncm->padding +
- ETH_HLEN ) % le16_to_cpu ( params.out.divisor ) ) ==
- le16_to_cpu ( params.out.remainder ) );
+ ETH_HLEN ) % divisor ) == remainder );
/* Register network device */
if ( ( rc = register_netdev ( netdev ) ) != 0 )
diff --git a/src/drivers/net/netfront.c b/src/drivers/net/netfront.c
index b6205542b..be210850a 100644
--- a/src/drivers/net/netfront.c
+++ b/src/drivers/net/netfront.c
@@ -338,7 +338,7 @@ static int netfront_create_ring ( struct netfront_nic *netfront,
ring->id_cons = 0;
/* Allocate and initialise shared ring */
- ring->sring.raw = malloc_dma ( PAGE_SIZE, PAGE_SIZE );
+ ring->sring.raw = malloc_phys ( PAGE_SIZE, PAGE_SIZE );
if ( ! ring->sring.raw ) {
rc = -ENOMEM;
goto err_alloc;
@@ -368,7 +368,7 @@ static int netfront_create_ring ( struct netfront_nic *netfront,
err_write_num:
xengrant_invalidate ( xen, ring->ref );
err_permit_access:
- free_dma ( ring->sring.raw, PAGE_SIZE );
+ free_phys ( ring->sring.raw, PAGE_SIZE );
err_alloc:
return rc;
}
@@ -490,7 +490,7 @@ static void netfront_destroy_ring ( struct netfront_nic *netfront,
xengrant_invalidate ( xen, ring->ref );
/* Free page */
- free_dma ( ring->sring.raw, PAGE_SIZE );
+ free_phys ( ring->sring.raw, PAGE_SIZE );
ring->sring.raw = NULL;
}
diff --git a/src/drivers/net/pcnet32.c b/src/drivers/net/pcnet32.c
index 2635aaca2..c0dea86a8 100644
--- a/src/drivers/net/pcnet32.c
+++ b/src/drivers/net/pcnet32.c
@@ -246,7 +246,7 @@ pcnet32_setup_rx_resources ( struct pcnet32_private *priv )
{
DBGP ( "pcnet32_setup_rx_resources\n" );
- priv->rx_base = malloc_dma ( RX_RING_BYTES, RX_RING_ALIGN );
+ priv->rx_base = malloc_phys ( RX_RING_BYTES, RX_RING_ALIGN );
DBG ( "priv->rx_base = %#08lx\n", virt_to_bus ( priv->rx_base ) );
@@ -270,7 +270,7 @@ pcnet32_free_rx_resources ( struct pcnet32_private *priv )
DBGP ( "pcnet32_free_rx_resources\n" );
- free_dma ( priv->rx_base, RX_RING_BYTES );
+ free_phys ( priv->rx_base, RX_RING_BYTES );
for ( i = 0; i < RX_RING_SIZE; i++ ) {
free_iob ( priv->rx_iobuf[i] );
@@ -290,7 +290,7 @@ pcnet32_setup_tx_resources ( struct pcnet32_private *priv )
{
DBGP ( "pcnet32_setup_tx_resources\n" );
- priv->tx_base = malloc_dma ( TX_RING_BYTES, TX_RING_ALIGN );
+ priv->tx_base = malloc_phys ( TX_RING_BYTES, TX_RING_ALIGN );
if ( ! priv->tx_base ) {
return -ENOMEM;
@@ -312,7 +312,7 @@ pcnet32_free_tx_resources ( struct pcnet32_private *priv )
{
DBGP ( "pcnet32_free_tx_resources\n" );
- free_dma ( priv->tx_base, TX_RING_BYTES );
+ free_phys ( priv->tx_base, TX_RING_BYTES );
}
static int
diff --git a/src/drivers/net/phantom/phantom.c b/src/drivers/net/phantom/phantom.c
index 781049ff4..843459059 100644
--- a/src/drivers/net/phantom/phantom.c
+++ b/src/drivers/net/phantom/phantom.c
@@ -640,7 +640,7 @@ static int phantom_create_rx_ctx ( struct phantom_nic *phantom ) {
int rc;
/* Allocate context creation buffer */
- buf = malloc_dma ( sizeof ( *buf ), UNM_DMA_BUFFER_ALIGN );
+ buf = malloc_phys ( sizeof ( *buf ), UNM_DMA_BUFFER_ALIGN );
if ( ! buf ) {
rc = -ENOMEM;
goto out;
@@ -716,7 +716,7 @@ static int phantom_create_rx_ctx ( struct phantom_nic *phantom ) {
phantom, phantom->sds_irq_mask_crb );
out:
- free_dma ( buf, sizeof ( *buf ) );
+ free_phys ( buf, sizeof ( *buf ) );
return rc;
}
@@ -765,7 +765,7 @@ static int phantom_create_tx_ctx ( struct phantom_nic *phantom ) {
int rc;
/* Allocate context creation buffer */
- buf = malloc_dma ( sizeof ( *buf ), UNM_DMA_BUFFER_ALIGN );
+ buf = malloc_phys ( sizeof ( *buf ), UNM_DMA_BUFFER_ALIGN );
if ( ! buf ) {
rc = -ENOMEM;
goto out;
@@ -821,7 +821,7 @@ static int phantom_create_tx_ctx ( struct phantom_nic *phantom ) {
phantom, phantom->cds_producer_crb );
out:
- free_dma ( buf, sizeof ( *buf ) );
+ free_phys ( buf, sizeof ( *buf ) );
return rc;
}
@@ -1164,8 +1164,8 @@ static int phantom_open ( struct net_device *netdev ) {
int rc;
/* Allocate and zero descriptor rings */
- phantom->desc = malloc_dma ( sizeof ( *(phantom->desc) ),
- UNM_DMA_BUFFER_ALIGN );
+ phantom->desc = malloc_phys ( sizeof ( *(phantom->desc) ),
+ UNM_DMA_BUFFER_ALIGN );
if ( ! phantom->desc ) {
rc = -ENOMEM;
goto err_alloc_desc;
@@ -1208,7 +1208,7 @@ static int phantom_open ( struct net_device *netdev ) {
err_create_tx_ctx:
phantom_destroy_rx_ctx ( phantom );
err_create_rx_ctx:
- free_dma ( phantom->desc, sizeof ( *(phantom->desc) ) );
+ free_phys ( phantom->desc, sizeof ( *(phantom->desc) ) );
phantom->desc = NULL;
err_alloc_desc:
return rc;
@@ -1229,7 +1229,7 @@ static void phantom_close ( struct net_device *netdev ) {
phantom_del_macaddr ( phantom, netdev->ll_broadcast );
phantom_destroy_tx_ctx ( phantom );
phantom_destroy_rx_ctx ( phantom );
- free_dma ( phantom->desc, sizeof ( *(phantom->desc) ) );
+ free_phys ( phantom->desc, sizeof ( *(phantom->desc) ) );
phantom->desc = NULL;
/* Flush any uncompleted descriptors */
@@ -1837,7 +1837,7 @@ static int phantom_map_crb ( struct phantom_nic *phantom,
return -EINVAL;
}
- phantom->bar0 = ioremap ( bar0_start, bar0_size );
+ phantom->bar0 = pci_ioremap ( pci, bar0_start, bar0_size );
if ( ! phantom->bar0 ) {
DBGC ( phantom, "Phantom %p could not map BAR0\n", phantom );
return -EIO;
diff --git a/src/drivers/net/prism2_pci.c b/src/drivers/net/prism2_pci.c
index 69ddf0fb0..2feb69522 100644
--- a/src/drivers/net/prism2_pci.c
+++ b/src/drivers/net/prism2_pci.c
@@ -36,7 +36,7 @@ static int prism2_pci_probe ( struct nic *nic, struct pci_device *pci ) {
hfa384x_t *hw = &hw_global;
printf ( "Prism2.5 has registers at %#lx\n", pci->membase );
- hw->membase = ioremap ( pci->membase, 0x100 );
+ hw->membase = pci_ioremap ( pci, pci->membase, 0x100 );
nic->ioaddr = pci->membase;
nic->irqno = 0;
diff --git a/src/drivers/net/realtek.c b/src/drivers/net/realtek.c
index 310b9f96a..0af3416d5 100644
--- a/src/drivers/net/realtek.c
+++ b/src/drivers/net/realtek.c
@@ -36,6 +36,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <ipxe/iobuf.h>
#include <ipxe/malloc.h>
#include <ipxe/pci.h>
+#include <ipxe/dma.h>
#include <ipxe/nvs.h>
#include <ipxe/threewire.h>
#include <ipxe/bitbash.h>
@@ -505,44 +506,27 @@ static void realtek_check_link ( struct net_device *netdev ) {
* @ret rc Return status code
*/
static int realtek_create_buffer ( struct realtek_nic *rtl ) {
+ struct realtek_rx_buffer *rxbuf = &rtl->rxbuf;
size_t len = ( RTL_RXBUF_LEN + RTL_RXBUF_PAD );
- physaddr_t address;
- int rc;
/* Do nothing unless in legacy mode */
if ( ! rtl->legacy )
return 0;
/* Allocate buffer */
- rtl->rx_buffer = malloc_dma ( len, RTL_RXBUF_ALIGN );
- if ( ! rtl->rx_buffer ) {
- rc = -ENOMEM;
- goto err_alloc;
- }
- address = virt_to_bus ( rtl->rx_buffer );
-
- /* Check that card can support address */
- if ( address & ~0xffffffffULL ) {
- DBGC ( rtl, "REALTEK %p cannot support 64-bit RX buffer "
- "address\n", rtl );
- rc = -ENOTSUP;
- goto err_64bit;
- }
+ rxbuf->data = dma_alloc ( rtl->dma, &rxbuf->map, len,
+ RTL_RXBUF_ALIGN );
+ if ( ! rxbuf->data )
+ return -ENOMEM;
/* Program buffer address */
- writel ( address, rtl->regs + RTL_RBSTART );
- DBGC ( rtl, "REALTEK %p receive buffer is at [%08llx,%08llx,%08llx)\n",
- rtl, ( ( unsigned long long ) address ),
- ( ( unsigned long long ) address + RTL_RXBUF_LEN ),
- ( ( unsigned long long ) address + len ) );
+ writel ( dma ( &rxbuf->map, rxbuf->data ), rtl->regs + RTL_RBSTART );
+ DBGC ( rtl, "REALTEK %p receive buffer is at [%08lx,%08lx,%08lx)\n",
+ rtl, virt_to_phys ( rxbuf->data ),
+ ( virt_to_phys ( rxbuf->data ) + RTL_RXBUF_LEN ),
+ ( virt_to_phys ( rxbuf->data ) + len ) );
return 0;
-
- err_64bit:
- free_dma ( rtl->rx_buffer, len );
- rtl->rx_buffer = NULL;
- err_alloc:
- return rc;
}
/**
@@ -551,6 +535,7 @@ static int realtek_create_buffer ( struct realtek_nic *rtl ) {
* @v rtl Realtek device
*/
static void realtek_destroy_buffer ( struct realtek_nic *rtl ) {
+ struct realtek_rx_buffer *rxbuf = &rtl->rxbuf;
size_t len = ( RTL_RXBUF_LEN + RTL_RXBUF_PAD );
/* Do nothing unless in legacy mode */
@@ -561,9 +546,9 @@ static void realtek_destroy_buffer ( struct realtek_nic *rtl ) {
writel ( 0, rtl->regs + RTL_RBSTART );
/* Free buffer */
- free_dma ( rtl->rx_buffer, len );
- rtl->rx_buffer = NULL;
- rtl->rx_offset = 0;
+ dma_free ( &rxbuf->map, rxbuf->data, len );
+ rxbuf->data = NULL;
+ rxbuf->offset = 0;
}
/**
@@ -582,7 +567,8 @@ static int realtek_create_ring ( struct realtek_nic *rtl,
return 0;
/* Allocate descriptor ring */
- ring->desc = malloc_dma ( ring->len, RTL_RING_ALIGN );
+ ring->desc = dma_alloc ( rtl->dma, &ring->map, ring->len,
+ RTL_RING_ALIGN );
if ( ! ring->desc )
return -ENOMEM;
@@ -590,13 +576,13 @@ static int realtek_create_ring ( struct realtek_nic *rtl,
memset ( ring->desc, 0, ring->len );
/* Program ring address */
- address = virt_to_bus ( ring->desc );
+ address = dma ( &ring->map, ring->desc );
writel ( ( ( ( uint64_t ) address ) >> 32 ),
rtl->regs + ring->reg + 4 );
writel ( ( address & 0xffffffffUL ), rtl->regs + ring->reg );
- DBGC ( rtl, "REALTEK %p ring %02x is at [%08llx,%08llx)\n",
- rtl, ring->reg, ( ( unsigned long long ) address ),
- ( ( unsigned long long ) address + ring->len ) );
+ DBGC ( rtl, "REALTEK %p ring %02x is at [%08lx,%08lx)\n",
+ rtl, ring->reg, virt_to_phys ( ring->desc ),
+ ( virt_to_phys ( ring->desc ) + ring->len ) );
return 0;
}
@@ -623,7 +609,7 @@ static void realtek_destroy_ring ( struct realtek_nic *rtl,
writel ( 0, rtl->regs + ring->reg + 4 );
/* Free descriptor ring */
- free_dma ( ring->desc, ring->len );
+ dma_free ( &ring->map, ring->desc, ring->len );
ring->desc = NULL;
}
@@ -636,7 +622,6 @@ static void realtek_refill_rx ( struct realtek_nic *rtl ) {
struct realtek_descriptor *rx;
struct io_buffer *iobuf;
unsigned int rx_idx;
- physaddr_t address;
int is_last;
/* Do nothing in legacy mode */
@@ -646,7 +631,7 @@ static void realtek_refill_rx ( struct realtek_nic *rtl ) {
while ( ( rtl->rx.prod - rtl->rx.cons ) < RTL_NUM_RX_DESC ) {
/* Allocate I/O buffer */
- iobuf = alloc_iob ( RTL_RX_MAX_LEN );
+ iobuf = alloc_rx_iob ( RTL_RX_MAX_LEN, rtl->dma );
if ( ! iobuf ) {
/* Wait for next refill */
return;
@@ -658,8 +643,7 @@ static void realtek_refill_rx ( struct realtek_nic *rtl ) {
rx = &rtl->rx.desc[rx_idx];
/* Populate receive descriptor */
- address = virt_to_bus ( iobuf->data );
- rx->address = cpu_to_le64 ( address );
+ rx->address = cpu_to_le64 ( iob_dma ( iobuf ) );
rx->length = cpu_to_le16 ( RTL_RX_MAX_LEN );
wmb();
rx->flags = ( cpu_to_le16 ( RTL_DESC_OWN ) |
@@ -670,9 +654,9 @@ static void realtek_refill_rx ( struct realtek_nic *rtl ) {
assert ( rtl->rx_iobuf[rx_idx] == NULL );
rtl->rx_iobuf[rx_idx] = iobuf;
- DBGC2 ( rtl, "REALTEK %p RX %d is [%llx,%llx)\n", rtl, rx_idx,
- ( ( unsigned long long ) address ),
- ( ( unsigned long long ) address + RTL_RX_MAX_LEN ) );
+ DBGC2 ( rtl, "REALTEK %p RX %d is [%lx,%lx)\n",
+ rtl, rx_idx, virt_to_phys ( iobuf->data ),
+ ( virt_to_phys ( iobuf->data ) + RTL_RX_MAX_LEN ) );
}
}
@@ -762,12 +746,16 @@ static void realtek_close ( struct net_device *netdev ) {
/* Discard any unused receive buffers */
for ( i = 0 ; i < RTL_NUM_RX_DESC ; i++ ) {
if ( rtl->rx_iobuf[i] )
- free_iob ( rtl->rx_iobuf[i] );
+ free_rx_iob ( rtl->rx_iobuf[i] );
rtl->rx_iobuf[i] = NULL;
}
/* Destroy transmit descriptor ring */
realtek_destroy_ring ( rtl, &rtl->tx );
+
+ /* Reset legacy transmit descriptor index, if applicable */
+ if ( rtl->legacy )
+ realtek_reset ( rtl );
}
/**
@@ -782,42 +770,41 @@ static int realtek_transmit ( struct net_device *netdev,
struct realtek_nic *rtl = netdev->priv;
struct realtek_descriptor *tx;
unsigned int tx_idx;
- physaddr_t address;
int is_last;
+ int rc;
/* Get next transmit descriptor */
if ( ( rtl->tx.prod - rtl->tx.cons ) >= RTL_NUM_TX_DESC ) {
netdev_tx_defer ( netdev, iobuf );
return 0;
}
- tx_idx = ( rtl->tx.prod++ % RTL_NUM_TX_DESC );
+ tx_idx = ( rtl->tx.prod % RTL_NUM_TX_DESC );
- /* Transmit packet */
- if ( rtl->legacy ) {
-
- /* Pad and align packet */
+ /* Pad and align packet, if needed */
+ if ( rtl->legacy )
iob_pad ( iobuf, ETH_ZLEN );
- address = virt_to_bus ( iobuf->data );
- /* Check that card can support address */
- if ( address & ~0xffffffffULL ) {
- DBGC ( rtl, "REALTEK %p cannot support 64-bit TX "
- "buffer address\n", rtl );
- return -ENOTSUP;
- }
+ /* Map I/O buffer */
+ if ( ( rc = iob_map_tx ( iobuf, rtl->dma ) ) != 0 )
+ return rc;
+
+ /* Update producer index */
+ rtl->tx.prod++;
+
+ /* Transmit packet */
+ if ( rtl->legacy ) {
/* Add to transmit ring */
- writel ( address, rtl->regs + RTL_TSAD ( tx_idx ) );
+ writel ( iob_dma ( iobuf ), rtl->regs + RTL_TSAD ( tx_idx ) );
writel ( ( RTL_TSD_ERTXTH_DEFAULT | iob_len ( iobuf ) ),
rtl->regs + RTL_TSD ( tx_idx ) );
} else {
/* Populate transmit descriptor */
- address = virt_to_bus ( iobuf->data );
is_last = ( tx_idx == ( RTL_NUM_TX_DESC - 1 ) );
tx = &rtl->tx.desc[tx_idx];
- tx->address = cpu_to_le64 ( address );
+ tx->address = cpu_to_le64 ( iob_dma ( iobuf ) );
tx->length = cpu_to_le16 ( iob_len ( iobuf ) );
wmb();
tx->flags = ( cpu_to_le16 ( RTL_DESC_OWN | RTL_DESC_FS |
@@ -829,10 +816,9 @@ static int realtek_transmit ( struct net_device *netdev,
writeb ( RTL_TPPOLL_NPQ, rtl->regs + rtl->tppoll );
}
- DBGC2 ( rtl, "REALTEK %p TX %d is [%llx,%llx)\n", rtl, tx_idx,
- ( ( unsigned long long ) virt_to_bus ( iobuf->data ) ),
- ( ( ( unsigned long long ) virt_to_bus ( iobuf->data ) ) +
- iob_len ( iobuf ) ) );
+ DBGC2 ( rtl, "REALTEK %p TX %d is [%lx,%lx)\n",
+ rtl, tx_idx, virt_to_phys ( iobuf->data ),
+ virt_to_phys ( iobuf->data ) + iob_len ( iobuf ) );
return 0;
}
@@ -892,12 +878,12 @@ static void realtek_legacy_poll_rx ( struct net_device *netdev ) {
while ( ! ( readb ( rtl->regs + RTL_CR ) & RTL_CR_BUFE ) ) {
/* Extract packet from receive buffer */
- rx = ( rtl->rx_buffer + rtl->rx_offset );
+ rx = ( rtl->rxbuf.data + rtl->rxbuf.offset );
len = le16_to_cpu ( rx->length );
if ( rx->status & cpu_to_le16 ( RTL_STAT_ROK ) ) {
DBGC2 ( rtl, "REALTEK %p RX offset %x+%zx\n",
- rtl, rtl->rx_offset, len );
+ rtl, rtl->rxbuf.offset, len );
/* Allocate I/O buffer */
iobuf = alloc_iob ( len );
@@ -917,16 +903,16 @@ static void realtek_legacy_poll_rx ( struct net_device *netdev ) {
} else {
DBGC ( rtl, "REALTEK %p RX offset %x+%zx error %04x\n",
- rtl, rtl->rx_offset, len,
+ rtl, rtl->rxbuf.offset, len,
le16_to_cpu ( rx->status ) );
netdev_rx_err ( netdev, NULL, -EIO );
}
/* Update buffer offset */
- rtl->rx_offset = ( rtl->rx_offset + sizeof ( *rx ) + len );
- rtl->rx_offset = ( ( rtl->rx_offset + 3 ) & ~3 );
- rtl->rx_offset = ( rtl->rx_offset % RTL_RXBUF_LEN );
- writew ( ( rtl->rx_offset - 16 ), rtl->regs + RTL_CAPR );
+ rtl->rxbuf.offset += ( sizeof ( *rx ) + len );
+ rtl->rxbuf.offset = ( ( rtl->rxbuf.offset + 3 ) & ~3 );
+ rtl->rxbuf.offset = ( rtl->rxbuf.offset % RTL_RXBUF_LEN );
+ writew ( ( rtl->rxbuf.offset - 16 ), rtl->regs + RTL_CAPR );
/* Give chip time to react before rechecking RTL_CR */
readw ( rtl->regs + RTL_CAPR );
@@ -1084,11 +1070,13 @@ static void realtek_detect ( struct realtek_nic *rtl ) {
DBGC ( rtl, "REALTEK %p appears to be an RTL8169\n", rtl );
rtl->have_phy_regs = 1;
rtl->tppoll = RTL_TPPOLL_8169;
+ dma_set_mask_64bit ( rtl->dma );
} else {
if ( ( check_cpcr == cpcr ) && ( cpcr != 0xffff ) ) {
DBGC ( rtl, "REALTEK %p appears to be an RTL8139C+\n",
rtl );
rtl->tppoll = RTL_TPPOLL_8139CP;
+ dma_set_mask_64bit ( rtl->dma );
} else {
DBGC ( rtl, "REALTEK %p appears to be an RTL8139\n",
rtl );
@@ -1128,12 +1116,15 @@ static int realtek_probe ( struct pci_device *pci ) {
adjust_pci_device ( pci );
/* Map registers */
- rtl->regs = ioremap ( pci->membase, RTL_BAR_SIZE );
+ rtl->regs = pci_ioremap ( pci, pci->membase, RTL_BAR_SIZE );
if ( ! rtl->regs ) {
rc = -ENODEV;
goto err_ioremap;
}
+ /* Configure DMA */
+ rtl->dma = &pci->dma;
+
/* Reset the NIC */
if ( ( rc = realtek_reset ( rtl ) ) != 0 )
goto err_reset;
diff --git a/src/drivers/net/realtek.h b/src/drivers/net/realtek.h
index 4d13784c4..d4642fd76 100644
--- a/src/drivers/net/realtek.h
+++ b/src/drivers/net/realtek.h
@@ -247,6 +247,8 @@ enum realtek_legacy_status {
struct realtek_ring {
/** Descriptors */
struct realtek_descriptor *desc;
+ /** Descriptor ring DMA mapping */
+ struct dma_mapping map;
/** Producer index */
unsigned int prod;
/** Consumer index */
@@ -272,10 +274,22 @@ realtek_init_ring ( struct realtek_ring *ring, unsigned int count,
ring->reg = reg;
}
+/** Receive buffer (legacy mode *) */
+struct realtek_rx_buffer {
+ /** Buffer */
+ void *data;
+ /** Buffer DMA mapping */
+ struct dma_mapping map;
+ /** Offset within buffer */
+ unsigned int offset;
+};
+
/** A Realtek network card */
struct realtek_nic {
/** Registers */
void *regs;
+ /** DMA device */
+ struct dma_device *dma;
/** SPI bit-bashing interface */
struct spi_bit_basher spibit;
/** EEPROM */
@@ -301,9 +315,7 @@ struct realtek_nic {
/** Receive I/O buffers */
struct io_buffer *rx_iobuf[RTL_NUM_RX_DESC];
/** Receive buffer (legacy mode) */
- void *rx_buffer;
- /** Offset within receive buffer (legacy mode) */
- unsigned int rx_offset;
+ struct realtek_rx_buffer rxbuf;
};
#endif /* _REALTEK_H */
diff --git a/src/drivers/net/rhine.c b/src/drivers/net/rhine.c
index a1dc58725..f4d3a2580 100644
--- a/src/drivers/net/rhine.c
+++ b/src/drivers/net/rhine.c
@@ -292,7 +292,7 @@ static int rhine_create_ring ( struct rhine_nic *rhn,
unsigned int i;
/* Allocate descriptors */
- ring->desc = malloc_dma ( len, RHINE_RING_ALIGN );
+ ring->desc = malloc_phys ( len, RHINE_RING_ALIGN );
if ( ! ring->desc )
return -ENOMEM;
@@ -328,7 +328,7 @@ static void rhine_destroy_ring ( struct rhine_nic *rhn,
writel ( 0, rhn->regs + ring->reg );
/* Free descriptor ring */
- free_dma ( ring->desc, len );
+ free_phys ( ring->desc, len );
ring->desc = NULL;
ring->prod = 0;
ring->cons = 0;
@@ -700,7 +700,7 @@ static int rhine_probe ( struct pci_device *pci ) {
adjust_pci_device ( pci );
/* Map registers */
- rhn->regs = ioremap ( pci->membase, RHINE_BAR_SIZE );
+ rhn->regs = pci_ioremap ( pci, pci->membase, RHINE_BAR_SIZE );
rhn->ioaddr = pci->ioaddr;
DBGC ( rhn, "RHINE %p regs at %08lx, I/O at %04lx\n", rhn,
pci->membase, pci->ioaddr );
diff --git a/src/drivers/net/rtl818x/rtl818x.c b/src/drivers/net/rtl818x/rtl818x.c
index f5082084e..599d36fad 100644
--- a/src/drivers/net/rtl818x/rtl818x.c
+++ b/src/drivers/net/rtl818x/rtl818x.c
@@ -328,8 +328,8 @@ static int rtl818x_init_rx_ring(struct net80211_device *dev)
struct rtl818x_rx_desc *entry;
int i;
- priv->rx_ring = malloc_dma(sizeof(*priv->rx_ring) * RTL818X_RX_RING_SIZE,
- RTL818X_RING_ALIGN);
+ priv->rx_ring = malloc_phys(sizeof(*priv->rx_ring) * RTL818X_RX_RING_SIZE,
+ RTL818X_RING_ALIGN);
priv->rx_ring_dma = virt_to_bus(priv->rx_ring);
if (!priv->rx_ring) {
DBG("rtl818x %s: cannot allocate RX ring\n", dev->netdev->name);
@@ -364,7 +364,7 @@ static void rtl818x_free_rx_ring(struct net80211_device *dev)
priv->rx_buf[i] = NULL;
}
- free_dma(priv->rx_ring, sizeof(*priv->rx_ring) * RTL818X_RX_RING_SIZE);
+ free_phys(priv->rx_ring, sizeof(*priv->rx_ring) * RTL818X_RX_RING_SIZE);
priv->rx_ring = NULL;
}
@@ -373,8 +373,8 @@ static int rtl818x_init_tx_ring(struct net80211_device *dev)
struct rtl818x_priv *priv = dev->priv;
int i;
- priv->tx_ring = malloc_dma(sizeof(*priv->tx_ring) * RTL818X_TX_RING_SIZE,
- RTL818X_RING_ALIGN);
+ priv->tx_ring = malloc_phys(sizeof(*priv->tx_ring) * RTL818X_TX_RING_SIZE,
+ RTL818X_RING_ALIGN);
priv->tx_ring_dma = virt_to_bus(priv->tx_ring);
if (!priv->tx_ring) {
DBG("rtl818x %s: cannot allocate TX ring\n", dev->netdev->name);
@@ -402,7 +402,7 @@ static void rtl818x_free_tx_ring(struct net80211_device *dev)
priv->tx_buf[i] = NULL;
}
- free_dma(priv->tx_ring, sizeof(*priv->tx_ring) * RTL818X_TX_RING_SIZE);
+ free_phys(priv->tx_ring, sizeof(*priv->tx_ring) * RTL818X_TX_RING_SIZE);
priv->tx_ring = NULL;
}
diff --git a/src/drivers/net/sfc/efx_common.c b/src/drivers/net/sfc/efx_common.c
index 403887707..ad572b1da 100644
--- a/src/drivers/net/sfc/efx_common.c
+++ b/src/drivers/net/sfc/efx_common.c
@@ -2,11 +2,12 @@
*
* Driver datapath common code for Solarflare network cards
*
- * Written by Shradha Shah <sshah@solarflare.com>
+ * Written by Shradha Shah, maintained by <pre-boot-drivers@xilinx.com>
*
* Copyright Fen Systems Ltd. 2005
* Copyright Level 5 Networks Inc. 2005
- * Copyright 2006-2017 Solarflare Communications Inc.
+ * Copyright 2006-2019 Solarflare Communications Inc.
+ * Copyright 2019-2020 Xilinx Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -85,7 +86,7 @@ void efx_probe(struct net_device *netdev, enum efx_revision revision)
efx->mmio_start = pci_bar_start(pci, reg);
efx->mmio_len = pci_bar_size(pci, reg);
- efx->membase = ioremap(efx->mmio_start, efx->mmio_len);
+ efx->membase = pci_ioremap(pci, efx->mmio_start, efx->mmio_len);
DBGCP(efx, "BAR of %lx bytes at phys %lx mapped at %p\n",
efx->mmio_len, efx->mmio_start, efx->membase);
diff --git a/src/drivers/net/sfc/efx_hunt.c b/src/drivers/net/sfc/efx_hunt.c
index 07dd7dfea..0bce3e45a 100644
--- a/src/drivers/net/sfc/efx_hunt.c
+++ b/src/drivers/net/sfc/efx_hunt.c
@@ -2,9 +2,10 @@
*
* Driver datapath for Solarflare network cards
*
- * Written by Shradha Shah <sshah@solarflare.com>
+ * Written by Shradha Shah, maintained by <pre-boot-drivers@xilinx.com>
*
- * Copyright 2012-2017 Solarflare Communications Inc.
+ * Copyright 2012-2019 Solarflare Communications Inc.
+ * Copyright 2019-2020 Xilinx Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -37,7 +38,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
void efx_hunt_free_special_buffer(void *buf, int bytes)
{
- free_dma(buf, bytes);
+ free_phys(buf, bytes);
}
static void *efx_hunt_alloc_special_buffer(int bytes,
@@ -50,7 +51,7 @@ static void *efx_hunt_alloc_special_buffer(int bytes,
* buffer will be passed into an MC_CMD_INIT_*Q command to setup the
* appropriate type of queue via MCDI.
*/
- buffer = malloc_dma(bytes, EFX_BUF_ALIGN);
+ buffer = malloc_phys(bytes, EFX_BUF_ALIGN);
if (!buffer)
return NULL;
diff --git a/src/drivers/net/sfc/efx_hunt.h b/src/drivers/net/sfc/efx_hunt.h
index b8377bf20..d6bb4659f 100644
--- a/src/drivers/net/sfc/efx_hunt.h
+++ b/src/drivers/net/sfc/efx_hunt.h
@@ -2,9 +2,10 @@
*
* GPL net driver for Solarflare network cards
*
- * Written by Shradha Shah <sshah@solarflare.com>
+ * Written by Shradha Shah, maintained by <pre-boot-drivers@xilinx.com>
*
- * Copyright 2012-2017 Solarflare Communications Inc.
+ * Copyright 2012-2019 Solarflare Communications Inc.
+ * Copyright 2019-2020 Xilinx Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
diff --git a/src/drivers/net/sfc/mcdi.h b/src/drivers/net/sfc/mcdi.h
index 19c62021a..2d26cded3 100644
--- a/src/drivers/net/sfc/mcdi.h
+++ b/src/drivers/net/sfc/mcdi.h
@@ -1,9 +1,11 @@
/****************************************************************************
* Driver for Solarflare network controllers and boards
*
- * Written by Martin Habets <mhabets@solarflare.com>
+ * Written by Martin Habets <habetsm.xilinx@gmail.com>, maintained
+ * by <pre-boot-drivers@xilinx.com>
*
- * Copyright 2012-2017 Solarflare Communications Inc.
+ * Copyright 2012-2019 Solarflare Communications Inc.
+ * Copyright 2019-2020 Xilinx Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
diff --git a/src/drivers/net/sfc/sfc_hunt.c b/src/drivers/net/sfc/sfc_hunt.c
index 3c9a5fe38..a37670ae2 100644
--- a/src/drivers/net/sfc/sfc_hunt.c
+++ b/src/drivers/net/sfc/sfc_hunt.c
@@ -2,9 +2,10 @@
*
* Device driver for Solarflare Communications EF10 devices
*
- * Written by Shradha Shah <sshah@solarflare.com>
+ * Written by Shradha Shah, maintained by <pre-boot-drivers@xilinx.com>
*
- * Copyright 2012-2017 Solarflare Communications Inc.
+ * Copyright 2012-2019 Solarflare Communications Inc.
+ * Copyright 2019-2020 Xilinx Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
diff --git a/src/drivers/net/sis190.c b/src/drivers/net/sis190.c
index b92e95f2a..0e4f0762e 100644
--- a/src/drivers/net/sis190.c
+++ b/src/drivers/net/sis190.c
@@ -552,7 +552,7 @@ static int sis190_open(struct net_device *dev)
int rc;
/* Allocate TX ring */
- tp->TxDescRing = malloc_dma(TX_RING_BYTES, RING_ALIGNMENT);
+ tp->TxDescRing = malloc_phys(TX_RING_BYTES, RING_ALIGNMENT);
if (!tp->TxDescRing) {
DBG("sis190: TX ring allocation failed\n");
rc = -ENOMEM;
@@ -561,7 +561,7 @@ static int sis190_open(struct net_device *dev)
tp->tx_dma = cpu_to_le32(virt_to_bus(tp->TxDescRing));
/* Allocate RX ring */
- tp->RxDescRing = malloc_dma(RX_RING_BYTES, RING_ALIGNMENT);
+ tp->RxDescRing = malloc_phys(RX_RING_BYTES, RING_ALIGNMENT);
if (!tp->RxDescRing) {
DBG("sis190: RX ring allocation failed\n");
rc = -ENOMEM;
@@ -600,8 +600,8 @@ static void sis190_free(struct net_device *dev)
struct sis190_private *tp = netdev_priv(dev);
int i;
- free_dma(tp->TxDescRing, TX_RING_BYTES);
- free_dma(tp->RxDescRing, RX_RING_BYTES);
+ free_phys(tp->TxDescRing, TX_RING_BYTES);
+ free_phys(tp->RxDescRing, RX_RING_BYTES);
tp->TxDescRing = NULL;
tp->RxDescRing = NULL;
@@ -886,7 +886,7 @@ static int sis190_init_board(struct pci_device *pdev, struct net_device **netdev
adjust_pci_device(pdev);
- ioaddr = ioremap(pdev->membase, SIS190_REGS_SIZE);
+ ioaddr = pci_ioremap(pdev, pdev->membase, SIS190_REGS_SIZE);
if (!ioaddr) {
DBG("sis190: cannot remap MMIO, aborting\n");
rc = -EIO;
diff --git a/src/drivers/net/skeleton.c b/src/drivers/net/skeleton.c
index 0bae3089c..a76c6e3d9 100644
--- a/src/drivers/net/skeleton.c
+++ b/src/drivers/net/skeleton.c
@@ -195,7 +195,7 @@ static int skeleton_probe ( struct pci_device *pci ) {
adjust_pci_device ( pci );
/* Map registers */
- skel->regs = ioremap ( pci->membase, SKELETON_BAR_SIZE );
+ skel->regs = pci_ioremap ( pci, pci->membase, SKELETON_BAR_SIZE );
if ( ! skel->regs ) {
rc = -ENODEV;
goto err_ioremap;
diff --git a/src/drivers/net/skge.c b/src/drivers/net/skge.c
index c3264225b..5aa5e2a6a 100755
--- a/src/drivers/net/skge.c
+++ b/src/drivers/net/skge.c
@@ -1699,7 +1699,7 @@ void skge_free(struct net_device *dev)
free(skge->tx_ring.start);
skge->tx_ring.start = NULL;
- free_dma(skge->mem, RING_SIZE);
+ free_phys(skge->mem, RING_SIZE);
skge->mem = NULL;
skge->dma = 0;
}
@@ -1714,7 +1714,7 @@ static int skge_up(struct net_device *dev)
DBG2(PFX "%s: enabling interface\n", dev->name);
- skge->mem = malloc_dma(RING_SIZE, SKGE_RING_ALIGN);
+ skge->mem = malloc_phys(RING_SIZE, SKGE_RING_ALIGN);
skge->dma = virt_to_bus(skge->mem);
if (!skge->mem)
return -ENOMEM;
@@ -2346,8 +2346,9 @@ static int skge_probe(struct pci_device *pdev)
hw->pdev = pdev;
- hw->regs = (unsigned long)ioremap(pci_bar_start(pdev, PCI_BASE_ADDRESS_0),
- SKGE_REG_SIZE);
+ hw->regs = (unsigned long)pci_ioremap(pdev,
+ pci_bar_start(pdev, PCI_BASE_ADDRESS_0),
+ SKGE_REG_SIZE);
if (!hw->regs) {
DBG(PFX "cannot map device registers\n");
goto err_out_free_hw;
diff --git a/src/drivers/net/sky2.c b/src/drivers/net/sky2.c
index 211f22466..9d612c997 100644
--- a/src/drivers/net/sky2.c
+++ b/src/drivers/net/sky2.c
@@ -1112,10 +1112,10 @@ nomem:
/* Free the le and ring buffers */
static void sky2_free_rings(struct sky2_port *sky2)
{
- free_dma(sky2->rx_le, RX_LE_BYTES);
+ free_phys(sky2->rx_le, RX_LE_BYTES);
free(sky2->rx_ring);
- free_dma(sky2->tx_le, TX_RING_SIZE * sizeof(struct sky2_tx_le));
+ free_phys(sky2->tx_le, TX_RING_SIZE * sizeof(struct sky2_tx_le));
free(sky2->tx_ring);
sky2->tx_le = NULL;
@@ -1137,7 +1137,7 @@ static int sky2_up(struct net_device *dev)
netdev_link_down(dev);
/* must be power of 2 */
- sky2->tx_le = malloc_dma(TX_RING_SIZE * sizeof(struct sky2_tx_le), TX_RING_ALIGN);
+ sky2->tx_le = malloc_phys(TX_RING_SIZE * sizeof(struct sky2_tx_le), TX_RING_ALIGN);
sky2->tx_le_map = virt_to_bus(sky2->tx_le);
if (!sky2->tx_le)
goto err_out;
@@ -1149,7 +1149,7 @@ static int sky2_up(struct net_device *dev)
tx_init(sky2);
- sky2->rx_le = malloc_dma(RX_LE_BYTES, RX_RING_ALIGN);
+ sky2->rx_le = malloc_phys(RX_LE_BYTES, RX_RING_ALIGN);
sky2->rx_le_map = virt_to_bus(sky2->rx_le);
if (!sky2->rx_le)
goto err_out;
@@ -2278,14 +2278,14 @@ static int sky2_probe(struct pci_device *pdev)
hw->pdev = pdev;
- hw->regs = (unsigned long)ioremap(pci_bar_start(pdev, PCI_BASE_ADDRESS_0), 0x4000);
+ hw->regs = (unsigned long)pci_ioremap(pdev, pci_bar_start(pdev, PCI_BASE_ADDRESS_0), 0x4000);
if (!hw->regs) {
DBG(PFX "cannot map device registers\n");
goto err_out_free_hw;
}
/* ring for status responses */
- hw->st_le = malloc_dma(STATUS_LE_BYTES, STATUS_RING_ALIGN);
+ hw->st_le = malloc_phys(STATUS_LE_BYTES, STATUS_RING_ALIGN);
if (!hw->st_le)
goto err_out_iounmap;
hw->st_dma = virt_to_bus(hw->st_le);
@@ -2344,7 +2344,7 @@ err_out_free_netdev:
netdev_put(dev);
err_out_free_pci:
sky2_write8(hw, B0_CTST, CS_RST_SET);
- free_dma(hw->st_le, STATUS_LE_BYTES);
+ free_phys(hw->st_le, STATUS_LE_BYTES);
err_out_iounmap:
iounmap((void *)hw->regs);
err_out_free_hw:
@@ -2373,7 +2373,7 @@ static void sky2_remove(struct pci_device *pdev)
sky2_write8(hw, B0_CTST, CS_RST_SET);
sky2_read8(hw, B0_CTST);
- free_dma(hw->st_le, STATUS_LE_BYTES);
+ free_phys(hw->st_le, STATUS_LE_BYTES);
for (i = hw->ports-1; i >= 0; --i) {
netdev_nullify(hw->dev[i]);
diff --git a/src/drivers/net/tg3/tg3.c b/src/drivers/net/tg3/tg3.c
index 1bed06649..cec599c1c 100644
--- a/src/drivers/net/tg3/tg3.c
+++ b/src/drivers/net/tg3/tg3.c
@@ -42,7 +42,7 @@ void tg3_rx_prodring_fini(struct tg3_rx_prodring_set *tpr)
{ DBGP("%s\n", __func__);
if (tpr->rx_std) {
- free_dma(tpr->rx_std, TG3_RX_STD_RING_BYTES(tp));
+ free_phys(tpr->rx_std, TG3_RX_STD_RING_BYTES(tp));
tpr->rx_std = NULL;
}
}
@@ -55,7 +55,7 @@ static void tg3_free_consistent(struct tg3 *tp)
{ DBGP("%s\n", __func__);
if (tp->tx_ring) {
- free_dma(tp->tx_ring, TG3_TX_RING_BYTES);
+ free_phys(tp->tx_ring, TG3_TX_RING_BYTES);
tp->tx_ring = NULL;
}
@@ -63,7 +63,7 @@ static void tg3_free_consistent(struct tg3 *tp)
tp->tx_buffers = NULL;
if (tp->rx_rcb) {
- free_dma(tp->rx_rcb, TG3_RX_RCB_RING_BYTES(tp));
+ free_phys(tp->rx_rcb, TG3_RX_RCB_RING_BYTES(tp));
tp->rx_rcb_mapping = 0;
tp->rx_rcb = NULL;
}
@@ -71,7 +71,7 @@ static void tg3_free_consistent(struct tg3 *tp)
tg3_rx_prodring_fini(&tp->prodring);
if (tp->hw_status) {
- free_dma(tp->hw_status, TG3_HW_STATUS_SIZE);
+ free_phys(tp->hw_status, TG3_HW_STATUS_SIZE);
tp->status_mapping = 0;
tp->hw_status = NULL;
}
@@ -87,7 +87,7 @@ int tg3_alloc_consistent(struct tg3 *tp)
struct tg3_hw_status *sblk;
struct tg3_rx_prodring_set *tpr = &tp->prodring;
- tp->hw_status = malloc_dma(TG3_HW_STATUS_SIZE, TG3_DMA_ALIGNMENT);
+ tp->hw_status = malloc_phys(TG3_HW_STATUS_SIZE, TG3_DMA_ALIGNMENT);
if (!tp->hw_status) {
DBGC(tp->dev, "hw_status alloc failed\n");
goto err_out;
@@ -97,7 +97,7 @@ int tg3_alloc_consistent(struct tg3 *tp)
memset(tp->hw_status, 0, TG3_HW_STATUS_SIZE);
sblk = tp->hw_status;
- tpr->rx_std = malloc_dma(TG3_RX_STD_RING_BYTES(tp), TG3_DMA_ALIGNMENT);
+ tpr->rx_std = malloc_phys(TG3_RX_STD_RING_BYTES(tp), TG3_DMA_ALIGNMENT);
if (!tpr->rx_std) {
DBGC(tp->dev, "rx prodring alloc failed\n");
goto err_out;
@@ -109,7 +109,7 @@ int tg3_alloc_consistent(struct tg3 *tp)
if (!tp->tx_buffers)
goto err_out;
- tp->tx_ring = malloc_dma(TG3_TX_RING_BYTES, TG3_DMA_ALIGNMENT);
+ tp->tx_ring = malloc_phys(TG3_TX_RING_BYTES, TG3_DMA_ALIGNMENT);
if (!tp->tx_ring)
goto err_out;
tp->tx_desc_mapping = virt_to_bus(tp->tx_ring);
@@ -123,7 +123,7 @@ int tg3_alloc_consistent(struct tg3 *tp)
tp->rx_rcb_prod_idx = &sblk->idx[0].rx_producer;
- tp->rx_rcb = malloc_dma(TG3_RX_RCB_RING_BYTES(tp), TG3_DMA_ALIGNMENT);
+ tp->rx_rcb = malloc_phys(TG3_RX_RCB_RING_BYTES(tp), TG3_DMA_ALIGNMENT);
if (!tp->rx_rcb)
goto err_out;
tp->rx_rcb_mapping = virt_to_bus(tp->rx_rcb);
@@ -541,7 +541,7 @@ static int tg3_test_dma(struct tg3 *tp)
u32 *buf;
int ret = 0;
- buf = malloc_dma(TEST_BUFFER_SIZE, TG3_DMA_ALIGNMENT);
+ buf = malloc_phys(TEST_BUFFER_SIZE, TG3_DMA_ALIGNMENT);
if (!buf) {
ret = -ENOMEM;
goto out_nofree;
@@ -708,7 +708,7 @@ static int tg3_test_dma(struct tg3 *tp)
}
out:
- free_dma(buf, TEST_BUFFER_SIZE);
+ free_phys(buf, TEST_BUFFER_SIZE);
out_nofree:
return ret;
}
@@ -771,7 +771,7 @@ static int tg3_init_one(struct pci_device *pdev)
reg_base = pci_bar_start(pdev, PCI_BASE_ADDRESS_0);
reg_size = pci_bar_size(pdev, PCI_BASE_ADDRESS_0);
- tp->regs = ioremap(reg_base, reg_size);
+ tp->regs = pci_ioremap(pdev, reg_base, reg_size);
if (!tp->regs) {
DBGC(&pdev->dev, "Failed to remap device registers\n");
errno = -ENOENT;
diff --git a/src/drivers/net/thunderx.c b/src/drivers/net/thunderx.c
index 9ddb98ab8..1865a9b91 100644
--- a/src/drivers/net/thunderx.c
+++ b/src/drivers/net/thunderx.c
@@ -645,11 +645,11 @@ static void txnic_poll ( struct txnic *vnic ) {
/**
* Allocate virtual NIC
*
- * @v dev Underlying device
+ * @v pci Underlying PCI device
* @v membase Register base address
* @ret vnic Virtual NIC, or NULL on failure
*/
-static struct txnic * txnic_alloc ( struct device *dev,
+static struct txnic * txnic_alloc ( struct pci_device *pci,
unsigned long membase ) {
struct net_device *netdev;
struct txnic *vnic;
@@ -658,10 +658,10 @@ static struct txnic * txnic_alloc ( struct device *dev,
netdev = alloc_etherdev ( sizeof ( *vnic ) );
if ( ! netdev )
goto err_alloc_netdev;
- netdev->dev = dev;
+ netdev->dev = &pci->dev;
vnic = netdev->priv;
vnic->netdev = netdev;
- vnic->name = dev->name;
+ vnic->name = pci->dev.name;
/* Allow caller to reuse netdev->priv. (The generic virtual
* NIC code never assumes that netdev->priv==vnic.)
@@ -684,7 +684,7 @@ static struct txnic * txnic_alloc ( struct device *dev,
goto err_alloc_rq;
/* Map registers */
- vnic->regs = ioremap ( membase, TXNIC_VF_BAR_SIZE );
+ vnic->regs = pci_ioremap ( pci, membase, TXNIC_VF_BAR_SIZE );
if ( ! vnic->regs )
goto err_ioremap;
@@ -1103,7 +1103,7 @@ static int txnic_lmac_probe ( struct txnic_lmac *lmac ) {
membase = ( pf->vf_membase + ( lmac->idx * pf->vf_stride ) );
/* Allocate and initialise network device */
- vnic = txnic_alloc ( &bgx->pci->dev, membase );
+ vnic = txnic_alloc ( bgx->pci, membase );
if ( ! vnic ) {
rc = -ENOMEM;
goto err_alloc;
@@ -1275,7 +1275,7 @@ static int txnic_pf_probe ( struct pci_device *pci ) {
adjust_pci_device ( pci );
/* Map registers */
- pf->regs = ioremap ( membase, TXNIC_PF_BAR_SIZE );
+ pf->regs = pci_ioremap ( pci, membase, TXNIC_PF_BAR_SIZE );
if ( ! pf->regs ) {
rc = -ENODEV;
goto err_ioremap;
@@ -1633,7 +1633,7 @@ static int txnic_bgx_probe ( struct pci_device *pci ) {
adjust_pci_device ( pci );
/* Map registers */
- bgx->regs = ioremap ( membase, TXNIC_BGX_BAR_SIZE );
+ bgx->regs = pci_ioremap ( pci, membase, TXNIC_BGX_BAR_SIZE );
if ( ! bgx->regs ) {
rc = -ENODEV;
goto err_ioremap;
diff --git a/src/drivers/net/velocity.c b/src/drivers/net/velocity.c
index 0a2a3ac10..373714293 100644
--- a/src/drivers/net/velocity.c
+++ b/src/drivers/net/velocity.c
@@ -320,7 +320,8 @@ static int velocity_alloc_rings ( struct velocity_nic *vlc ) {
vlc->rx_prod = 0;
vlc->rx_cons = 0;
vlc->rx_commit = 0;
- vlc->rx_ring = malloc_dma ( VELOCITY_RXDESC_SIZE, VELOCITY_RING_ALIGN );
+ vlc->rx_ring = malloc_phys ( VELOCITY_RXDESC_SIZE,
+ VELOCITY_RING_ALIGN );
if ( ! vlc->rx_ring )
return -ENOMEM;
@@ -332,7 +333,8 @@ static int velocity_alloc_rings ( struct velocity_nic *vlc ) {
/* Allocate TX descriptor ring */
vlc->tx_prod = 0;
vlc->tx_cons = 0;
- vlc->tx_ring = malloc_dma ( VELOCITY_TXDESC_SIZE, VELOCITY_RING_ALIGN );
+ vlc->tx_ring = malloc_phys ( VELOCITY_TXDESC_SIZE,
+ VELOCITY_RING_ALIGN );
if ( ! vlc->tx_ring ) {
rc = -ENOMEM;
goto err_tx_alloc;
@@ -356,7 +358,7 @@ static int velocity_alloc_rings ( struct velocity_nic *vlc ) {
return 0;
err_tx_alloc:
- free_dma ( vlc->rx_ring, VELOCITY_RXDESC_SIZE );
+ free_phys ( vlc->rx_ring, VELOCITY_RXDESC_SIZE );
return rc;
}
@@ -482,7 +484,7 @@ static void velocity_close ( struct net_device *netdev ) {
writew ( 0, vlc->regs + VELOCITY_RXDESCNUM );
/* Destroy RX ring */
- free_dma ( vlc->rx_ring, VELOCITY_RXDESC_SIZE );
+ free_phys ( vlc->rx_ring, VELOCITY_RXDESC_SIZE );
vlc->rx_ring = NULL;
vlc->rx_prod = 0;
vlc->rx_cons = 0;
@@ -499,7 +501,7 @@ static void velocity_close ( struct net_device *netdev ) {
writew ( 0, vlc->regs + VELOCITY_TXDESCNUM );
/* Destroy TX ring */
- free_dma ( vlc->tx_ring, VELOCITY_TXDESC_SIZE );
+ free_phys ( vlc->tx_ring, VELOCITY_TXDESC_SIZE );
vlc->tx_ring = NULL;
vlc->tx_prod = 0;
vlc->tx_cons = 0;
@@ -731,7 +733,7 @@ static int velocity_probe ( struct pci_device *pci ) {
adjust_pci_device ( pci );
/* Map registers */
- vlc->regs = ioremap ( pci->membase, VELOCITY_BAR_SIZE );
+ vlc->regs = pci_ioremap ( pci, pci->membase, VELOCITY_BAR_SIZE );
vlc->netdev = netdev;
/* Reset the NIC */
diff --git a/src/drivers/net/vmxnet3.c b/src/drivers/net/vmxnet3.c
index 6a54dbf89..63bcf0e01 100644
--- a/src/drivers/net/vmxnet3.c
+++ b/src/drivers/net/vmxnet3.c
@@ -465,7 +465,8 @@ static int vmxnet3_open ( struct net_device *netdev ) {
int rc;
/* Allocate DMA areas */
- vmxnet->dma = malloc_dma ( sizeof ( *vmxnet->dma ), VMXNET3_DMA_ALIGN );
+ vmxnet->dma = malloc_phys ( sizeof ( *vmxnet->dma ),
+ VMXNET3_DMA_ALIGN );
if ( ! vmxnet->dma ) {
DBGC ( vmxnet, "VMXNET3 %p could not allocate DMA area\n",
vmxnet );
@@ -542,7 +543,7 @@ static int vmxnet3_open ( struct net_device *netdev ) {
err_activate:
vmxnet3_flush_tx ( netdev );
vmxnet3_flush_rx ( netdev );
- free_dma ( vmxnet->dma, sizeof ( *vmxnet->dma ) );
+ free_phys ( vmxnet->dma, sizeof ( *vmxnet->dma ) );
err_alloc_dma:
return rc;
}
@@ -559,7 +560,7 @@ static void vmxnet3_close ( struct net_device *netdev ) {
vmxnet3_command ( vmxnet, VMXNET3_CMD_RESET_DEV );
vmxnet3_flush_tx ( netdev );
vmxnet3_flush_rx ( netdev );
- free_dma ( vmxnet->dma, sizeof ( *vmxnet->dma ) );
+ free_phys ( vmxnet->dma, sizeof ( *vmxnet->dma ) );
}
/** vmxnet3 net device operations */
@@ -641,14 +642,14 @@ static int vmxnet3_probe ( struct pci_device *pci ) {
adjust_pci_device ( pci );
/* Map PCI BARs */
- vmxnet->pt = ioremap ( pci_bar_start ( pci, VMXNET3_PT_BAR ),
- VMXNET3_PT_LEN );
+ vmxnet->pt = pci_ioremap ( pci, pci_bar_start ( pci, VMXNET3_PT_BAR ),
+ VMXNET3_PT_LEN );
if ( ! vmxnet->pt ) {
rc = -ENODEV;
goto err_ioremap_pt;
}
- vmxnet->vd = ioremap ( pci_bar_start ( pci, VMXNET3_VD_BAR ),
- VMXNET3_VD_LEN );
+ vmxnet->vd = pci_ioremap ( pci, pci_bar_start ( pci, VMXNET3_VD_BAR ),
+ VMXNET3_VD_LEN );
if ( ! vmxnet->vd ) {
rc = -ENODEV;
goto err_ioremap_vd;
diff --git a/src/drivers/net/vxge/vxge_config.c b/src/drivers/net/vxge/vxge_config.c
index ba62b508e..f4d217097 100644
--- a/src/drivers/net/vxge/vxge_config.c
+++ b/src/drivers/net/vxge/vxge_config.c
@@ -624,10 +624,10 @@ __vxge_hw_ring_create(struct __vxge_hw_virtualpath *vpath,
hldev = vpath->hldev;
vp_id = vpath->vp_id;
- ring->rxdl = malloc_dma(sizeof(struct __vxge_hw_ring_block),
+ ring->rxdl = malloc_phys(sizeof(struct __vxge_hw_ring_block),
sizeof(struct __vxge_hw_ring_block));
if (!ring->rxdl) {
- vxge_debug(VXGE_ERR, "%s:%d malloc_dma error\n",
+ vxge_debug(VXGE_ERR, "%s:%d malloc_phys error\n",
__func__, __LINE__);
status = VXGE_HW_ERR_OUT_OF_MEMORY;
goto exit;
@@ -667,7 +667,7 @@ enum vxge_hw_status __vxge_hw_ring_delete(struct __vxge_hw_ring *ring)
}
if (ring->rxdl) {
- free_dma(ring->rxdl, sizeof(struct __vxge_hw_ring_block));
+ free_phys(ring->rxdl, sizeof(struct __vxge_hw_ring_block));
ring->rxdl = NULL;
}
ring->rxd_offset = 0;
@@ -826,10 +826,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_virtualpath *vpath,
fifo->tx_intr_num = (vpath->vp_id * VXGE_HW_MAX_INTR_PER_VP)
+ VXGE_HW_VPATH_INTR_TX;
- fifo->txdl = malloc_dma(sizeof(struct vxge_hw_fifo_txd)
+ fifo->txdl = malloc_phys(sizeof(struct vxge_hw_fifo_txd)
* fifo->depth, fifo->depth);
if (!fifo->txdl) {
- vxge_debug(VXGE_ERR, "%s:%d malloc_dma error\n",
+ vxge_debug(VXGE_ERR, "%s:%d malloc_phys error\n",
__func__, __LINE__);
return VXGE_HW_ERR_OUT_OF_MEMORY;
}
@@ -846,7 +846,7 @@ enum vxge_hw_status __vxge_hw_fifo_delete(struct __vxge_hw_fifo *fifo)
vxge_trace();
if (fifo->txdl)
- free_dma(fifo->txdl,
+ free_phys(fifo->txdl,
sizeof(struct vxge_hw_fifo_txd) * fifo->depth);
fifo->txdl = NULL;
diff --git a/src/drivers/net/vxge/vxge_main.c b/src/drivers/net/vxge/vxge_main.c
index 8b099c0e2..631928318 100644
--- a/src/drivers/net/vxge/vxge_main.c
+++ b/src/drivers/net/vxge/vxge_main.c
@@ -520,7 +520,7 @@ vxge_probe(struct pci_device *pdev)
/* sets the bus master */
adjust_pci_device(pdev);
- bar0 = ioremap(mmio_start, mmio_len);
+ bar0 = pci_ioremap(pdev, mmio_start, mmio_len);
if (!bar0) {
vxge_debug(VXGE_ERR,
"%s : cannot remap io memory bar0\n", __func__);
diff --git a/src/drivers/usb/ehci.c b/src/drivers/usb/ehci.c
index 29c32b356..77022a47d 100644
--- a/src/drivers/usb/ehci.c
+++ b/src/drivers/usb/ehci.c
@@ -565,8 +565,8 @@ static int ehci_ring_alloc ( struct ehci_device *ehci,
}
/* Allocate queue head */
- ring->head = malloc_dma ( sizeof ( *ring->head ),
- ehci_align ( sizeof ( *ring->head ) ) );
+ ring->head = malloc_phys ( sizeof ( *ring->head ),
+ ehci_align ( sizeof ( *ring->head ) ) );
if ( ! ring->head ) {
rc = -ENOMEM;
goto err_alloc_queue;
@@ -579,7 +579,7 @@ static int ehci_ring_alloc ( struct ehci_device *ehci,
/* Allocate transfer descriptors */
len = ( EHCI_RING_COUNT * sizeof ( ring->desc[0] ) );
- ring->desc = malloc_dma ( len, sizeof ( ring->desc[0] ) );
+ ring->desc = malloc_phys ( len, sizeof ( ring->desc[0] ) );
if ( ! ring->desc ) {
rc = -ENOMEM;
goto err_alloc_desc;
@@ -607,10 +607,10 @@ static int ehci_ring_alloc ( struct ehci_device *ehci,
return 0;
err_unreachable_desc:
- free_dma ( ring->desc, len );
+ free_phys ( ring->desc, len );
err_alloc_desc:
err_unreachable_queue:
- free_dma ( ring->head, sizeof ( *ring->head ) );
+ free_phys ( ring->head, sizeof ( *ring->head ) );
err_alloc_queue:
free ( ring->iobuf );
err_alloc_iobuf:
@@ -631,10 +631,11 @@ static void ehci_ring_free ( struct ehci_ring *ring ) {
assert ( ring->iobuf[i] == NULL );
/* Free transfer descriptors */
- free_dma ( ring->desc, ( EHCI_RING_COUNT * sizeof ( ring->desc[0] ) ) );
+ free_phys ( ring->desc, ( EHCI_RING_COUNT *
+ sizeof ( ring->desc[0] ) ) );
/* Free queue head */
- free_dma ( ring->head, sizeof ( *ring->head ) );
+ free_phys ( ring->head, sizeof ( *ring->head ) );
/* Free I/O buffers */
free ( ring->iobuf );
@@ -1787,8 +1788,8 @@ static int ehci_bus_open ( struct usb_bus *bus ) {
assert ( list_empty ( &ehci->periodic ) );
/* Allocate and initialise asynchronous queue head */
- ehci->head = malloc_dma ( sizeof ( *ehci->head ),
- ehci_align ( sizeof ( *ehci->head ) ) );
+ ehci->head = malloc_phys ( sizeof ( *ehci->head ),
+ ehci_align ( sizeof ( *ehci->head ) ) );
if ( ! ehci->head ) {
rc = -ENOMEM;
goto err_alloc_head;
@@ -1816,7 +1817,7 @@ static int ehci_bus_open ( struct usb_bus *bus ) {
/* Allocate periodic frame list */
frames = EHCI_PERIODIC_FRAMES ( ehci->flsize );
len = ( frames * sizeof ( ehci->frame[0] ) );
- ehci->frame = malloc_dma ( len, EHCI_PAGE_ALIGN );
+ ehci->frame = malloc_phys ( len, EHCI_PAGE_ALIGN );
if ( ! ehci->frame ) {
rc = -ENOMEM;
goto err_alloc_frame;
@@ -1836,10 +1837,10 @@ static int ehci_bus_open ( struct usb_bus *bus ) {
ehci_stop ( ehci );
err_unreachable_frame:
- free_dma ( ehci->frame, len );
+ free_phys ( ehci->frame, len );
err_alloc_frame:
err_ctrldssegment:
- free_dma ( ehci->head, sizeof ( *ehci->head ) );
+ free_phys ( ehci->head, sizeof ( *ehci->head ) );
err_alloc_head:
return rc;
}
@@ -1861,10 +1862,10 @@ static void ehci_bus_close ( struct usb_bus *bus ) {
ehci_stop ( ehci );
/* Free periodic frame list */
- free_dma ( ehci->frame, ( frames * sizeof ( ehci->frame[0] ) ) );
+ free_phys ( ehci->frame, ( frames * sizeof ( ehci->frame[0] ) ) );
/* Free asynchronous schedule */
- free_dma ( ehci->head, sizeof ( *ehci->head ) );
+ free_phys ( ehci->head, sizeof ( *ehci->head ) );
}
/**
@@ -1989,7 +1990,7 @@ static int ehci_probe ( struct pci_device *pci ) {
/* Map registers */
bar_start = pci_bar_start ( pci, EHCI_BAR );
bar_size = pci_bar_size ( pci, EHCI_BAR );
- ehci->regs = ioremap ( bar_start, bar_size );
+ ehci->regs = pci_ioremap ( pci, bar_start, bar_size );
if ( ! ehci->regs ) {
rc = -ENODEV;
goto err_ioremap;
diff --git a/src/drivers/usb/uhci.c b/src/drivers/usb/uhci.c
index ce2962d36..47474bdc7 100644
--- a/src/drivers/usb/uhci.c
+++ b/src/drivers/usb/uhci.c
@@ -179,7 +179,7 @@ static int uhci_ring_alloc ( struct uhci_ring *ring ) {
memset ( ring, 0, sizeof ( *ring ) );
/* Allocate queue head */
- ring->head = malloc_dma ( sizeof ( *ring->head ), UHCI_ALIGN );
+ ring->head = malloc_phys ( sizeof ( *ring->head ), UHCI_ALIGN );
if ( ! ring->head ) {
rc = -ENOMEM;
goto err_alloc;
@@ -194,7 +194,7 @@ static int uhci_ring_alloc ( struct uhci_ring *ring ) {
return 0;
err_unreachable:
- free_dma ( ring->head, sizeof ( *ring->head ) );
+ free_phys ( ring->head, sizeof ( *ring->head ) );
err_alloc:
return rc;
}
@@ -213,7 +213,7 @@ static void uhci_ring_free ( struct uhci_ring *ring ) {
assert ( ring->xfer[i] == NULL );
/* Free queue head */
- free_dma ( ring->head, sizeof ( *ring->head ) );
+ free_phys ( ring->head, sizeof ( *ring->head ) );
}
/**
@@ -263,7 +263,7 @@ static int uhci_enqueue ( struct uhci_ring *ring, struct io_buffer *iobuf,
/* Allocate transfer descriptors */
len = ( count * sizeof ( xfer->desc[0] ) );
- xfer->desc = malloc_dma ( len, UHCI_ALIGN );
+ xfer->desc = malloc_phys ( len, UHCI_ALIGN );
if ( ! xfer->desc ) {
rc = -ENOMEM;
goto err_alloc_desc;
@@ -299,7 +299,7 @@ static int uhci_enqueue ( struct uhci_ring *ring, struct io_buffer *iobuf,
return 0;
err_unreachable_desc:
- free_dma ( xfer->desc, len );
+ free_phys ( xfer->desc, len );
err_alloc_desc:
free ( xfer );
err_alloc_xfer:
@@ -377,7 +377,7 @@ static struct io_buffer * uhci_dequeue ( struct uhci_ring *ring ) {
/* Free transfer descriptors */
len = ( xfer->prod * sizeof ( xfer->desc[0] ) );
- free_dma ( xfer->desc, len );
+ free_phys ( xfer->desc, len );
/* Free transfer */
free ( xfer );
@@ -1312,7 +1312,7 @@ static int uhci_bus_open ( struct usb_bus *bus ) {
assert ( list_empty ( &uhci->periodic ) );
/* Allocate and initialise asynchronous queue head */
- uhci->head = malloc_dma ( sizeof ( *uhci->head ), UHCI_ALIGN );
+ uhci->head = malloc_phys ( sizeof ( *uhci->head ), UHCI_ALIGN );
if ( ! uhci->head ) {
rc = -ENOMEM;
goto err_alloc_head;
@@ -1324,8 +1324,8 @@ static int uhci_bus_open ( struct usb_bus *bus ) {
uhci_async_schedule ( uhci );
/* Allocate periodic frame list */
- uhci->frame = malloc_dma ( sizeof ( *uhci->frame ),
- sizeof ( *uhci->frame ) );
+ uhci->frame = malloc_phys ( sizeof ( *uhci->frame ),
+ sizeof ( *uhci->frame ) );
if ( ! uhci->frame ) {
rc = -ENOMEM;
goto err_alloc_frame;
@@ -1343,10 +1343,10 @@ static int uhci_bus_open ( struct usb_bus *bus ) {
uhci_stop ( uhci );
err_unreachable_frame:
- free_dma ( uhci->frame, sizeof ( *uhci->frame ) );
+ free_phys ( uhci->frame, sizeof ( *uhci->frame ) );
err_alloc_frame:
err_unreachable_head:
- free_dma ( uhci->head, sizeof ( *uhci->head ) );
+ free_phys ( uhci->head, sizeof ( *uhci->head ) );
err_alloc_head:
return rc;
}
@@ -1367,10 +1367,10 @@ static void uhci_bus_close ( struct usb_bus *bus ) {
uhci_stop ( uhci );
/* Free periodic frame list */
- free_dma ( uhci->frame, sizeof ( *uhci->frame ) );
+ free_phys ( uhci->frame, sizeof ( *uhci->frame ) );
/* Free asynchronous schedule */
- free_dma ( uhci->head, sizeof ( *uhci->head ) );
+ free_phys ( uhci->head, sizeof ( *uhci->head ) );
}
/**
diff --git a/src/drivers/usb/usbblk.c b/src/drivers/usb/usbblk.c
new file mode 100644
index 000000000..5a086d3f8
--- /dev/null
+++ b/src/drivers/usb/usbblk.c
@@ -0,0 +1,912 @@
+/*
+ * Copyright (C) 2020 Michael Brown <mbrown@fensystems.co.uk>.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <ipxe/usb.h>
+#include <ipxe/scsi.h>
+#include <ipxe/xfer.h>
+#include <ipxe/uri.h>
+#include <ipxe/open.h>
+#include <ipxe/efi/efi_path.h>
+#include "usbblk.h"
+
+/** @file
+ *
+ * USB mass storage driver
+ *
+ */
+
+static void usbblk_stop ( struct usbblk_device *usbblk, int rc );
+
+/** List of USB block devices */
+static LIST_HEAD ( usbblk_devices );
+
+/******************************************************************************
+ *
+ * Endpoint management
+ *
+ ******************************************************************************
+ */
+
+/**
+ * Open endpoints
+ *
+ * @v usbblk USB block device
+ * @ret rc Return status code
+ */
+static int usbblk_open ( struct usbblk_device *usbblk ) {
+ struct usb_device *usb = usbblk->func->usb;
+ unsigned int interface = usbblk->func->interface[0];
+ int rc;
+
+ /* Sanity checks */
+ assert ( ! usbblk->in.open );
+ assert ( ! usbblk->out.open );
+
+ /* Issue reset */
+ if ( ( rc = usb_control ( usb, USBBLK_RESET, 0, interface,
+ NULL, 0 ) ) != 0 ) {
+ DBGC ( usbblk, "USBBLK %s could not issue reset: %s\n",
+ usbblk->func->name, strerror ( rc ) );
+ goto err_reset;
+ }
+
+ /* Open bulk OUT endpoint */
+ if ( ( rc = usb_endpoint_open ( &usbblk->out ) ) != 0 ) {
+ DBGC ( usbblk, "USBBLK %s could not open bulk OUT: %s\n",
+ usbblk->func->name, strerror ( rc ) );
+ goto err_open_out;
+ }
+
+ /* Clear any bulk OUT halt condition */
+ if ( ( rc = usb_endpoint_clear_halt ( &usbblk->out ) ) != 0 ) {
+ DBGC ( usbblk, "USBBLK %s could not reset bulk OUT: %s\n",
+ usbblk->func->name, strerror ( rc ) );
+ goto err_clear_out;
+ }
+
+ /* Open bulk IN endpoint */
+ if ( ( rc = usb_endpoint_open ( &usbblk->in ) ) != 0 ) {
+ DBGC ( usbblk, "USBBLK %s could not open bulk IN: %s\n",
+ usbblk->func->name, strerror ( rc ) );
+ goto err_open_in;
+ }
+
+ /* Clear any bulk IN halt condition */
+ if ( ( rc = usb_endpoint_clear_halt ( &usbblk->in ) ) != 0 ) {
+ DBGC ( usbblk, "USBBLK %s could not reset bulk IN: %s\n",
+ usbblk->func->name, strerror ( rc ) );
+ goto err_clear_in;
+ }
+
+ return 0;
+
+ err_clear_in:
+ usb_endpoint_close ( &usbblk->in );
+ err_open_in:
+ err_clear_out:
+ usb_endpoint_close ( &usbblk->out );
+ err_open_out:
+ err_reset:
+ return rc;
+}
+
+/**
+ * Close endpoints
+ *
+ * @v usbblk USB block device
+ */
+static void usbblk_close ( struct usbblk_device *usbblk ) {
+
+ /* Close bulk OUT endpoint */
+ if ( usbblk->out.open )
+ usb_endpoint_close ( &usbblk->out );
+
+ /* Close bulk IN endpoint */
+ if ( usbblk->in.open )
+ usb_endpoint_close ( &usbblk->in );
+}
+
+/******************************************************************************
+ *
+ * Bulk OUT endpoint
+ *
+ ******************************************************************************
+ */
+
+/**
+ * Issue bulk OUT command
+ *
+ * @v usbblk USB block device
+ * @ret rc Return status code
+ */
+static int usbblk_out_command ( struct usbblk_device *usbblk ) {
+ struct usbblk_command *cmd = &usbblk->cmd;
+ struct usbblk_command_wrapper *wrapper;
+ struct io_buffer *iobuf;
+ int rc;
+
+ /* Sanity checks */
+ assert ( cmd->tag );
+ assert ( ! ( cmd->scsi.data_in_len && cmd->scsi.data_out_len ) );
+
+ /* Allocate I/O buffer */
+ iobuf = alloc_iob ( sizeof ( *wrapper ) );
+ if ( ! iobuf ) {
+ rc = -ENOMEM;
+ goto err_alloc;
+ }
+
+ /* Populate command */
+ wrapper = iob_put ( iobuf, sizeof ( *wrapper ) );
+ memset ( wrapper, 0, sizeof ( *wrapper ) );
+ wrapper->signature = cpu_to_le32 ( USBBLK_COMMAND_SIGNATURE );
+ wrapper->tag = cmd->tag; /* non-endian */
+ if ( cmd->scsi.data_out_len ) {
+ wrapper->len = cpu_to_le32 ( cmd->scsi.data_out_len );
+ } else {
+ wrapper->len = cpu_to_le32 ( cmd->scsi.data_in_len );
+ wrapper->flags = USB_DIR_IN;
+ }
+ wrapper->lun = ntohs ( cmd->scsi.lun.u16[0] );
+ wrapper->cblen = sizeof ( wrapper->cb );
+ memcpy ( wrapper->cb, &cmd->scsi.cdb, sizeof ( wrapper->cb ) );
+
+ /* Issue command */
+ if ( ( rc = usb_stream ( &usbblk->out, iobuf, 0 ) ) != 0 ) {
+ DBGC ( usbblk, "USBBLK %s bulk OUT could not issue command: "
+ "%s\n", usbblk->func->name, strerror ( rc ) );
+ goto err_stream;
+ }
+
+ return 0;
+
+ err_stream:
+ free_iob ( iobuf );
+ err_alloc:
+ return rc;
+}
+
+/**
+ * Send bulk OUT data block
+ *
+ * @v usbblk USB block device
+ * @ret rc Return status code
+ */
+static int usbblk_out_data ( struct usbblk_device *usbblk ) {
+ struct usbblk_command *cmd = &usbblk->cmd;
+ struct io_buffer *iobuf;
+ size_t len;
+ int rc;
+
+ /* Calculate length */
+ assert ( cmd->tag );
+ assert ( cmd->scsi.data_out != UNULL );
+ assert ( cmd->offset < cmd->scsi.data_out_len );
+ len = ( cmd->scsi.data_out_len - cmd->offset );
+ if ( len > USBBLK_MAX_LEN )
+ len = USBBLK_MAX_LEN;
+ assert ( ( len % usbblk->out.mtu ) == 0 );
+
+ /* Allocate I/O buffer */
+ iobuf = alloc_iob ( len );
+ if ( ! iobuf ) {
+ rc = -ENOMEM;
+ goto err_alloc;
+ }
+
+ /* Populate I/O buffer */
+ copy_from_user ( iob_put ( iobuf, len ), cmd->scsi.data_out,
+ cmd->offset, len );
+
+ /* Send data */
+ if ( ( rc = usb_stream ( &usbblk->out, iobuf, 0 ) ) != 0 ) {
+ DBGC ( usbblk, "USBBLK %s bulk OUT could not send data: %s\n",
+ usbblk->func->name, strerror ( rc ) );
+ goto err_stream;
+ }
+
+ /* Consume data */
+ cmd->offset += len;
+
+ return 0;
+
+ err_stream:
+ free_iob ( iobuf );
+ err_alloc:
+ return rc;
+}
+
+/**
+ * Refill bulk OUT endpoint
+ *
+ * @v usbblk USB block device
+ * @ret rc Return status code
+ */
+static int usbblk_out_refill ( struct usbblk_device *usbblk ) {
+ struct usbblk_command *cmd = &usbblk->cmd;
+ int rc;
+
+ /* Sanity checks */
+ assert ( cmd->tag );
+
+ /* Refill endpoint */
+ while ( ( cmd->offset < cmd->scsi.data_out_len ) &&
+ ( usbblk->out.fill < USBBLK_MAX_FILL ) ) {
+ if ( ( rc = usbblk_out_data ( usbblk ) ) != 0 )
+ return rc;
+ }
+
+ return 0;
+}
+
+/**
+ * Complete bulk OUT transfer
+ *
+ * @v ep USB endpoint
+ * @v iobuf I/O buffer
+ * @v rc Completion status code
+ */
+static void usbblk_out_complete ( struct usb_endpoint *ep,
+ struct io_buffer *iobuf, int rc ) {
+ struct usbblk_device *usbblk =
+ container_of ( ep, struct usbblk_device, out );
+ struct usbblk_command *cmd = &usbblk->cmd;
+
+ /* Ignore cancellations after closing endpoint */
+ if ( ! ep->open )
+ goto drop;
+
+ /* Sanity check */
+ assert ( cmd->tag );
+
+ /* Check for failures */
+ if ( rc != 0 ) {
+ DBGC ( usbblk, "USBBLK %s bulk OUT failed: %s\n",
+ usbblk->func->name, strerror ( rc ) );
+ goto err;
+ }
+
+ /* Trigger refill process, if applicable */
+ if ( cmd->offset < cmd->scsi.data_out_len )
+ process_add ( &usbblk->process );
+
+ drop:
+ /* Free I/O buffer */
+ free_iob ( iobuf );
+
+ return;
+
+ err:
+ free_iob ( iobuf );
+ usbblk_stop ( usbblk, rc );
+}
+
+/** Bulk OUT endpoint operations */
+static struct usb_endpoint_driver_operations usbblk_out_operations = {
+ .complete = usbblk_out_complete,
+};
+
+/******************************************************************************
+ *
+ * Bulk IN endpoint
+ *
+ ******************************************************************************
+ */
+
+/**
+ * Handle bulk IN data block
+ *
+ * @v usbblk USB block device
+ * @v data Data block
+ * @v len Length of data
+ * @ret rc Return status code
+ */
+static int usbblk_in_data ( struct usbblk_device *usbblk, const void *data,
+ size_t len ) {
+ struct usbblk_command *cmd = &usbblk->cmd;
+
+ /* Sanity checks */
+ assert ( cmd->tag );
+ assert ( cmd->scsi.data_in != UNULL );
+ assert ( cmd->offset <= cmd->scsi.data_in_len );
+ assert ( len <= ( cmd->scsi.data_in_len - cmd->offset ) );
+
+ /* Store data */
+ copy_to_user ( cmd->scsi.data_in, cmd->offset, data, len );
+ cmd->offset += len;
+
+ return 0;
+}
+
+/**
+ * Handle bulk IN status
+ *
+ * @v usbblk USB block device
+ * @v data Status data
+ * @v len Length of status data
+ * @ret rc Return status code
+ */
+static int usbblk_in_status ( struct usbblk_device *usbblk, const void *data,
+ size_t len ) {
+ struct usbblk_command *cmd = &usbblk->cmd;
+ const struct usbblk_status_wrapper *stat;
+
+ /* Sanity checks */
+ assert ( cmd->tag );
+
+ /* Validate length */
+ if ( len < sizeof ( *stat ) ) {
+ DBGC ( usbblk, "USBBLK %s bulk IN malformed status:\n",
+ usbblk->func->name );
+ DBGC_HDA ( usbblk, 0, data, len );
+ return -EIO;
+ }
+ stat = data;
+
+ /* Validate signature */
+ if ( stat->signature != cpu_to_le32 ( USBBLK_STATUS_SIGNATURE ) ) {
+ DBGC ( usbblk, "USBBLK %s bulk IN invalid signature %08x:\n",
+ usbblk->func->name, le32_to_cpu ( stat->signature ) );
+ DBGC_HDA ( usbblk, 0, stat, sizeof ( *stat ) );
+ return -EIO;
+ }
+
+ /* Validate tag */
+ if ( stat->tag != cmd->tag ) {
+ DBGC ( usbblk, "USBBLK %s bulk IN tag mismatch (got %08x, "
+ "expected %08x):\n",
+ usbblk->func->name, stat->tag, cmd->tag );
+ DBGC_HDA ( usbblk, 0, stat, sizeof ( *stat ) );
+ return -EIO;
+ }
+
+ /* Check status */
+ if ( stat->status ) {
+ DBGC ( usbblk, "USBBLK %s bulk IN status %02x:\n",
+ usbblk->func->name, stat->status );
+ DBGC_HDA ( usbblk, 0, stat, sizeof ( *stat ) );
+ return -EIO;
+ }
+
+ /* Check for residual data */
+ if ( stat->residue ) {
+ DBGC ( usbblk, "USBBLK %s bulk IN residue %#x:\n",
+ usbblk->func->name, le32_to_cpu ( stat->residue ) );
+ return -EIO;
+ }
+
+ /* Mark command as complete */
+ usbblk_stop ( usbblk, 0 );
+
+ return 0;
+}
+
+/**
+ * Refill bulk IN endpoint
+ *
+ * @v usbblk USB block device
+ * @ret rc Return status code
+ */
+static int usbblk_in_refill ( struct usbblk_device *usbblk ) {
+ struct usbblk_command *cmd = &usbblk->cmd;
+ struct usbblk_status_wrapper *stat;
+ size_t remaining;
+ unsigned int max;
+ int rc;
+
+ /* Sanity checks */
+ assert ( cmd->tag );
+
+ /* Calculate maximum required refill */
+ remaining = sizeof ( *stat );
+ if ( cmd->scsi.data_in_len ) {
+ assert ( cmd->offset <= cmd->scsi.data_in_len );
+ remaining += ( cmd->scsi.data_in_len - cmd->offset );
+ }
+ max = ( ( remaining + USBBLK_MAX_LEN - 1 ) / USBBLK_MAX_LEN );
+
+ /* Refill bulk IN endpoint */
+ if ( ( rc = usb_refill_limit ( &usbblk->in, max ) ) != 0 )
+ return rc;
+
+ return 0;
+}
+
+/**
+ * Complete bulk IN transfer
+ *
+ * @v ep USB endpoint
+ * @v iobuf I/O buffer
+ * @v rc Completion status code
+ */
+static void usbblk_in_complete ( struct usb_endpoint *ep,
+ struct io_buffer *iobuf, int rc ) {
+ struct usbblk_device *usbblk =
+ container_of ( ep, struct usbblk_device, in );
+ struct usbblk_command *cmd = &usbblk->cmd;
+ size_t remaining;
+ size_t len;
+
+ /* Ignore cancellations after closing endpoint */
+ if ( ! ep->open )
+ goto drop;
+
+ /* Sanity check */
+ assert ( cmd->tag );
+
+ /* Handle errors */
+ if ( rc != 0 ) {
+ DBGC ( usbblk, "USBBLK %s bulk IN failed: %s\n",
+ usbblk->func->name, strerror ( rc ) );
+ goto err;
+ }
+
+ /* Trigger refill process */
+ process_add ( &usbblk->process );
+
+ /* Handle data portion, if any */
+ if ( cmd->scsi.data_in_len ) {
+ assert ( cmd->offset <= cmd->scsi.data_in_len );
+ remaining = ( cmd->scsi.data_in_len - cmd->offset );
+ len = iob_len ( iobuf );
+ if ( len > remaining )
+ len = remaining;
+ if ( len ) {
+ if ( ( rc = usbblk_in_data ( usbblk, iobuf->data,
+ len ) ) != 0 )
+ goto err;
+ iob_pull ( iobuf, len );
+ }
+ }
+
+ /* Handle status portion, if any */
+ len = iob_len ( iobuf );
+ if ( len ) {
+ if ( ( rc = usbblk_in_status ( usbblk, iobuf->data,
+ len ) ) != 0 )
+ goto err;
+ }
+
+ drop:
+ /* Free I/O buffer */
+ free_iob ( iobuf );
+
+ return;
+
+ err:
+ free_iob ( iobuf );
+ usbblk_stop ( usbblk, rc );
+}
+
+/** Bulk IN endpoint operations */
+static struct usb_endpoint_driver_operations usbblk_in_operations = {
+ .complete = usbblk_in_complete,
+};
+
+/******************************************************************************
+ *
+ * Refill process
+ *
+ ******************************************************************************
+ */
+
+/**
+ * Refill endpoints
+ *
+ * @v usbblk USB block device
+ */
+static void usbblk_step ( struct usbblk_device *usbblk ) {
+
+ /* Refill bulk OUT endpoint */
+ usbblk_out_refill ( usbblk );
+
+ /* Refill bulk IN endpoint */
+ usbblk_in_refill ( usbblk );
+}
+
+/** Refill process descriptor */
+static struct process_descriptor usbblk_process_desc =
+ PROC_DESC ( struct usbblk_device, process, usbblk_step );
+
+/******************************************************************************
+ *
+ * SCSI command management
+ *
+ ******************************************************************************
+ */
+
+/** Next command tag */
+static uint16_t usbblk_tag;
+
+/**
+ * Stop SCSI command
+ *
+ * @v usbblk USB block device
+ * @v rc Reason for stop
+ */
+static void usbblk_stop ( struct usbblk_device *usbblk, int rc ) {
+
+ /* Stop process */
+ process_del ( &usbblk->process );
+
+ /* Reset command */
+ memset ( &usbblk->cmd, 0, sizeof ( usbblk->cmd ) );
+
+ /* Close endpoints if an error occurred */
+ if ( rc != 0 ) {
+ DBGC ( usbblk, "USBBLK %s closing for error recovery\n",
+ usbblk->func->name );
+ usbblk_close ( usbblk );
+ }
+
+ /* Terminate command */
+ intf_restart ( &usbblk->data, rc );
+}
+
+/**
+ * Start new SCSI command
+ *
+ * @v usbblk USB block device
+ * @v scsicmd SCSI command
+ * @ret rc Return status code
+ */
+static int usbblk_start ( struct usbblk_device *usbblk,
+ struct scsi_cmd *scsicmd ) {
+ struct usbblk_command *cmd = &usbblk->cmd;
+ int rc;
+
+ /* Fail if command is in progress */
+ if ( cmd->tag ) {
+ rc = -EBUSY;
+ DBGC ( usbblk, "USBBLK %s cannot support multiple commands\n",
+ usbblk->func->name );
+ goto err_busy;
+ }
+
+ /* Refuse bidirectional commands */
+ if ( scsicmd->data_in_len && scsicmd->data_out_len ) {
+ rc = -EOPNOTSUPP;
+ DBGC ( usbblk, "USBBLK %s cannot support bidirectional "
+ "commands\n", usbblk->func->name );
+ goto err_bidirectional;
+ }
+
+ /* Sanity checks */
+ assert ( ! process_running ( &usbblk->process ) );
+ assert ( cmd->offset == 0 );
+
+ /* Initialise command */
+ memcpy ( &cmd->scsi, scsicmd, sizeof ( cmd->scsi ) );
+ cmd->tag = ( USBBLK_TAG_MAGIC | ++usbblk_tag );
+
+ /* Issue bulk OUT command */
+ if ( ( rc = usbblk_out_command ( usbblk ) ) != 0 )
+ goto err_command;
+
+ /* Start refill process */
+ process_add ( &usbblk->process );
+
+ return 0;
+
+ err_command:
+ memset ( &usbblk->cmd, 0, sizeof ( usbblk->cmd ) );
+ err_bidirectional:
+ err_busy:
+ return rc;
+}
+
+/******************************************************************************
+ *
+ * SCSI interfaces
+ *
+ ******************************************************************************
+ */
+
+/** SCSI data interface operations */
+static struct interface_operation usbblk_data_operations[] = {
+ INTF_OP ( intf_close, struct usbblk_device *, usbblk_stop ),
+};
+
+/** SCSI data interface descriptor */
+static struct interface_descriptor usbblk_data_desc =
+ INTF_DESC ( struct usbblk_device, data, usbblk_data_operations );
+
+/**
+ * Check SCSI command flow-control window
+ *
+ * @v usbblk USB block device
+ * @ret len Length of window
+ */
+static size_t usbblk_scsi_window ( struct usbblk_device *usbblk ) {
+ struct usbblk_command *cmd = &usbblk->cmd;
+
+ /* Allow a single command if no command is currently in progress */
+ return ( cmd->tag ? 0 : 1 );
+}
+
+/**
+ * Issue SCSI command
+ *
+ * @v usbblk USB block device
+ * @v data SCSI data interface
+ * @v scsicmd SCSI command
+ * @ret tag Command tag, or negative error
+ */
+static int usbblk_scsi_command ( struct usbblk_device *usbblk,
+ struct interface *data,
+ struct scsi_cmd *scsicmd ) {
+ struct usbblk_command *cmd = &usbblk->cmd;
+ int rc;
+
+ /* (Re)open endpoints if needed */
+ if ( ( ! usbblk->in.open ) && ( ( rc = usbblk_open ( usbblk ) ) != 0 ) )
+ goto err_open;
+
+ /* Start new command */
+ if ( ( rc = usbblk_start ( usbblk, scsicmd ) ) != 0 )
+ goto err_start;
+
+ /* Attach to parent interface and return */
+ intf_plug_plug ( &usbblk->data, data );
+ return cmd->tag;
+
+ usbblk_stop ( usbblk, rc );
+ err_start:
+ usbblk_close ( usbblk );
+ err_open:
+ return rc;
+}
+
+/**
+ * Close SCSI interface
+ *
+ * @v usbblk USB block device
+ * @v rc Reason for close
+ */
+static void usbblk_scsi_close ( struct usbblk_device *usbblk, int rc ) {
+
+ /* Restart interfaces */
+ intfs_restart ( rc, &usbblk->scsi, &usbblk->data, NULL );
+
+ /* Stop any in-progress command */
+ usbblk_stop ( usbblk, rc );
+
+ /* Close endpoints */
+ usbblk_close ( usbblk );
+
+ /* Flag as closed */
+ usbblk->opened = 0;
+}
+
+/**
+ * Describe as an EFI device path
+ *
+ * @v usbblk USB block device
+ * @ret path EFI device path, or NULL on error
+ */
+static EFI_DEVICE_PATH_PROTOCOL *
+usbblk_efi_describe ( struct usbblk_device *usbblk ) {
+
+ return efi_usb_path ( usbblk->func );
+}
+
+/** SCSI command interface operations */
+static struct interface_operation usbblk_scsi_operations[] = {
+ INTF_OP ( scsi_command, struct usbblk_device *, usbblk_scsi_command ),
+ INTF_OP ( xfer_window, struct usbblk_device *, usbblk_scsi_window ),
+ INTF_OP ( intf_close, struct usbblk_device *, usbblk_scsi_close ),
+ EFI_INTF_OP ( efi_describe, struct usbblk_device *,
+ usbblk_efi_describe ),
+};
+
+/** SCSI command interface descriptor */
+static struct interface_descriptor usbblk_scsi_desc =
+ INTF_DESC ( struct usbblk_device, scsi, usbblk_scsi_operations );
+
+/******************************************************************************
+ *
+ * SAN device interface
+ *
+ ******************************************************************************
+ */
+
+/**
+ * Find USB block device
+ *
+ * @v name USB block device name
+ * @ret usbblk USB block device, or NULL
+ */
+static struct usbblk_device * usbblk_find ( const char *name ) {
+ struct usbblk_device *usbblk;
+
+ /* Look for matching device */
+ list_for_each_entry ( usbblk, &usbblk_devices, list ) {
+ if ( strcmp ( usbblk->func->name, name ) == 0 )
+ return usbblk;
+ }
+
+ return NULL;
+}
+
+/**
+ * Open USB block device URI
+ *
+ * @v parent Parent interface
+ * @v uri URI
+ * @ret rc Return status code
+ */
+static int usbblk_open_uri ( struct interface *parent, struct uri *uri ) {
+ static struct scsi_lun lun;
+ struct usbblk_device *usbblk;
+ int rc;
+
+ /* Sanity check */
+ if ( ! uri->opaque )
+ return -EINVAL;
+
+ /* Find matching device */
+ usbblk = usbblk_find ( uri->opaque );
+ if ( ! usbblk )
+ return -ENOENT;
+
+ /* Fail if device is already open */
+ if ( usbblk->opened )
+ return -EBUSY;
+
+ /* Open SCSI device */
+ if ( ( rc = scsi_open ( parent, &usbblk->scsi, &lun ) ) != 0 ) {
+ DBGC ( usbblk, "USBBLK %s could not open SCSI device: %s\n",
+ usbblk->func->name, strerror ( rc ) );
+ return rc;
+ }
+
+ /* Mark as opened */
+ usbblk->opened = 1;
+
+ return 0;
+}
+
+/** USB block device URI opener */
+struct uri_opener usbblk_uri_opener __uri_opener = {
+ .scheme = "usb",
+ .open = usbblk_open_uri,
+};
+
+/******************************************************************************
+ *
+ * USB interface
+ *
+ ******************************************************************************
+ */
+
+/**
+ * Probe device
+ *
+ * @v func USB function
+ * @v config Configuration descriptor
+ * @ret rc Return status code
+ */
+static int usbblk_probe ( struct usb_function *func,
+ struct usb_configuration_descriptor *config ) {
+ struct usb_device *usb = func->usb;
+ struct usbblk_device *usbblk;
+ struct usb_interface_descriptor *desc;
+ int rc;
+
+ /* Allocate and initialise structure */
+ usbblk = zalloc ( sizeof ( *usbblk ) );
+ if ( ! usbblk ) {
+ rc = -ENOMEM;
+ goto err_alloc;
+ }
+ usbblk->func = func;
+ usb_endpoint_init ( &usbblk->out, usb, &usbblk_out_operations );
+ usb_endpoint_init ( &usbblk->in, usb, &usbblk_in_operations );
+ usb_refill_init ( &usbblk->in, 0, USBBLK_MAX_LEN, USBBLK_MAX_FILL );
+ intf_init ( &usbblk->scsi, &usbblk_scsi_desc, &usbblk->refcnt );
+ intf_init ( &usbblk->data, &usbblk_data_desc, &usbblk->refcnt );
+ process_init_stopped ( &usbblk->process, &usbblk_process_desc,
+ &usbblk->refcnt );
+
+ /* Locate interface descriptor */
+ desc = usb_interface_descriptor ( config, func->interface[0], 0 );
+ if ( ! desc ) {
+ DBGC ( usbblk, "USBBLK %s missing interface descriptor\n",
+ usbblk->func->name );
+ rc = -ENOENT;
+ goto err_desc;
+ }
+
+ /* Describe endpoints */
+ if ( ( rc = usb_endpoint_described ( &usbblk->out, config, desc,
+ USB_BULK_OUT, 0 ) ) != 0 ) {
+ DBGC ( usbblk, "USBBLK %s could not describe bulk OUT: %s\n",
+ usbblk->func->name, strerror ( rc ) );
+ goto err_out;
+ }
+ if ( ( rc = usb_endpoint_described ( &usbblk->in, config, desc,
+ USB_BULK_IN, 0 ) ) != 0 ) {
+ DBGC ( usbblk, "USBBLK %s could not describe bulk IN: %s\n",
+ usbblk->func->name, strerror ( rc ) );
+ goto err_in;
+ }
+
+ /* Add to list of devices */
+ list_add_tail ( &usbblk->list, &usbblk_devices );
+
+ usb_func_set_drvdata ( func, usbblk );
+ return 0;
+
+ err_in:
+ err_out:
+ err_desc:
+ ref_put ( &usbblk->refcnt );
+ err_alloc:
+ return rc;
+}
+
+/**
+ * Remove device
+ *
+ * @v func USB function
+ */
+static void usbblk_remove ( struct usb_function *func ) {
+ struct usbblk_device *usbblk = usb_func_get_drvdata ( func );
+
+ /* Remove from list of devices */
+ list_del ( &usbblk->list );
+
+ /* Close all interfaces */
+ usbblk_scsi_close ( usbblk, -ENODEV );
+
+ /* Shut down interfaces */
+ intfs_shutdown ( -ENODEV, &usbblk->scsi, &usbblk->data, NULL );
+
+ /* Drop reference */
+ ref_put ( &usbblk->refcnt );
+}
+
+/** Mass storage class device IDs */
+static struct usb_device_id usbblk_ids[] = {
+ {
+ .name = "usbblk",
+ .vendor = USB_ANY_ID,
+ .product = USB_ANY_ID,
+ },
+};
+
+/** Mass storage driver */
+struct usb_driver usbblk_driver __usb_driver = {
+ .ids = usbblk_ids,
+ .id_count = ( sizeof ( usbblk_ids ) / sizeof ( usbblk_ids[0] ) ),
+ .class = USB_CLASS_ID ( USB_CLASS_MSC, USB_SUBCLASS_MSC_SCSI,
+ USB_PROTOCOL_MSC_BULK ),
+ .score = USB_SCORE_NORMAL,
+ .probe = usbblk_probe,
+ .remove = usbblk_remove,
+};
diff --git a/src/drivers/usb/usbblk.h b/src/drivers/usb/usbblk.h
new file mode 100644
index 000000000..65d0705e3
--- /dev/null
+++ b/src/drivers/usb/usbblk.h
@@ -0,0 +1,121 @@
+#ifndef _USBBLK_H
+#define _USBBLK_H
+
+/** @file
+ *
+ * USB mass storage driver
+ *
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+
+#include <stdint.h>
+#include <ipxe/usb.h>
+#include <ipxe/scsi.h>
+#include <ipxe/interface.h>
+
+/** Mass storage class code */
+#define USB_CLASS_MSC 0x08
+
+/** SCSI command set subclass code */
+#define USB_SUBCLASS_MSC_SCSI 0x06
+
+/** Bulk-only transport protocol */
+#define USB_PROTOCOL_MSC_BULK 0x50
+
+/** Mass storage reset command */
+#define USBBLK_RESET ( USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE | \
+ USB_REQUEST_TYPE ( 255 ) )
+
+/** Command block wrapper */
+struct usbblk_command_wrapper {
+ /** Signature */
+ uint32_t signature;
+ /** Tag */
+ uint32_t tag;
+ /** Data transfer length */
+ uint32_t len;
+ /** Flags */
+ uint8_t flags;
+ /** LUN */
+ uint8_t lun;
+ /** Command block length */
+ uint8_t cblen;
+ /** Command block */
+ uint8_t cb[16];
+} __attribute__ (( packed ));
+
+/** Command block wrapper signature */
+#define USBBLK_COMMAND_SIGNATURE 0x43425355UL
+
+/** Command status wrapper */
+struct usbblk_status_wrapper {
+ /** Signature */
+ uint32_t signature;
+ /** Tag */
+ uint32_t tag;
+ /** Data residue */
+ uint32_t residue;
+ /** Status */
+ uint8_t status;
+} __attribute__ (( packed ));
+
+/** Command status wrapper signature */
+#define USBBLK_STATUS_SIGNATURE 0x53425355UL
+
+/** A USB mass storage command */
+struct usbblk_command {
+ /** SCSI command */
+ struct scsi_cmd scsi;
+ /** Command tag (0 for no command in progress) */
+ uint32_t tag;
+ /** Offset within data buffer */
+ size_t offset;
+};
+
+/** A USB mass storage device */
+struct usbblk_device {
+ /** Reference count */
+ struct refcnt refcnt;
+ /** List of devices */
+ struct list_head list;
+
+ /** USB function */
+ struct usb_function *func;
+ /** Bulk OUT endpoint */
+ struct usb_endpoint out;
+ /** Bulk IN endpoint */
+ struct usb_endpoint in;
+
+ /** SCSI command-issuing interface */
+ struct interface scsi;
+ /** SCSI data interface */
+ struct interface data;
+ /** Command process */
+ struct process process;
+ /** Device opened flag */
+ int opened;
+
+ /** Current command (if any) */
+ struct usbblk_command cmd;
+};
+
+/** Command tag magic
+ *
+ * This is a policy decision.
+ */
+#define USBBLK_TAG_MAGIC 0x18ae0000
+
+/** Maximum length of USB data block
+ *
+ * This is a policy decision.
+ */
+#define USBBLK_MAX_LEN 2048
+
+/** Maximum endpoint fill level
+ *
+ * This is a policy decision.
+ */
+#define USBBLK_MAX_FILL 4
+
+#endif /* _USBBLK_H */
diff --git a/src/drivers/usb/usbio.c b/src/drivers/usb/usbio.c
index dfb93dab1..278b43cd3 100644
--- a/src/drivers/usb/usbio.c
+++ b/src/drivers/usb/usbio.c
@@ -29,6 +29,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <assert.h>
#include <ipxe/efi/efi.h>
#include <ipxe/efi/efi_driver.h>
+#include <ipxe/efi/efi_path.h>
#include <ipxe/efi/efi_utils.h>
#include <ipxe/efi/Protocol/UsbIo.h>
#include <ipxe/usb.h>
@@ -206,7 +207,7 @@ static int usbio_open ( struct usbio_device *usbio, unsigned int interface ) {
path = usbio->path;
usbpath = usbio->usbpath;
usbpath->InterfaceNumber = interface;
- end = efi_devpath_end ( path );
+ end = efi_path_end ( path );
/* Locate handle for this endpoint's interface */
if ( ( efirc = bs->LocateDevicePath ( &efi_usb_io_protocol_guid, &path,
@@ -1503,7 +1504,7 @@ static int usbio_path ( struct usbio_device *usbio ) {
path = u.interface;
/* Locate end of device path and sanity check */
- len = efi_devpath_len ( path );
+ len = efi_path_len ( path );
if ( len < sizeof ( *usbpath ) ) {
DBGC ( usbio, "USBIO %s underlength device path\n",
efi_handle_name ( handle ) );
diff --git a/src/drivers/usb/xhci.c b/src/drivers/usb/xhci.c
index aa6ca73c4..cc48af033 100644
--- a/src/drivers/usb/xhci.c
+++ b/src/drivers/usb/xhci.c
@@ -31,7 +31,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <errno.h>
#include <byteswap.h>
#include <ipxe/malloc.h>
-#include <ipxe/umalloc.h>
#include <ipxe/pci.h>
#include <ipxe/usb.h>
#include <ipxe/init.h>
@@ -294,9 +293,9 @@ static void xhci_init ( struct xhci_device *xhci, void *regs ) {
/* Read structural parameters 2 */
hcsparams2 = readl ( xhci->cap + XHCI_CAP_HCSPARAMS2 );
- xhci->scratchpads = XHCI_HCSPARAMS2_SCRATCHPADS ( hcsparams2 );
+ xhci->scratch.count = XHCI_HCSPARAMS2_SCRATCHPADS ( hcsparams2 );
DBGC2 ( xhci, "XHCI %s needs %d scratchpads\n",
- xhci->name, xhci->scratchpads );
+ xhci->name, xhci->scratch.count );
/* Read capability parameters 1 */
hccparams1 = readl ( xhci->cap + XHCI_CAP_HCCPARAMS1 );
@@ -918,27 +917,29 @@ static int xhci_dcbaa_alloc ( struct xhci_device *xhci ) {
* align on its own size (rounded up to a power of two and
* with a minimum of 64 bytes).
*/
- len = ( ( xhci->slots + 1 ) * sizeof ( xhci->dcbaa[0] ) );
- xhci->dcbaa = malloc_dma ( len, xhci_align ( len ) );
- if ( ! xhci->dcbaa ) {
+ len = ( ( xhci->slots + 1 ) * sizeof ( xhci->dcbaa.context[0] ) );
+ xhci->dcbaa.context = dma_alloc ( xhci->dma, &xhci->dcbaa.map, len,
+ xhci_align ( len ) );
+ if ( ! xhci->dcbaa.context ) {
DBGC ( xhci, "XHCI %s could not allocate DCBAA\n", xhci->name );
rc = -ENOMEM;
goto err_alloc;
}
- memset ( xhci->dcbaa, 0, len );
+ memset ( xhci->dcbaa.context, 0, len );
/* Program DCBAA pointer */
- dcbaap = virt_to_phys ( xhci->dcbaa );
+ dcbaap = dma ( &xhci->dcbaa.map, xhci->dcbaa.context );
if ( ( rc = xhci_writeq ( xhci, dcbaap,
xhci->op + XHCI_OP_DCBAAP ) ) != 0 )
goto err_writeq;
- DBGC2 ( xhci, "XHCI %s DCBAA at [%08lx,%08lx)\n",
- xhci->name, dcbaap, ( dcbaap + len ) );
+ DBGC2 ( xhci, "XHCI %s DCBAA at [%08lx,%08lx)\n", xhci->name,
+ virt_to_phys ( xhci->dcbaa.context ),
+ ( virt_to_phys ( xhci->dcbaa.context ) + len ) );
return 0;
err_writeq:
- free_dma ( xhci->dcbaa, len );
+ dma_free ( &xhci->dcbaa.map, xhci->dcbaa.context, len );
err_alloc:
return rc;
}
@@ -954,14 +955,14 @@ static void xhci_dcbaa_free ( struct xhci_device *xhci ) {
/* Sanity check */
for ( i = 0 ; i <= xhci->slots ; i++ )
- assert ( xhci->dcbaa[i] == 0 );
+ assert ( xhci->dcbaa.context[i] == 0 );
/* Clear DCBAA pointer */
xhci_writeq ( xhci, 0, xhci->op + XHCI_OP_DCBAAP );
/* Free DCBAA */
- len = ( ( xhci->slots + 1 ) * sizeof ( xhci->dcbaa[0] ) );
- free_dma ( xhci->dcbaa, len );
+ len = ( ( xhci->slots + 1 ) * sizeof ( xhci->dcbaa.context[0] ) );
+ dma_free ( &xhci->dcbaa.map, xhci->dcbaa.context, len );
}
/******************************************************************************
@@ -978,32 +979,34 @@ static void xhci_dcbaa_free ( struct xhci_device *xhci ) {
* @ret rc Return status code
*/
static int xhci_scratchpad_alloc ( struct xhci_device *xhci ) {
+ struct xhci_scratchpad *scratch = &xhci->scratch;
+ size_t buffer_len;
size_t array_len;
- size_t len;
- physaddr_t phys;
+ physaddr_t addr;
unsigned int i;
int rc;
/* Do nothing if no scratchpad buffers are used */
- if ( ! xhci->scratchpads )
+ if ( ! scratch->count )
return 0;
- /* Allocate scratchpads */
- len = ( xhci->scratchpads * xhci->pagesize );
- xhci->scratchpad = umalloc ( len );
- if ( ! xhci->scratchpad ) {
+ /* Allocate scratchpad buffers */
+ buffer_len = ( scratch->count * xhci->pagesize );
+ scratch->buffer = dma_umalloc ( xhci->dma, &scratch->buffer_map,
+ buffer_len, xhci->pagesize );
+ if ( ! scratch->buffer ) {
DBGC ( xhci, "XHCI %s could not allocate scratchpad buffers\n",
xhci->name );
rc = -ENOMEM;
goto err_alloc;
}
- memset_user ( xhci->scratchpad, 0, 0, len );
+ memset_user ( scratch->buffer, 0, 0, buffer_len );
/* Allocate scratchpad array */
- array_len = ( xhci->scratchpads * sizeof ( xhci->scratchpad_array[0] ));
- xhci->scratchpad_array =
- malloc_dma ( array_len, xhci_align ( array_len ) );
- if ( ! xhci->scratchpad_array ) {
+ array_len = ( scratch->count * sizeof ( scratch->array[0] ) );
+ scratch->array = dma_alloc ( xhci->dma, &scratch->array_map,
+ array_len, xhci_align ( array_len ) );
+ if ( ! scratch->array ) {
DBGC ( xhci, "XHCI %s could not allocate scratchpad buffer "
"array\n", xhci->name );
rc = -ENOMEM;
@@ -1011,25 +1014,28 @@ static int xhci_scratchpad_alloc ( struct xhci_device *xhci ) {
}
/* Populate scratchpad array */
- for ( i = 0 ; i < xhci->scratchpads ; i++ ) {
- phys = user_to_phys ( xhci->scratchpad, ( i * xhci->pagesize ));
- xhci->scratchpad_array[i] = phys;
+ addr = dma_phys ( &scratch->buffer_map,
+ user_to_phys ( scratch->buffer, 0 ) );
+ for ( i = 0 ; i < scratch->count ; i++ ) {
+ scratch->array[i] = cpu_to_le64 ( addr );
+ addr += xhci->pagesize;
}
/* Set scratchpad array pointer */
- assert ( xhci->dcbaa != NULL );
- xhci->dcbaa[0] = cpu_to_le64 ( virt_to_phys ( xhci->scratchpad_array ));
+ assert ( xhci->dcbaa.context != NULL );
+ xhci->dcbaa.context[0] = cpu_to_le64 ( dma ( &scratch->array_map,
+ scratch->array ) );
DBGC2 ( xhci, "XHCI %s scratchpad [%08lx,%08lx) array [%08lx,%08lx)\n",
- xhci->name, user_to_phys ( xhci->scratchpad, 0 ),
- user_to_phys ( xhci->scratchpad, len ),
- virt_to_phys ( xhci->scratchpad_array ),
- ( virt_to_phys ( xhci->scratchpad_array ) + array_len ) );
+ xhci->name, user_to_phys ( scratch->buffer, 0 ),
+ user_to_phys ( scratch->buffer, buffer_len ),
+ virt_to_phys ( scratch->array ),
+ ( virt_to_phys ( scratch->array ) + array_len ) );
return 0;
- free_dma ( xhci->scratchpad_array, array_len );
+ dma_free ( &scratch->array_map, scratch->array, array_len );
err_alloc_array:
- ufree ( xhci->scratchpad );
+ dma_ufree ( &scratch->buffer_map, scratch->buffer, buffer_len );
err_alloc:
return rc;
}
@@ -1040,22 +1046,25 @@ static int xhci_scratchpad_alloc ( struct xhci_device *xhci ) {
* @v xhci xHCI device
*/
static void xhci_scratchpad_free ( struct xhci_device *xhci ) {
+ struct xhci_scratchpad *scratch = &xhci->scratch;
size_t array_len;
+ size_t buffer_len;
/* Do nothing if no scratchpad buffers are used */
- if ( ! xhci->scratchpads )
+ if ( ! scratch->count )
return;
/* Clear scratchpad array pointer */
- assert ( xhci->dcbaa != NULL );
- xhci->dcbaa[0] = 0;
+ assert ( xhci->dcbaa.context != NULL );
+ xhci->dcbaa.context[0] = 0;
/* Free scratchpad array */
- array_len = ( xhci->scratchpads * sizeof ( xhci->scratchpad_array[0] ));
- free_dma ( xhci->scratchpad_array, array_len );
+ array_len = ( scratch->count * sizeof ( scratch->array[0] ) );
+ dma_free ( &scratch->array_map, scratch->array, array_len );
- /* Free scratchpads */
- ufree ( xhci->scratchpad );
+ /* Free scratchpad buffers */
+ buffer_len = ( scratch->count * xhci->pagesize );
+ dma_ufree ( &scratch->buffer_map, scratch->buffer, buffer_len );
}
/******************************************************************************
@@ -1202,7 +1211,8 @@ static int xhci_ring_alloc ( struct xhci_device *xhci,
}
/* Allocate TRBs */
- ring->trb = malloc_dma ( ring->len, xhci_align ( ring->len ) );
+ ring->trb = dma_alloc ( xhci->dma, &ring->map, ring->len,
+ xhci_align ( ring->len ) );
if ( ! ring->trb ) {
rc = -ENOMEM;
goto err_alloc_trb;
@@ -1211,14 +1221,14 @@ static int xhci_ring_alloc ( struct xhci_device *xhci,
/* Initialise Link TRB */
link = &ring->trb[count].link;
- link->next = cpu_to_le64 ( virt_to_phys ( ring->trb ) );
+ link->next = cpu_to_le64 ( dma ( &ring->map, ring->trb ) );
link->flags = XHCI_TRB_TC;
link->type = XHCI_TRB_LINK;
ring->link = link;
return 0;
- free_dma ( ring->trb, ring->len );
+ dma_free ( &ring->map, ring->trb, ring->len );
err_alloc_trb:
free ( ring->iobuf );
err_alloc_iobuf:
@@ -1256,7 +1266,7 @@ static void xhci_ring_free ( struct xhci_trb_ring *ring ) {
assert ( ring->iobuf[i] == NULL );
/* Free TRBs */
- free_dma ( ring->trb, ring->len );
+ dma_free ( &ring->map, ring->trb, ring->len );
/* Free I/O buffers */
free ( ring->iobuf );
@@ -1422,13 +1432,14 @@ static int xhci_command_alloc ( struct xhci_device *xhci ) {
goto err_ring_alloc;
/* Program command ring control register */
- crp = virt_to_phys ( xhci->command.trb );
+ crp = dma ( &xhci->command.map, xhci->command.trb );
if ( ( rc = xhci_writeq ( xhci, ( crp | XHCI_CRCR_RCS ),
xhci->op + XHCI_OP_CRCR ) ) != 0 )
goto err_writeq;
- DBGC2 ( xhci, "XHCI %s CRCR at [%08lx,%08lx)\n",
- xhci->name, crp, ( crp + xhci->command.len ) );
+ DBGC2 ( xhci, "XHCI %s CRCR at [%08lx,%08lx)\n", xhci->name,
+ virt_to_phys ( xhci->command.trb ),
+ ( virt_to_phys ( xhci->command.trb ) + xhci->command.len ) );
return 0;
err_writeq:
@@ -1469,7 +1480,8 @@ static int xhci_event_alloc ( struct xhci_device *xhci ) {
/* Allocate event ring */
count = ( 1 << XHCI_EVENT_TRBS_LOG2 );
len = ( count * sizeof ( event->trb[0] ) );
- event->trb = malloc_dma ( len, xhci_align ( len ) );
+ event->trb = dma_alloc ( xhci->dma, &event->trb_map, len,
+ xhci_align ( len ) );
if ( ! event->trb ) {
rc = -ENOMEM;
goto err_alloc_trb;
@@ -1477,22 +1489,25 @@ static int xhci_event_alloc ( struct xhci_device *xhci ) {
memset ( event->trb, 0, len );
/* Allocate event ring segment table */
- event->segment = malloc_dma ( sizeof ( event->segment[0] ),
- xhci_align ( sizeof (event->segment[0])));
+ event->segment = dma_alloc ( xhci->dma, &event->segment_map,
+ sizeof ( event->segment[0] ),
+ xhci_align ( sizeof (event->segment[0])));
if ( ! event->segment ) {
rc = -ENOMEM;
goto err_alloc_segment;
}
memset ( event->segment, 0, sizeof ( event->segment[0] ) );
- event->segment[0].base = cpu_to_le64 ( virt_to_phys ( event->trb ) );
+ event->segment[0].base = cpu_to_le64 ( dma ( &event->trb_map,
+ event->trb ) );
event->segment[0].count = cpu_to_le32 ( count );
/* Program event ring registers */
writel ( 1, xhci->run + XHCI_RUN_ERSTSZ ( 0 ) );
- if ( ( rc = xhci_writeq ( xhci, virt_to_phys ( event->trb ),
+ if ( ( rc = xhci_writeq ( xhci, dma ( &event->trb_map, event->trb ),
xhci->run + XHCI_RUN_ERDP ( 0 ) ) ) != 0 )
goto err_writeq_erdp;
- if ( ( rc = xhci_writeq ( xhci, virt_to_phys ( event->segment ),
+ if ( ( rc = xhci_writeq ( xhci,
+ dma ( &event->segment_map, event->segment ),
xhci->run + XHCI_RUN_ERSTBA ( 0 ) ) ) != 0 )
goto err_writeq_erstba;
@@ -1501,16 +1516,17 @@ static int xhci_event_alloc ( struct xhci_device *xhci ) {
( virt_to_phys ( event->trb ) + len ),
virt_to_phys ( event->segment ),
( virt_to_phys ( event->segment ) +
- sizeof (event->segment[0] ) ) );
+ sizeof ( event->segment[0] ) ) );
return 0;
xhci_writeq ( xhci, 0, xhci->run + XHCI_RUN_ERSTBA ( 0 ) );
err_writeq_erstba:
xhci_writeq ( xhci, 0, xhci->run + XHCI_RUN_ERDP ( 0 ) );
err_writeq_erdp:
- free_dma ( event->trb, len );
+ dma_free ( &event->segment_map, event->segment,
+ sizeof ( event->segment[0] ) );
err_alloc_segment:
- free_dma ( event->segment, sizeof ( event->segment[0] ) );
+ dma_free ( &event->trb_map, event->trb, len );
err_alloc_trb:
return rc;
}
@@ -1531,12 +1547,13 @@ static void xhci_event_free ( struct xhci_device *xhci ) {
xhci_writeq ( xhci, 0, xhci->run + XHCI_RUN_ERDP ( 0 ) );
/* Free event ring segment table */
- free_dma ( event->segment, sizeof ( event->segment[0] ) );
+ dma_free ( &event->segment_map, event->segment,
+ sizeof ( event->segment[0] ) );
/* Free event ring */
count = ( 1 << XHCI_EVENT_TRBS_LOG2 );
len = ( count * sizeof ( event->trb[0] ) );
- free_dma ( event->trb, len );
+ dma_free ( &event->trb_map, event->trb, len );
}
/**
@@ -1577,6 +1594,9 @@ static void xhci_transfer ( struct xhci_device *xhci,
iobuf = xhci_dequeue_multi ( &endpoint->ring );
assert ( iobuf != NULL );
+ /* Unmap I/O buffer */
+ iob_unmap ( iobuf );
+
/* Check for errors */
if ( ! ( ( trb->code == XHCI_CMPLT_SUCCESS ) ||
( trb->code == XHCI_CMPLT_SHORT ) ) ) {
@@ -1745,7 +1765,7 @@ static void xhci_event_poll ( struct xhci_device *xhci ) {
/* Update dequeue pointer if applicable */
if ( consumed ) {
- xhci_writeq ( xhci, virt_to_phys ( trb ),
+ xhci_writeq ( xhci, dma ( &event->trb_map, trb ),
xhci->run + XHCI_RUN_ERDP ( 0 ) );
profile_stop ( &xhci_event_profiler );
}
@@ -1774,7 +1794,7 @@ static void xhci_abort ( struct xhci_device *xhci ) {
/* Reset the command ring control register */
xhci_ring_reset ( &xhci->command );
- crp = virt_to_phys ( xhci->command.trb );
+ crp = dma ( &xhci->command.map, xhci->command.trb );
xhci_writeq ( xhci, ( crp | XHCI_CRCR_RCS ), xhci->op + XHCI_OP_CRCR );
}
@@ -1793,6 +1813,13 @@ static int xhci_command ( struct xhci_device *xhci, union xhci_trb *trb ) {
unsigned int i;
int rc;
+ /* Sanity check */
+ if ( xhci->pending ) {
+ DBGC ( xhci, "XHCI %s command ring busy\n", xhci->name );
+ rc = -EBUSY;
+ goto err_pending;
+ }
+
/* Record the pending command */
xhci->pending = trb;
@@ -1835,6 +1862,7 @@ static int xhci_command ( struct xhci_device *xhci, union xhci_trb *trb ) {
err_enqueue:
xhci->pending = NULL;
+ err_pending:
return rc;
}
@@ -1855,9 +1883,13 @@ static inline int xhci_nop ( struct xhci_device *xhci ) {
nop->type = XHCI_TRB_NOP_CMD;
/* Issue command and wait for completion */
- if ( ( rc = xhci_command ( xhci, &trb ) ) != 0 )
+ if ( ( rc = xhci_command ( xhci, &trb ) ) != 0 ) {
+ DBGC ( xhci, "XHCI %s NOP failed: %s\n",
+ xhci->name, strerror ( rc ) );
return rc;
+ }
+ DBGC2 ( xhci, "XHCI %s NOP completed successfully\n", xhci->name );
return 0;
}
@@ -1942,13 +1974,15 @@ static int xhci_context ( struct xhci_device *xhci, struct xhci_slot *slot,
void *input ) ) {
union xhci_trb trb;
struct xhci_trb_context *context = &trb.context;
+ struct dma_mapping map;
size_t len;
void *input;
int rc;
/* Allocate an input context */
+ memset ( &map, 0, sizeof ( map ) );
len = xhci_input_context_offset ( xhci, XHCI_CTX_END );
- input = malloc_dma ( len, xhci_align ( len ) );
+ input = dma_alloc ( xhci->dma, &map, len, xhci_align ( len ) );
if ( ! input ) {
rc = -ENOMEM;
goto err_alloc;
@@ -1961,7 +1995,7 @@ static int xhci_context ( struct xhci_device *xhci, struct xhci_slot *slot,
/* Construct command */
memset ( context, 0, sizeof ( *context ) );
context->type = type;
- context->input = cpu_to_le64 ( virt_to_phys ( input ) );
+ context->input = cpu_to_le64 ( dma ( &map, input ) );
context->slot = slot->id;
/* Issue command and wait for completion */
@@ -1969,7 +2003,7 @@ static int xhci_context ( struct xhci_device *xhci, struct xhci_slot *slot,
goto err_command;
err_command:
- free_dma ( input, len );
+ dma_free ( &map, input, len );
err_alloc:
return rc;
}
@@ -1986,6 +2020,7 @@ static void xhci_address_device_input ( struct xhci_device *xhci,
struct xhci_slot *slot,
struct xhci_endpoint *endpoint,
void *input ) {
+ struct xhci_trb_ring *ring = &endpoint->ring;
struct xhci_control_context *control_ctx;
struct xhci_slot_context *slot_ctx;
struct xhci_endpoint_context *ep_ctx;
@@ -2011,7 +2046,7 @@ static void xhci_address_device_input ( struct xhci_device *xhci,
ep_ctx->type = XHCI_EP_TYPE_CONTROL;
ep_ctx->burst = endpoint->ep->burst;
ep_ctx->mtu = cpu_to_le16 ( endpoint->ep->mtu );
- ep_ctx->dequeue = cpu_to_le64 ( virt_to_phys ( endpoint->ring.trb ) |
+ ep_ctx->dequeue = cpu_to_le64 ( dma ( &ring->map, ring->trb ) |
XHCI_EP_DCS );
ep_ctx->trb_len = cpu_to_le16 ( XHCI_EP0_TRB_LEN );
}
@@ -2032,15 +2067,18 @@ static inline int xhci_address_device ( struct xhci_device *xhci,
/* Assign device address */
if ( ( rc = xhci_context ( xhci, slot, slot->endpoint[XHCI_CTX_EP0],
XHCI_TRB_ADDRESS_DEVICE,
- xhci_address_device_input ) ) != 0 )
+ xhci_address_device_input ) ) != 0 ) {
+ DBGC ( xhci, "XHCI %s slot %d could not assign address: %s\n",
+ xhci->name, slot->id, strerror ( rc ) );
return rc;
+ }
/* Get assigned address */
slot_ctx = ( slot->context +
xhci_device_context_offset ( xhci, XHCI_CTX_SLOT ) );
usb->address = slot_ctx->address;
- DBGC2 ( xhci, "XHCI %s assigned address %d to %s\n",
- xhci->name, usb->address, usb->name );
+ DBGC2 ( xhci, "XHCI %s slot %d assigned address %d to %s\n",
+ xhci->name, slot->id, usb->address, usb->name );
return 0;
}
@@ -2057,6 +2095,7 @@ static void xhci_configure_endpoint_input ( struct xhci_device *xhci,
struct xhci_slot *slot,
struct xhci_endpoint *endpoint,
void *input ) {
+ struct xhci_trb_ring *ring = &endpoint->ring;
struct xhci_control_context *control_ctx;
struct xhci_slot_context *slot_ctx;
struct xhci_endpoint_context *ep_ctx;
@@ -2079,7 +2118,7 @@ static void xhci_configure_endpoint_input ( struct xhci_device *xhci,
ep_ctx->type = endpoint->type;
ep_ctx->burst = endpoint->ep->burst;
ep_ctx->mtu = cpu_to_le16 ( endpoint->ep->mtu );
- ep_ctx->dequeue = cpu_to_le64 ( virt_to_phys ( endpoint->ring.trb ) |
+ ep_ctx->dequeue = cpu_to_le64 ( dma ( &ring->map, ring->trb ) |
XHCI_EP_DCS );
ep_ctx->trb_len = cpu_to_le16 ( endpoint->ep->mtu ); /* best guess */
}
@@ -2100,8 +2139,11 @@ static inline int xhci_configure_endpoint ( struct xhci_device *xhci,
/* Configure endpoint */
if ( ( rc = xhci_context ( xhci, slot, endpoint,
XHCI_TRB_CONFIGURE_ENDPOINT,
- xhci_configure_endpoint_input ) ) != 0 )
+ xhci_configure_endpoint_input ) ) != 0 ) {
+ DBGC ( xhci, "XHCI %s slot %d ctx %d could not configure: %s\n",
+ xhci->name, slot->id, endpoint->ctx, strerror ( rc ) );
return rc;
+ }
DBGC2 ( xhci, "XHCI %s slot %d ctx %d configured\n",
xhci->name, slot->id, endpoint->ctx );
@@ -2151,8 +2193,12 @@ static inline int xhci_deconfigure_endpoint ( struct xhci_device *xhci,
/* Deconfigure endpoint */
if ( ( rc = xhci_context ( xhci, slot, endpoint,
XHCI_TRB_CONFIGURE_ENDPOINT,
- xhci_deconfigure_endpoint_input ) ) != 0 )
+ xhci_deconfigure_endpoint_input ) ) != 0 ) {
+ DBGC ( xhci, "XHCI %s slot %d ctx %d could not deconfigure: "
+ "%s\n", xhci->name, slot->id, endpoint->ctx,
+ strerror ( rc ) );
return rc;
+ }
DBGC2 ( xhci, "XHCI %s slot %d ctx %d deconfigured\n",
xhci->name, slot->id, endpoint->ctx );
@@ -2206,8 +2252,12 @@ static inline int xhci_evaluate_context ( struct xhci_device *xhci,
/* Configure endpoint */
if ( ( rc = xhci_context ( xhci, slot, endpoint,
XHCI_TRB_EVALUATE_CONTEXT,
- xhci_evaluate_context_input ) ) != 0 )
+ xhci_evaluate_context_input ) ) != 0 ) {
+ DBGC ( xhci, "XHCI %s slot %d ctx %d could not (re-)evaluate: "
+ "%s\n", xhci->name, slot->id, endpoint->ctx,
+ strerror ( rc ) );
return rc;
+ }
DBGC2 ( xhci, "XHCI %s slot %d ctx %d (re-)evaluated\n",
xhci->name, slot->id, endpoint->ctx );
@@ -2297,6 +2347,7 @@ xhci_set_tr_dequeue_pointer ( struct xhci_device *xhci,
unsigned int mask;
unsigned int index;
unsigned int dcs;
+ physaddr_t addr;
int rc;
/* Construct command */
@@ -2305,8 +2356,8 @@ xhci_set_tr_dequeue_pointer ( struct xhci_device *xhci,
mask = ring->mask;
dcs = ( ( ~( cons >> ring->shift ) ) & XHCI_EP_DCS );
index = ( cons & mask );
- dequeue->dequeue =
- cpu_to_le64 ( virt_to_phys ( &ring->trb[index] ) | dcs );
+ addr = dma ( &ring->map, &ring->trb[index] );
+ dequeue->dequeue = cpu_to_le64 ( addr | dcs );
dequeue->slot = slot->id;
dequeue->endpoint = endpoint->ctx;
dequeue->type = XHCI_TRB_SET_TR_DEQUEUE_POINTER;
@@ -2425,6 +2476,7 @@ static void xhci_endpoint_close ( struct usb_endpoint *ep ) {
/* Cancel any incomplete transfers */
while ( xhci_ring_fill ( &endpoint->ring ) ) {
iobuf = xhci_dequeue_multi ( &endpoint->ring );
+ iob_unmap ( iobuf );
usb_complete_err ( ep, iobuf, -ECANCELED );
}
@@ -2491,6 +2543,7 @@ static int xhci_endpoint_mtu ( struct usb_endpoint *ep ) {
static int xhci_endpoint_message ( struct usb_endpoint *ep,
struct io_buffer *iobuf ) {
struct xhci_endpoint *endpoint = usb_endpoint_get_hostdata ( ep );
+ struct xhci_device *xhci = endpoint->xhci;
struct usb_setup_packet *packet;
unsigned int input;
size_t len;
@@ -2520,10 +2573,15 @@ static int xhci_endpoint_message ( struct usb_endpoint *ep,
if ( len )
setup->direction = ( input ? XHCI_SETUP_IN : XHCI_SETUP_OUT );
+ /* Map I/O buffer */
+ if ( ( rc = iob_map ( iobuf, xhci->dma, len,
+ ( input ? DMA_RX : DMA_TX ) ) ) != 0 )
+ goto err_map;
+
/* Construct data stage TRB, if applicable */
if ( len ) {
data = &(trb++)->data;
- data->data = cpu_to_le64 ( virt_to_phys ( iobuf->data ) );
+ data->data = cpu_to_le64 ( iob_dma ( iobuf ) );
data->len = cpu_to_le32 ( len );
data->type = XHCI_TRB_DATA;
data->direction = ( input ? XHCI_DATA_IN : XHCI_DATA_OUT );
@@ -2539,13 +2597,18 @@ static int xhci_endpoint_message ( struct usb_endpoint *ep,
/* Enqueue TRBs */
if ( ( rc = xhci_enqueue_multi ( &endpoint->ring, iobuf, trbs,
( trb - trbs ) ) ) != 0 )
- return rc;
+ goto err_enqueue;
/* Ring the doorbell */
xhci_doorbell ( &endpoint->ring );
profile_stop ( &xhci_message_profiler );
return 0;
+
+ err_enqueue:
+ iob_unmap ( iobuf );
+ err_map:
+ return rc;
}
/**
@@ -2579,12 +2642,13 @@ static unsigned int xhci_endpoint_count ( size_t len, int zlp ) {
static int xhci_endpoint_stream ( struct usb_endpoint *ep,
struct io_buffer *iobuf, int zlp ) {
struct xhci_endpoint *endpoint = usb_endpoint_get_hostdata ( ep );
- void *data = iobuf->data;
+ struct xhci_device *xhci = endpoint->xhci;
size_t len = iob_len ( iobuf );
unsigned int count = xhci_endpoint_count ( len, zlp );
union xhci_trb trbs[count];
union xhci_trb *trb = trbs;
struct xhci_trb_normal *normal;
+ physaddr_t data;
unsigned int i;
size_t trb_len;
int rc;
@@ -2592,6 +2656,13 @@ static int xhci_endpoint_stream ( struct usb_endpoint *ep,
/* Profile stream transfers */
profile_start ( &xhci_stream_profiler );
+ /* Map I/O buffer */
+ if ( ( rc = iob_map ( iobuf, xhci->dma, len,
+ ( ( ep->address & USB_DIR_IN ) ?
+ DMA_RX : DMA_TX ) ) ) != 0 )
+ goto err_map;
+ data = iob_dma ( iobuf );
+
/* Construct normal TRBs */
memset ( &trbs, 0, sizeof ( trbs ) );
for ( i = 0 ; i < count ; i ++ ) {
@@ -2603,7 +2674,7 @@ static int xhci_endpoint_stream ( struct usb_endpoint *ep,
/* Construct normal TRB */
normal = &trb->normal;
- normal->data = cpu_to_le64 ( virt_to_phys ( data ) );
+ normal->data = cpu_to_le64 ( data );
normal->len = cpu_to_le32 ( trb_len );
normal->type = XHCI_TRB_NORMAL;
normal->flags = XHCI_TRB_CH;
@@ -2624,13 +2695,18 @@ static int xhci_endpoint_stream ( struct usb_endpoint *ep,
/* Enqueue TRBs */
if ( ( rc = xhci_enqueue_multi ( &endpoint->ring, iobuf, trbs,
count ) ) != 0 )
- return rc;
+ goto err_enqueue;
/* Ring the doorbell */
xhci_doorbell ( &endpoint->ring );
profile_stop ( &xhci_stream_profiler );
return 0;
+
+ err_enqueue:
+ iob_unmap ( iobuf );
+ err_map:
+ return rc;
}
/******************************************************************************
@@ -2693,7 +2769,8 @@ static int xhci_device_open ( struct usb_device *usb ) {
/* Allocate a device context */
len = xhci_device_context_offset ( xhci, XHCI_CTX_END );
- slot->context = malloc_dma ( len, xhci_align ( len ) );
+ slot->context = dma_alloc ( xhci->dma, &slot->map, len,
+ xhci_align ( len ) );
if ( ! slot->context ) {
rc = -ENOMEM;
goto err_alloc_context;
@@ -2701,16 +2778,17 @@ static int xhci_device_open ( struct usb_device *usb ) {
memset ( slot->context, 0, len );
/* Set device context base address */
- assert ( xhci->dcbaa[id] == 0 );
- xhci->dcbaa[id] = cpu_to_le64 ( virt_to_phys ( slot->context ) );
+ assert ( xhci->dcbaa.context[id] == 0 );
+ xhci->dcbaa.context[id] = cpu_to_le64 ( dma ( &slot->map,
+ slot->context ) );
DBGC2 ( xhci, "XHCI %s slot %d device context [%08lx,%08lx) for %s\n",
xhci->name, slot->id, virt_to_phys ( slot->context ),
( virt_to_phys ( slot->context ) + len ), usb->name );
return 0;
- xhci->dcbaa[id] = 0;
- free_dma ( slot->context, len );
+ xhci->dcbaa.context[id] = 0;
+ dma_free ( &slot->map, slot->context, len );
err_alloc_context:
xhci->slot[id] = NULL;
free ( slot );
@@ -2750,8 +2828,8 @@ static void xhci_device_close ( struct usb_device *usb ) {
/* Free slot */
if ( slot->context ) {
- free_dma ( slot->context, len );
- xhci->dcbaa[id] = 0;
+ dma_free ( &slot->map, slot->context, len );
+ xhci->dcbaa.context[id] = 0;
}
xhci->slot[id] = NULL;
free ( slot );
@@ -3261,7 +3339,7 @@ static int xhci_probe ( struct pci_device *pci ) {
/* Map registers */
bar_start = pci_bar_start ( pci, XHCI_BAR );
bar_size = pci_bar_size ( pci, XHCI_BAR );
- xhci->regs = ioremap ( bar_start, bar_size );
+ xhci->regs = pci_ioremap ( pci, bar_start, bar_size );
if ( ! xhci->regs ) {
rc = -ENODEV;
goto err_ioremap;
@@ -3270,6 +3348,11 @@ static int xhci_probe ( struct pci_device *pci ) {
/* Initialise xHCI device */
xhci_init ( xhci, xhci->regs );
+ /* Configure DMA device */
+ xhci->dma = &pci->dma;
+ if ( xhci->addr64 )
+ dma_set_mask_64bit ( xhci->dma );
+
/* Initialise USB legacy support and claim ownership */
xhci_legacy_init ( xhci );
xhci_legacy_claim ( xhci );
diff --git a/src/drivers/usb/xhci.h b/src/drivers/usb/xhci.h
index e996363ea..6e02d70e0 100644
--- a/src/drivers/usb/xhci.h
+++ b/src/drivers/usb/xhci.h
@@ -854,6 +854,8 @@ struct xhci_trb_ring {
union xhci_trb *trb;
/** Length of transfer request blocks */
size_t len;
+ /** DMA mapping */
+ struct dma_mapping map;
/** Link TRB (if applicable) */
struct xhci_trb_link *link;
@@ -869,8 +871,12 @@ struct xhci_event_ring {
unsigned int cons;
/** Event ring segment table */
struct xhci_event_ring_segment *segment;
+ /** Event ring segment table DMA mapping */
+ struct dma_mapping segment_map;
/** Transfer request blocks */
union xhci_trb *trb;
+ /** Transfer request blocks DMA mapping */
+ struct dma_mapping trb_map;
};
/**
@@ -1035,10 +1041,34 @@ struct xhci_pch {
/** Invalid protocol speed ID values quirk */
#define XHCI_BAD_PSIV 0x0002
+/** Device context base address array */
+struct xhci_dcbaa {
+ /** Context base addresses */
+ uint64_t *context;
+ /** DMA mapping */
+ struct dma_mapping map;
+};
+
+/** Scratchpad buffer */
+struct xhci_scratchpad {
+ /** Number of page-sized scratchpad buffers */
+ unsigned int count;
+ /** Scratchpad buffer area */
+ userptr_t buffer;
+ /** Buffer DMA mapping */
+ struct dma_mapping buffer_map;
+ /** Scratchpad array */
+ uint64_t *array;
+ /** Array DMA mapping */
+ struct dma_mapping array_map;
+};
+
/** An xHCI device */
struct xhci_device {
/** Registers */
void *regs;
+ /** DMA device */
+ struct dma_device *dma;
/** Name */
const char *name;
/** Quirks */
@@ -1060,9 +1090,6 @@ struct xhci_device {
/** Number of ports */
unsigned int ports;
- /** Number of page-sized scratchpad buffers */
- unsigned int scratchpads;
-
/** 64-bit addressing capability */
int addr64;
/** Context size shift */
@@ -1077,12 +1104,10 @@ struct xhci_device {
unsigned int legacy;
/** Device context base address array */
- uint64_t *dcbaa;
+ struct xhci_dcbaa dcbaa;
- /** Scratchpad buffer area */
- userptr_t scratchpad;
- /** Scratchpad buffer array */
- uint64_t *scratchpad_array;
+ /** Scratchpad buffer */
+ struct xhci_scratchpad scratch;
/** Command ring */
struct xhci_trb_ring command;
@@ -1111,6 +1136,8 @@ struct xhci_slot {
unsigned int id;
/** Slot context */
struct xhci_slot_context *context;
+ /** DMA mapping */
+ struct dma_mapping map;
/** Route string */
unsigned int route;
/** Root hub port number */