iPXE
Data Structures | Functions | Variables
ata.c File Reference

ATA block device. More...

#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <errno.h>
#include <byteswap.h>
#include <ipxe/list.h>
#include <ipxe/interface.h>
#include <ipxe/blockdev.h>
#include <ipxe/edd.h>
#include <ipxe/ata.h>

Go to the source code of this file.

Data Structures

struct  ata_device
 An ATA device. More...
 
struct  ata_command
 An ATA command. More...
 
struct  ata_command_type
 An ATA command type. More...
 
struct  ata_identify_private
 ATA IDENTIFY private data. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
int ata_command (struct interface *control, struct interface *data, struct ata_cmd *command)
 Issue ATA command. More...
 
static LIST_HEAD (ata_commands)
 List of all ATA commands. More...
 
static __attribute__ ((always_inline))
 Get reference to ATA device. More...
 
static void atacmd_free (struct refcnt *refcnt)
 Free ATA command. More...
 
static void atacmd_close (struct ata_command *atacmd, int rc)
 Close ATA command. More...
 
static void atacmd_done (struct ata_command *atacmd, int rc)
 Handle ATA command completion. More...
 
static void atacmd_data_buffer (struct ata_command *atacmd __unused, userptr_t buffer, size_t len, userptr_t *data, size_t *data_len)
 Use provided data buffer for ATA command. More...
 
static void atacmd_data_none (struct ata_command *atacmd __unused, userptr_t buffer __unused, size_t len __unused, userptr_t *data __unused, size_t *data_len __unused)
 Use no data buffer for ATA command. More...
 
static void atacmd_data_priv (struct ata_command *atacmd, userptr_t buffer __unused, size_t len __unused, userptr_t *data, size_t *data_len)
 Use private data buffer for ATA command. More...
 
static const char * ata_model (struct ata_identity *identity)
 Return ATA model string (for debugging) More...
 
static void atacmd_identify_done (struct ata_command *atacmd, int rc)
 Handle ATA IDENTIFY command completion. More...
 
static int atadev_command (struct ata_device *atadev, struct interface *block, struct ata_command_type *type, uint64_t lba, unsigned int count, userptr_t buffer, size_t len)
 Create ATA command. More...
 
static int atadev_read (struct ata_device *atadev, struct interface *block, uint64_t lba, unsigned int count, userptr_t buffer, size_t len)
 Issue ATA block read. More...
 
static int atadev_write (struct ata_device *atadev, struct interface *block, uint64_t lba, unsigned int count, userptr_t buffer, size_t len)
 Issue ATA block write. More...
 
static int atadev_read_capacity (struct ata_device *atadev, struct interface *block)
 Read ATA device capacity. More...
 
static void atadev_close (struct ata_device *atadev, int rc)
 Close ATA device. More...
 
static int atadev_edd_describe (struct ata_device *atadev, struct edd_interface_type *type, union edd_device_path *path)
 Describe ATA device using EDD. More...
 
int ata_open (struct interface *block, struct interface *ata, unsigned int device, unsigned int max_count)
 Open ATA device. More...
 

Variables

static struct ata_command_type atacmd_read
 ATA READ command type. More...
 
static struct ata_command_type atacmd_write
 ATA WRITE command type. More...
 
static struct ata_command_type atacmd_identify
 ATA IDENTITY command type. More...
 
static struct interface_operation atacmd_block_op []
 ATA command block interface operations. More...
 
static struct interface_descriptor atacmd_block_desc
 ATA command block interface descriptor. More...
 
static struct interface_operation atacmd_ata_op []
 ATA command ATA interface operations. More...
 
static struct interface_descriptor atacmd_ata_desc
 ATA command ATA interface descriptor. More...
 
static struct interface_operation atadev_block_op []
 ATA device block interface operations. More...
 
static struct interface_descriptor atadev_block_desc
 ATA device block interface descriptor. More...
 
static struct interface_operation atadev_ata_op []
 ATA device ATA interface operations. More...
 
static struct interface_descriptor atadev_ata_desc
 ATA device ATA interface descriptor. More...
 

Detailed Description

ATA block device.

Definition in file ata.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ ata_command()

int ata_command ( struct interface control,
struct interface data,
struct ata_cmd command 
)

Issue ATA command.

Parameters
controlATA control interface
dataATA data interface
commandATA command
Return values
tagCommand tag, or negative error

Definition at line 59 of file ata.c.

60  {
61  struct interface *dest;
62  ata_command_TYPE ( void * ) *op =
64  void *object = intf_object ( dest );
65  int tag;
66 
67  if ( op ) {
68  tag = op ( object, data, command );
69  } else {
70  /* Default is to fail to issue the command */
71  tag = -EOPNOTSUPP;
72  }
73 
74  intf_put ( dest );
75  return tag;
76 }
A command-line command.
Definition: command.h:9
void * intf_object(struct interface *intf)
Get pointer to object containing object interface.
Definition: interface.c:159
An object interface.
Definition: interface.h:124
static void * dest
Definition: strings.h:176
uint32_t control
Control.
Definition: myson.h:14
#define EOPNOTSUPP
Operation not supported on socket.
Definition: errno.h:604
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
#define ata_command_TYPE(object_type)
Definition: ata.h:197
void intf_put(struct interface *intf)
Decrement reference count on an object interface.
Definition: interface.c:149
uint8_t data[48]
Additional event data.
Definition: ena.h:22
uint64_t tag
Identity tag.
Definition: edd.h:30
An ATA command.
Definition: ata.c:109
#define intf_get_dest_op(intf, type, dest)
Get object interface destination and operation method.
Definition: interface.h:269

References ata_command_TYPE, control, data, dest, EOPNOTSUPP, intf_get_dest_op, intf_object(), intf_put(), op, and tag.

◆ LIST_HEAD()

static LIST_HEAD ( ata_commands  )
static

List of all ATA commands.

◆ __attribute__()

static __attribute__ ( (always_inline)  )
inlinestatic

Get reference to ATA device.

Get ATA command private data.

Drop reference to ATA command.

Get reference to ATA command.

Drop reference to ATA device.

Parameters
atadevATA device
Return values
atadevATA device
Parameters
atadevATA device
atacmdATA command
Return values
atacmdATA command
Parameters
atacmdATA command
atacmdATA command
Return values
privPrivate data

Definition at line 181 of file ata.c.

182  {
183  ref_get ( &atadev->refcnt );
184  return atadev;
185 }
#define ref_get(refcnt)
Get additional reference to object.
Definition: refcnt.h:92

References ref_get, and ata_device::refcnt.

◆ atacmd_free()

static void atacmd_free ( struct refcnt refcnt)
static

Free ATA command.

Parameters
refcntReference count

Definition at line 235 of file ata.c.

235  {
236  struct ata_command *atacmd =
237  container_of ( refcnt, struct ata_command, refcnt );
238 
239  /* Remove from list of commands */
240  list_del ( &atacmd->list );
241  atadev_put ( atacmd->atadev );
242 
243  /* Free command */
244  free ( atacmd );
245 }
struct ata_device * atadev
ATA device.
Definition: ata.c:113
A reference counter.
Definition: refcnt.h:26
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
struct list_head list
List of ATA commands.
Definition: ata.c:115
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
An ATA command.
Definition: ata.c:109

References ata_command::atadev, container_of, free, ata_command::list, and list_del.

Referenced by atadev_command().

◆ atacmd_close()

static void atacmd_close ( struct ata_command atacmd,
int  rc 
)
static

Close ATA command.

Parameters
atacmdATA command
rcReason for close

Definition at line 253 of file ata.c.

253  {
254  struct ata_device *atadev = atacmd->atadev;
255 
256  if ( rc != 0 ) {
257  DBGC ( atadev, "ATA %p tag %08x closed: %s\n",
258  atadev, atacmd->tag, strerror ( rc ) );
259  }
260 
261  /* Shut down interfaces */
262  intf_shutdown ( &atacmd->ata, rc );
263  intf_shutdown ( &atacmd->block, rc );
264 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void intf_shutdown(struct interface *intf, int rc)
Shut down an object interface.
Definition: interface.c:278
struct ata_device * atadev
ATA device.
Definition: ata.c:113
#define DBGC(...)
Definition: compiler.h:505
An ATA device.
Definition: ata.c:89
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
struct interface ata
ATA data interface.
Definition: ata.c:120
struct interface block
Block data interface.
Definition: ata.c:118
uint32_t tag
Command tag.
Definition: ata.c:125

References ata_command::ata, ata_command::atadev, ata_command::block, DBGC, intf_shutdown(), rc, strerror(), and ata_command::tag.

Referenced by atacmd_identify_done(), atadev_close(), and atadev_command().

◆ atacmd_done()

static void atacmd_done ( struct ata_command atacmd,
int  rc 
)
static

Handle ATA command completion.

Parameters
atacmdATA command
rcReason for close

Definition at line 272 of file ata.c.

272  {
273 
274  /* Hand over to the command completion handler */
275  atacmd->type->done ( atacmd, rc );
276 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void(* done)(struct ata_command *atacmd, int rc)
Handle ATA command completion.
Definition: ata.c:172
struct ata_command_type * type
Command type.
Definition: ata.c:123

References ata_command_type::done, rc, and ata_command::type.

◆ atacmd_data_buffer()

static void atacmd_data_buffer ( struct ata_command *atacmd  __unused,
userptr_t  buffer,
size_t  len,
userptr_t data,
size_t data_len 
)
static

Use provided data buffer for ATA command.

Parameters
atacmdATA command
bufferAvailable buffer
lenAvailable buffer length
Return values
dataData buffer
data_lenData buffer length

Definition at line 287 of file ata.c.

289  {
290  *data = buffer;
291  *data_len = len;
292 }
uint32_t data_len
Microcode data size (or 0 to indicate 2000 bytes)
Definition: ucode.h:26
uint32_t buffer
Buffer index (or NETVSC_RNDIS_NO_BUFFER)
Definition: netvsc.h:16
uint32_t len
Length.
Definition: ena.h:14
uint8_t data[48]
Additional event data.
Definition: ena.h:22

References buffer, data, data_len, and len.

◆ atacmd_data_none()

static void atacmd_data_none ( struct ata_command *atacmd  __unused,
userptr_t buffer  __unused,
size_t len  __unused,
userptr_t *data  __unused,
size_t *data_len  __unused 
)
static

Use no data buffer for ATA command.

Parameters
atacmdATA command
bufferAvailable buffer
lenAvailable buffer length
Return values
dataData buffer
data_lenData buffer length

Definition at line 303 of file ata.c.

306  {
307  /* Nothing to do */
308 }

◆ atacmd_data_priv()

static void atacmd_data_priv ( struct ata_command atacmd,
userptr_t buffer  __unused,
size_t len  __unused,
userptr_t data,
size_t data_len 
)
static

Use private data buffer for ATA command.

Parameters
atacmdATA command
bufferAvailable buffer
lenAvailable buffer length
Return values
dataData buffer
data_lenData buffer length

Definition at line 319 of file ata.c.

321  {
322  *data = virt_to_user ( atacmd_priv ( atacmd ) );
323  *data_len = atacmd->type->priv_len;
324 }
size_t priv_len
Additional working space.
Definition: ata.c:136
uint32_t data_len
Microcode data size (or 0 to indicate 2000 bytes)
Definition: ucode.h:26
struct ata_command_type * type
Command type.
Definition: ata.c:123
userptr_t virt_to_user(volatile const void *addr)
Convert virtual address to user pointer.
uint8_t data[48]
Additional event data.
Definition: ena.h:22

References data, data_len, ata_command_type::priv_len, ata_command::type, and virt_to_user().

◆ ata_model()

static const char* ata_model ( struct ata_identity identity)
static

Return ATA model string (for debugging)

Parameters
identifyATA identity data
Return values
modelModel string

Definition at line 358 of file ata.c.

358  {
359  static union {
360  uint16_t words[ sizeof ( identity->model ) / 2 ];
361  char text[ sizeof ( identity->model ) + 1 /* NUL */ ];
362  } buf;
363  unsigned int i;
364 
365  for ( i = 0 ; i < ( sizeof ( identity->model ) / 2 ) ; i++ )
366  buf.words[i] = bswap_16 ( identity->model[i] );
367 
368  return buf.text;
369 }
unsigned short uint16_t
Definition: stdint.h:11
uint16_t model[20]
Definition: ata.h:151
#define bswap_16(value)
Definition: byteswap.h:58

References bswap_16, and ata_identity::model.

Referenced by atacmd_identify_done().

◆ atacmd_identify_done()

static void atacmd_identify_done ( struct ata_command atacmd,
int  rc 
)
static

Handle ATA IDENTIFY command completion.

Parameters
atacmdATA command
rcReason for completion

Definition at line 377 of file ata.c.

377  {
378  struct ata_device *atadev = atacmd->atadev;
379  struct ata_identify_private *priv = atacmd_priv ( atacmd );
380  struct ata_identity *identity = &priv->identity;
381  struct block_device_capacity capacity;
382 
383  /* Close if command failed */
384  if ( rc != 0 ) {
385  atacmd_close ( atacmd, rc );
386  return;
387  }
388 
389  /* Extract capacity */
390  if ( identity->supports_lba48 & cpu_to_le16 ( ATA_SUPPORTS_LBA48 ) ) {
391  atadev->lba48 = 1;
392  capacity.blocks = le64_to_cpu ( identity->lba48_sectors );
393  } else {
394  capacity.blocks = le32_to_cpu ( identity->lba_sectors );
395  }
396  capacity.blksize = ATA_SECTOR_SIZE;
397  capacity.max_count = atadev->max_count;
398  DBGC ( atadev, "ATA %p is a %s\n", atadev, ata_model ( identity ) );
399  DBGC ( atadev, "ATA %p has %#llx blocks (%ld MB) and uses %s\n",
400  atadev, capacity.blocks,
401  ( ( signed long ) ( capacity.blocks >> 11 ) ),
402  ( atadev->lba48 ? "LBA48" : "LBA" ) );
403 
404  /* Return capacity to caller */
405  block_capacity ( &atacmd->block, &capacity );
406 
407  /* Close command */
408  atacmd_close ( atacmd, 0 );
409 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define le32_to_cpu(value)
Definition: byteswap.h:113
struct ata_device * atadev
ATA device.
Definition: ata.c:113
uint32_t lba_sectors
Definition: ata.h:153
void block_capacity(struct interface *intf, struct block_device_capacity *capacity)
Report block device capacity.
Definition: blockdev.c:129
static void atacmd_close(struct ata_command *atacmd, int rc)
Close ATA command.
Definition: ata.c:253
#define DBGC(...)
Definition: compiler.h:505
Structure returned by ATA IDENTIFY command.
Definition: ata.h:149
An ATA device.
Definition: ata.c:89
ATA IDENTIFY private data.
Definition: ata.c:347
uint64_t lba48_sectors
Definition: ata.h:157
unsigned int max_count
Maximum number of blocks per single transfer.
Definition: ata.c:103
int lba48
Device uses LBA48 extended addressing.
Definition: ata.c:105
static const char * ata_model(struct ata_identity *identity)
Return ATA model string (for debugging)
Definition: ata.c:358
Block device capacity.
Definition: blockdev.h:18
static struct tlan_private * priv
Definition: tlan.c:224
#define cpu_to_le16(value)
Definition: byteswap.h:106
uint16_t supports_lba48
Definition: ata.h:155
#define le64_to_cpu(value)
Definition: byteswap.h:114
#define ATA_SUPPORTS_LBA48
Supports LBA48 flag.
Definition: ata.h:162
struct interface block
Block data interface.
Definition: ata.c:118
#define ATA_SECTOR_SIZE
ATA sector size.
Definition: ata.h:165

References ata_model(), ATA_SECTOR_SIZE, ATA_SUPPORTS_LBA48, atacmd_close(), ata_command::atadev, block_device_capacity::blksize, ata_command::block, block_capacity(), block_device_capacity::blocks, cpu_to_le16, DBGC, ata_device::lba48, ata_identity::lba48_sectors, ata_identity::lba_sectors, le32_to_cpu, le64_to_cpu, block_device_capacity::max_count, ata_device::max_count, priv, rc, and ata_identity::supports_lba48.

◆ atadev_command()

static int atadev_command ( struct ata_device atadev,
struct interface block,
struct ata_command_type type,
uint64_t  lba,
unsigned int  count,
userptr_t  buffer,
size_t  len 
)
static

Create ATA command.

Parameters
atadevATA device
blockBlock data interface
typeATA command type
lbaStarting logical block address
countNumber of blocks to transfer
bufferData buffer
lenLength of data buffer
Return values
rcReturn status code

Definition at line 454 of file ata.c.

458  {
459  struct ata_command *atacmd;
460  struct ata_cmd command;
461  int tag;
462  int rc;
463 
464  /* Allocate and initialise structure */
465  atacmd = zalloc ( sizeof ( *atacmd ) + type->priv_len );
466  if ( ! atacmd ) {
467  rc = -ENOMEM;
468  goto err_zalloc;
469  }
470  ref_init ( &atacmd->refcnt, atacmd_free );
471  intf_init ( &atacmd->block, &atacmd_block_desc, &atacmd->refcnt );
472  intf_init ( &atacmd->ata, &atacmd_ata_desc,
473  &atacmd->refcnt );
474  atacmd->atadev = atadev_get ( atadev );
475  list_add ( &atacmd->list, &ata_commands );
476  atacmd->type = type;
477 
478  /* Sanity check */
479  if ( len != ( count * ATA_SECTOR_SIZE ) ) {
480  DBGC ( atadev, "ATA %p tag %08x buffer length mismatch (count "
481  "%d len %zd)\n", atadev, atacmd->tag, count, len );
482  rc = -EINVAL;
483  goto err_len;
484  }
485 
486  /* Construct command */
487  memset ( &command, 0, sizeof ( command ) );
488  command.cb.lba.native = lba;
489  command.cb.count.native = count;
490  command.cb.device = ( atadev->device | ATA_DEV_OBSOLETE | ATA_DEV_LBA );
491  command.cb.lba48 = atadev->lba48;
492  if ( ! atadev->lba48 )
493  command.cb.device |= command.cb.lba.bytes.low_prev;
494  command.cb.cmd_stat =
495  ( atadev->lba48 ? type->cmd_lba48 : type->cmd_lba );
496  type->data_in ( atacmd, buffer, len,
497  &command.data_in, &command.data_in_len );
498  type->data_out ( atacmd, buffer, len,
499  &command.data_out, &command.data_out_len );
500 
501  /* Issue command */
502  if ( ( tag = ata_command ( &atadev->ata, &atacmd->ata,
503  &command ) ) < 0 ) {
504  rc = tag;
505  DBGC ( atadev, "ATA %p tag %08x could not issue command: %s\n",
506  atadev, atacmd->tag, strerror ( rc ) );
507  goto err_command;
508  }
509  atacmd->tag = tag;
510 
511  DBGC2 ( atadev, "ATA %p tag %08x %s cmd %02x dev %02x LBA%s %08llx "
512  "count %04x\n", atadev, atacmd->tag, atacmd->type->name,
513  command.cb.cmd_stat, command.cb.device,
514  ( command.cb.lba48 ? "48" : "" ),
515  ( unsigned long long ) command.cb.lba.native,
516  command.cb.count.native );
517 
518  /* Attach to parent interface, mortalise self, and return */
519  intf_plug_plug ( &atacmd->block, block );
520  ref_put ( &atacmd->refcnt );
521  return 0;
522 
523  err_command:
524  err_len:
525  atacmd_close ( atacmd, rc );
526  ref_put ( &atacmd->refcnt );
527  err_zalloc:
528  return rc;
529 }
#define EINVAL
Invalid argument.
Definition: errno.h:428
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint32_t lba
Start address.
Definition: scsi.h:23
static void atacmd_free(struct refcnt *refcnt)
Free ATA command.
Definition: ata.c:235
struct ata_device * atadev
ATA device.
Definition: ata.c:113
#define list_add(new, head)
Add a new entry to the head of a list.
Definition: list.h:69
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition: refcnt.h:64
A command-line command.
Definition: command.h:9
static void atacmd_close(struct ata_command *atacmd, int rc)
Close ATA command.
Definition: ata.c:253
#define DBGC(...)
Definition: compiler.h:505
void intf_plug_plug(struct interface *a, struct interface *b)
Plug two object interfaces together.
Definition: interface.c:107
uint32_t buffer
Buffer index (or NETVSC_RNDIS_NO_BUFFER)
Definition: netvsc.h:16
unsigned int device
Device number.
Definition: ata.c:101
static struct interface_descriptor atacmd_ata_desc
ATA command ATA interface descriptor.
Definition: ata.c:438
struct refcnt refcnt
Reference count.
Definition: ata.c:111
#define ENOMEM
Not enough space.
Definition: errno.h:534
An ATA command information unit.
Definition: ata.h:168
#define ATA_DEV_OBSOLETE
Obsolete bits in the ATA device register.
Definition: ata.h:111
struct list_head list
List of ATA commands.
Definition: ata.c:115
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
struct interface ata
ATA data interface.
Definition: ata.c:120
int lba48
Device uses LBA48 extended addressing.
Definition: ata.c:105
#define ATA_DEV_LBA
LBA flag in the ATA device register.
Definition: ata.h:114
struct interface ata
ATA control interface.
Definition: ata.c:95
uint32_t len
Length.
Definition: ena.h:14
uint32_t type
Operating system type.
Definition: ena.h:12
#define DBGC2(...)
Definition: compiler.h:522
uint8_t block[3][8]
DES-encrypted blocks.
Definition: mschapv2.h:12
struct ata_command_type * type
Command type.
Definition: ata.c:123
uint16_t count
Number of entries.
Definition: ena.h:22
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition: interface.h:203
uint64_t tag
Identity tag.
Definition: edd.h:30
struct interface block
Block data interface.
Definition: ata.c:118
An ATA command.
Definition: ata.c:109
const char * name
Name.
Definition: ata.c:134
static struct interface_descriptor atacmd_block_desc
ATA command block interface descriptor.
Definition: ata.c:428
uint32_t tag
Command tag.
Definition: ata.c:125
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106
void * memset(void *dest, int character, size_t len) __nonnull
#define ATA_SECTOR_SIZE
ATA sector size.
Definition: ata.h:165

References ata_command::ata, ata_device::ata, ATA_DEV_LBA, ATA_DEV_OBSOLETE, ATA_SECTOR_SIZE, atacmd_ata_desc, atacmd_block_desc, atacmd_close(), atacmd_free(), ata_command::atadev, block, ata_command::block, buffer, count, DBGC, DBGC2, ata_device::device, EINVAL, ENOMEM, intf_init(), intf_plug_plug(), lba, ata_device::lba48, len, ata_command::list, list_add, memset(), ata_command_type::name, rc, ref_init, ref_put, ata_command::refcnt, strerror(), tag, ata_command::tag, type, ata_command::type, and zalloc().

Referenced by atadev_read(), atadev_read_capacity(), and atadev_write().

◆ atadev_read()

static int atadev_read ( struct ata_device atadev,
struct interface block,
uint64_t  lba,
unsigned int  count,
userptr_t  buffer,
size_t  len 
)
static

Issue ATA block read.

Parameters
atadevATA device
blockBlock data interface
lbaStarting logical block address
countNumber of blocks to transfer
bufferData buffer
lenLength of data buffer
Return values
rcReturn status code

Definition at line 543 of file ata.c.

546  {
547  return atadev_command ( atadev, block, &atacmd_read,
548  lba, count, buffer, len );
549 }
uint32_t lba
Start address.
Definition: scsi.h:23
uint32_t buffer
Buffer index (or NETVSC_RNDIS_NO_BUFFER)
Definition: netvsc.h:16
static int atadev_command(struct ata_device *atadev, struct interface *block, struct ata_command_type *type, uint64_t lba, unsigned int count, userptr_t buffer, size_t len)
Create ATA command.
Definition: ata.c:454
uint32_t len
Length.
Definition: ena.h:14
static struct ata_command_type atacmd_read
ATA READ command type.
Definition: ata.c:327
uint8_t block[3][8]
DES-encrypted blocks.
Definition: mschapv2.h:12
uint16_t count
Number of entries.
Definition: ena.h:22

References atacmd_read, atadev_command(), block, buffer, count, lba, and len.

◆ atadev_write()

static int atadev_write ( struct ata_device atadev,
struct interface block,
uint64_t  lba,
unsigned int  count,
userptr_t  buffer,
size_t  len 
)
static

Issue ATA block write.

Parameters
atadevATA device
blockBlock data interface
lbaStarting logical block address
countNumber of blocks to transfer
bufferData buffer
lenLength of data buffer
Return values
rcReturn status code

Definition at line 562 of file ata.c.

565  {
566  return atadev_command ( atadev, block, &atacmd_write,
567  lba, count, buffer, len );
568 }
uint32_t lba
Start address.
Definition: scsi.h:23
uint32_t buffer
Buffer index (or NETVSC_RNDIS_NO_BUFFER)
Definition: netvsc.h:16
static int atadev_command(struct ata_device *atadev, struct interface *block, struct ata_command_type *type, uint64_t lba, unsigned int count, userptr_t buffer, size_t len)
Create ATA command.
Definition: ata.c:454
uint32_t len
Length.
Definition: ena.h:14
uint8_t block[3][8]
DES-encrypted blocks.
Definition: mschapv2.h:12
uint16_t count
Number of entries.
Definition: ena.h:22
static struct ata_command_type atacmd_write
ATA WRITE command type.
Definition: ata.c:337

References atacmd_write, atadev_command(), block, buffer, count, lba, and len.

◆ atadev_read_capacity()

static int atadev_read_capacity ( struct ata_device atadev,
struct interface block 
)
static

Read ATA device capacity.

Parameters
atadevATA device
blockBlock data interface
Return values
rcReturn status code

Definition at line 577 of file ata.c.

578  {
579  struct ata_identity *identity;
580 
581  assert ( atacmd_identify.priv_len == sizeof ( *identity ) );
583  return atadev_command ( atadev, block, &atacmd_identify,
584  0, 1, UNULL, ATA_SECTOR_SIZE );
585 }
size_t priv_len
Additional working space.
Definition: ata.c:136
Structure returned by ATA IDENTIFY command.
Definition: ata.h:149
static int atadev_command(struct ata_device *atadev, struct interface *block, struct ata_command_type *type, uint64_t lba, unsigned int count, userptr_t buffer, size_t len)
Create ATA command.
Definition: ata.c:454
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static struct ata_command_type atacmd_identify
ATA IDENTITY command type.
Definition: ata.c:412
#define UNULL
Equivalent of NULL for user pointers.
Definition: uaccess.h:36
uint8_t block[3][8]
DES-encrypted blocks.
Definition: mschapv2.h:12
#define ATA_SECTOR_SIZE
ATA sector size.
Definition: ata.h:165

References assert(), ATA_SECTOR_SIZE, atacmd_identify, atadev_command(), block, ata_command_type::priv_len, and UNULL.

◆ atadev_close()

static void atadev_close ( struct ata_device atadev,
int  rc 
)
static

Close ATA device.

Parameters
atadevATA device
rcReason for close

Definition at line 593 of file ata.c.

593  {
594  struct ata_command *atacmd;
595  struct ata_command *tmp;
596 
597  /* Shut down interfaces */
598  intf_shutdown ( &atadev->block, rc );
599  intf_shutdown ( &atadev->ata, rc );
600 
601  /* Shut down any remaining commands */
602  list_for_each_entry_safe ( atacmd, tmp, &ata_commands, list ) {
603  if ( atacmd->atadev != atadev )
604  continue;
605  atacmd_get ( atacmd );
606  atacmd_close ( atacmd, rc );
607  atacmd_put ( atacmd );
608  }
609 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void intf_shutdown(struct interface *intf, int rc)
Shut down an object interface.
Definition: interface.c:278
struct ata_device * atadev
ATA device.
Definition: ata.c:113
static void atacmd_close(struct ata_command *atacmd, int rc)
Close ATA command.
Definition: ata.c:253
unsigned long tmp
Definition: linux_pci.h:53
struct interface block
Block control interface.
Definition: ata.c:93
struct list_head list
List of ATA commands.
Definition: ata.c:115
#define list_for_each_entry_safe(pos, tmp, head, member)
Iterate over entries in a list, safe against deletion of the current entry.
Definition: list.h:458
struct interface ata
ATA control interface.
Definition: ata.c:95
An ATA command.
Definition: ata.c:109

References ata_device::ata, atacmd_close(), ata_command::atadev, ata_device::block, intf_shutdown(), ata_command::list, list_for_each_entry_safe, rc, and tmp.

◆ atadev_edd_describe()

static int atadev_edd_describe ( struct ata_device atadev,
struct edd_interface_type type,
union edd_device_path path 
)
static

Describe ATA device using EDD.

Parameters
atadevATA device
typeEDD interface type
pathEDD device path
Return values
rcReturn status code

Definition at line 619 of file ata.c.

621  {
622 
623  type->type = cpu_to_le64 ( EDD_INTF_TYPE_ATA );
624  path->ata.slave = ( ( atadev->device == ATA_DEV_SLAVE ) ? 0x01 : 0x00 );
625  return 0;
626 }
#define EDD_INTF_TYPE_ATA
EDD ATA interface type.
Definition: edd.h:55
struct ata_device * atadev
ATA device.
Definition: ata.c:113
#define cpu_to_le64(value)
Definition: byteswap.h:108
unsigned int device
Device number.
Definition: ata.c:101
uint32_t type
Operating system type.
Definition: ena.h:12
uint8_t slave
Slave.
Definition: edd.h:102
#define ATA_DEV_SLAVE
Slave ("device 1") flag in the ATA device register.
Definition: ata.h:117

References ATA_DEV_SLAVE, ata_command::atadev, cpu_to_le64, ata_device::device, EDD_INTF_TYPE_ATA, edd_device_path::slave, and type.

◆ ata_open()

int ata_open ( struct interface block,
struct interface ata,
unsigned int  device,
unsigned int  max_count 
)

Open ATA device.

Parameters
blockBlock control interface
ataATA control interface
deviceATA device number
max_countMaximum number of blocks per single transfer
Return values
rcReturn status code

Definition at line 662 of file ata.c.

663  {
664  struct ata_device *atadev;
665 
666  /* Allocate and initialise structure */
667  atadev = zalloc ( sizeof ( *atadev ) );
668  if ( ! atadev )
669  return -ENOMEM;
670  ref_init ( &atadev->refcnt, NULL );
671  intf_init ( &atadev->block, &atadev_block_desc, &atadev->refcnt );
672  intf_init ( &atadev->ata, &atadev_ata_desc, &atadev->refcnt );
673  atadev->device = device;
674  atadev->max_count = max_count;
675 
676  /* Attach to ATA and parent and interfaces, mortalise self,
677  * and return
678  */
679  intf_plug_plug ( &atadev->ata, ata );
680  intf_plug_plug ( &atadev->block, block );
681  ref_put ( &atadev->refcnt );
682  return 0;
683 }
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition: refcnt.h:64
void intf_plug_plug(struct interface *a, struct interface *b)
Plug two object interfaces together.
Definition: interface.c:107
unsigned int device
Device number.
Definition: ata.c:101
uint16_t device
Device ID.
Definition: ena.h:24
static struct interface_descriptor atadev_block_desc
ATA device block interface descriptor.
Definition: ata.c:639
An ATA device.
Definition: ata.c:89
#define ENOMEM
Not enough space.
Definition: errno.h:534
struct interface block
Block control interface.
Definition: ata.c:93
struct refcnt refcnt
Reference count.
Definition: ata.c:91
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
unsigned int max_count
Maximum number of blocks per single transfer.
Definition: ata.c:103
struct interface ata
ATA control interface.
Definition: ata.c:95
uint8_t block[3][8]
DES-encrypted blocks.
Definition: mschapv2.h:12
static struct interface_descriptor atadev_ata_desc
ATA device ATA interface descriptor.
Definition: ata.c:649
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition: interface.h:203
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106

References ata_device::ata, atadev_ata_desc, atadev_block_desc, block, ata_device::block, device, ata_device::device, ENOMEM, intf_init(), intf_plug_plug(), ata_device::max_count, NULL, ref_init, ref_put, ata_device::refcnt, and zalloc().

Referenced by aoedev_open().

Variable Documentation

◆ atacmd_read

struct ata_command_type atacmd_read
static
Initial value:
= {
.name = "READ",
.cmd_lba = ATA_CMD_READ,
.cmd_lba48 = ATA_CMD_READ_EXT,
.data_in = atacmd_data_buffer,
.data_out = atacmd_data_none,
.done = atacmd_close,
}
static void atacmd_close(struct ata_command *atacmd, int rc)
Close ATA command.
Definition: ata.c:253
static void atacmd_data_buffer(struct ata_command *atacmd __unused, userptr_t buffer, size_t len, userptr_t *data, size_t *data_len)
Use provided data buffer for ATA command.
Definition: ata.c:287
static void atacmd_data_none(struct ata_command *atacmd __unused, userptr_t buffer __unused, size_t len __unused, userptr_t *data __unused, size_t *data_len __unused)
Use no data buffer for ATA command.
Definition: ata.c:303
#define ATA_CMD_READ_EXT
"Read sectors (ext)" command
Definition: ata.h:129
#define ATA_CMD_READ
"Read sectors" command
Definition: ata.h:126

ATA READ command type.

Definition at line 327 of file ata.c.

Referenced by atadev_read().

◆ atacmd_write

struct ata_command_type atacmd_write
static
Initial value:
= {
.name = "WRITE",
.cmd_lba = ATA_CMD_WRITE,
.cmd_lba48 = ATA_CMD_WRITE_EXT,
.data_in = atacmd_data_none,
.data_out = atacmd_data_buffer,
.done = atacmd_close,
}
static void atacmd_close(struct ata_command *atacmd, int rc)
Close ATA command.
Definition: ata.c:253
static void atacmd_data_buffer(struct ata_command *atacmd __unused, userptr_t buffer, size_t len, userptr_t *data, size_t *data_len)
Use provided data buffer for ATA command.
Definition: ata.c:287
static void atacmd_data_none(struct ata_command *atacmd __unused, userptr_t buffer __unused, size_t len __unused, userptr_t *data __unused, size_t *data_len __unused)
Use no data buffer for ATA command.
Definition: ata.c:303
#define ATA_CMD_WRITE
"Write sectors" command
Definition: ata.h:132
#define ATA_CMD_WRITE_EXT
"Write sectors (ext)" command
Definition: ata.h:135

ATA WRITE command type.

Definition at line 337 of file ata.c.

Referenced by atadev_write().

◆ atacmd_identify

struct ata_command_type atacmd_identify
static
Initial value:
= {
.name = "IDENTIFY",
.priv_len = sizeof ( struct ata_identify_private ),
.cmd_lba = ATA_CMD_IDENTIFY,
.cmd_lba48 = ATA_CMD_IDENTIFY,
.data_in = atacmd_data_priv,
.data_out = atacmd_data_none,
}
static void atacmd_data_none(struct ata_command *atacmd __unused, userptr_t buffer __unused, size_t len __unused, userptr_t *data __unused, size_t *data_len __unused)
Use no data buffer for ATA command.
Definition: ata.c:303
ATA IDENTIFY private data.
Definition: ata.c:347
#define ATA_CMD_IDENTIFY
"Identify" command
Definition: ata.h:138
static void atacmd_data_priv(struct ata_command *atacmd, userptr_t buffer __unused, size_t len __unused, userptr_t *data, size_t *data_len)
Use private data buffer for ATA command.
Definition: ata.c:319
static void atacmd_identify_done(struct ata_command *atacmd, int rc)
Handle ATA IDENTIFY command completion.
Definition: ata.c:377

ATA IDENTITY command type.

Definition at line 412 of file ata.c.

Referenced by atadev_read_capacity().

◆ atacmd_block_op

struct interface_operation atacmd_block_op[]
static
Initial value:
= {
}
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition: interface.c:249
static void atacmd_close(struct ata_command *atacmd, int rc)
Close ATA command.
Definition: ata.c:253
#define INTF_OP(op_type, object_type, op_func)
Define an object interface operation.
Definition: interface.h:32
An ATA command.
Definition: ata.c:109

ATA command block interface operations.

Definition at line 423 of file ata.c.

◆ atacmd_block_desc

struct interface_descriptor atacmd_block_desc
static
Initial value:
=
static struct interface_operation atacmd_block_op[]
ATA command block interface operations.
Definition: ata.c:423
uint8_t block[3][8]
DES-encrypted blocks.
Definition: mschapv2.h:12
#define INTF_DESC_PASSTHRU(object_type, intf, operations, passthru)
Define an object interface descriptor with pass-through interface.
Definition: interface.h:97
An ATA command.
Definition: ata.c:109

ATA command block interface descriptor.

Definition at line 428 of file ata.c.

Referenced by atadev_command().

◆ atacmd_ata_op

struct interface_operation atacmd_ata_op[]
static
Initial value:
= {
}
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition: interface.c:249
static void atacmd_done(struct ata_command *atacmd, int rc)
Handle ATA command completion.
Definition: ata.c:272
#define INTF_OP(op_type, object_type, op_func)
Define an object interface operation.
Definition: interface.h:32
An ATA command.
Definition: ata.c:109

ATA command ATA interface operations.

Definition at line 433 of file ata.c.

◆ atacmd_ata_desc

struct interface_descriptor atacmd_ata_desc
static
Initial value:
=
static struct interface_operation atacmd_ata_op[]
ATA command ATA interface operations.
Definition: ata.c:433
uint8_t block[3][8]
DES-encrypted blocks.
Definition: mschapv2.h:12
#define INTF_DESC_PASSTHRU(object_type, intf, operations, passthru)
Define an object interface descriptor with pass-through interface.
Definition: interface.h:97
An ATA command.
Definition: ata.c:109

ATA command ATA interface descriptor.

Definition at line 438 of file ata.c.

Referenced by atadev_command().

◆ atadev_block_op

struct interface_operation atadev_block_op[]
static
Initial value:
= {
}
int block_write(struct interface *control, struct interface *data, uint64_t lba, unsigned int count, userptr_t buffer, size_t len)
Write to block device.
Definition: blockdev.c:78
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition: interface.c:249
int edd_describe(struct interface *intf, struct edd_interface_type *type, union edd_device_path *path)
Describe a disk device using EDD.
Definition: edd.c:44
static int atadev_read_capacity(struct ata_device *atadev, struct interface *block)
Read ATA device capacity.
Definition: ata.c:577
int block_read(struct interface *control, struct interface *data, uint64_t lba, unsigned int count, userptr_t buffer, size_t len)
Read from block device.
Definition: blockdev.c:47
An ATA device.
Definition: ata.c:89
static int atadev_read(struct ata_device *atadev, struct interface *block, uint64_t lba, unsigned int count, userptr_t buffer, size_t len)
Issue ATA block read.
Definition: ata.c:543
static int atadev_write(struct ata_device *atadev, struct interface *block, uint64_t lba, unsigned int count, userptr_t buffer, size_t len)
Issue ATA block write.
Definition: ata.c:562
static int atadev_edd_describe(struct ata_device *atadev, struct edd_interface_type *type, union edd_device_path *path)
Describe ATA device using EDD.
Definition: ata.c:619
#define INTF_OP(op_type, object_type, op_func)
Define an object interface operation.
Definition: interface.h:32
int block_read_capacity(struct interface *control, struct interface *data)
Read block device capacity.
Definition: blockdev.c:105
static void atadev_close(struct ata_device *atadev, int rc)
Close ATA device.
Definition: ata.c:593

ATA device block interface operations.

Definition at line 629 of file ata.c.

◆ atadev_block_desc

struct interface_descriptor atadev_block_desc
static
Initial value:
=
An ATA device.
Definition: ata.c:89
static struct interface_operation atadev_block_op[]
ATA device block interface operations.
Definition: ata.c:629
uint8_t block[3][8]
DES-encrypted blocks.
Definition: mschapv2.h:12
#define INTF_DESC_PASSTHRU(object_type, intf, operations, passthru)
Define an object interface descriptor with pass-through interface.
Definition: interface.h:97

ATA device block interface descriptor.

Definition at line 639 of file ata.c.

Referenced by ata_open().

◆ atadev_ata_op

struct interface_operation atadev_ata_op[]
static
Initial value:
= {
}
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition: interface.c:249
An ATA device.
Definition: ata.c:89
#define INTF_OP(op_type, object_type, op_func)
Define an object interface operation.
Definition: interface.h:32
static void atadev_close(struct ata_device *atadev, int rc)
Close ATA device.
Definition: ata.c:593

ATA device ATA interface operations.

Definition at line 644 of file ata.c.

◆ atadev_ata_desc

struct interface_descriptor atadev_ata_desc
static
Initial value:
=
An ATA device.
Definition: ata.c:89
static struct interface_operation atadev_ata_op[]
ATA device ATA interface operations.
Definition: ata.c:644
uint8_t block[3][8]
DES-encrypted blocks.
Definition: mschapv2.h:12
#define INTF_DESC_PASSTHRU(object_type, intf, operations, passthru)
Define an object interface descriptor with pass-through interface.
Definition: interface.h:97

ATA device ATA interface descriptor.

Definition at line 649 of file ata.c.

Referenced by ata_open().