iPXE
aoe.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006 Michael Brown <mbrown@fensystems.co.uk>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  *
19  * You can also choose to distribute this program under the terms of
20  * the Unmodified Binary Distribution Licence (as given in the file
21  * COPYING.UBDL), provided that you have satisfied its requirements.
22  */
23 
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25 
26 #include <stddef.h>
27 #include <string.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <errno.h>
31 #include <assert.h>
32 #include <byteswap.h>
33 #include <ipxe/list.h>
34 #include <ipxe/if_ether.h>
35 #include <ipxe/iobuf.h>
36 #include <ipxe/uaccess.h>
37 #include <ipxe/netdevice.h>
38 #include <ipxe/features.h>
39 #include <ipxe/interface.h>
40 #include <ipxe/xfer.h>
41 #include <ipxe/uri.h>
42 #include <ipxe/open.h>
43 #include <ipxe/ata.h>
44 #include <ipxe/device.h>
45 #include <ipxe/efi/efi_path.h>
46 #include <ipxe/aoe.h>
47 
48 /** @file
49  *
50  * AoE protocol
51  *
52  */
53 
55 
56 struct net_protocol aoe_protocol __net_protocol;
57 struct acpi_model abft_model __acpi_model;
58 
59 /******************************************************************************
60  *
61  * AoE devices and commands
62  *
63  ******************************************************************************
64  */
65 
66 /** List of all AoE devices */
67 static LIST_HEAD ( aoe_devices );
68 
69 /** List of active AoE commands */
70 static LIST_HEAD ( aoe_commands );
71 
72 /** An AoE command */
73 struct aoe_command {
74  /** Reference count */
75  struct refcnt refcnt;
76  /** AOE device */
77  struct aoe_device *aoedev;
78  /** List of active commands */
79  struct list_head list;
80 
81  /** ATA command interface */
82  struct interface ata;
83 
84  /** ATA command */
85  struct ata_cmd command;
86  /** Command type */
88  /** Command tag */
90 
91  /** Retransmission timer */
93 };
94 
95 /** An AoE command type */
97  /**
98  * Calculate length of AoE command IU
99  *
100  * @v aoecmd AoE command
101  * @ret len Length of command IU
102  */
103  size_t ( * cmd_len ) ( struct aoe_command *aoecmd );
104  /**
105  * Build AoE command IU
106  *
107  * @v aoecmd AoE command
108  * @v data Command IU
109  * @v len Length of command IU
110  */
111  void ( * cmd ) ( struct aoe_command *aoecmd, void *data, size_t len );
112  /**
113  * Handle AoE response IU
114  *
115  * @v aoecmd AoE command
116  * @v data Response IU
117  * @v len Length of response IU
118  * @v ll_source Link-layer source address
119  * @ret rc Return status code
120  */
121  int ( * rsp ) ( struct aoe_command *aoecmd, const void *data,
122  size_t len, const void *ll_source );
123 };
124 
125 /**
126  * Get reference to AoE device
127  *
128  * @v aoedev AoE device
129  * @ret aoedev AoE device
130  */
131 static inline __attribute__ (( always_inline )) struct aoe_device *
132 aoedev_get ( struct aoe_device *aoedev ) {
133  ref_get ( &aoedev->refcnt );
134  return aoedev;
135 }
136 
137 /**
138  * Drop reference to AoE device
139  *
140  * @v aoedev AoE device
141  */
142 static inline __attribute__ (( always_inline )) void
143 aoedev_put ( struct aoe_device *aoedev ) {
144  ref_put ( &aoedev->refcnt );
145 }
146 
147 /**
148  * Get reference to AoE command
149  *
150  * @v aoecmd AoE command
151  * @ret aoecmd AoE command
152  */
153 static inline __attribute__ (( always_inline )) struct aoe_command *
155  ref_get ( &aoecmd->refcnt );
156  return aoecmd;
157 }
158 
159 /**
160  * Drop reference to AoE command
161  *
162  * @v aoecmd AoE command
163  */
164 static inline __attribute__ (( always_inline )) void
166  ref_put ( &aoecmd->refcnt );
167 }
168 
169 /**
170  * Name AoE device
171  *
172  * @v aoedev AoE device
173  * @ret name AoE device name
174  */
175 static const char * aoedev_name ( struct aoe_device *aoedev ) {
176  static char buf[16];
177 
178  snprintf ( buf, sizeof ( buf ), "%s/e%d.%d", aoedev->netdev->name,
179  aoedev->major, aoedev->minor );
180  return buf;
181 }
182 
183 /**
184  * Free AoE command
185  *
186  * @v refcnt Reference counter
187  */
188 static void aoecmd_free ( struct refcnt *refcnt ) {
189  struct aoe_command *aoecmd =
190  container_of ( refcnt, struct aoe_command, refcnt );
191 
192  assert ( ! timer_running ( &aoecmd->timer ) );
193  assert ( list_empty ( &aoecmd->list ) );
194 
195  aoedev_put ( aoecmd->aoedev );
196  free ( aoecmd );
197 }
198 
199 /**
200  * Close AoE command
201  *
202  * @v aoecmd AoE command
203  * @v rc Reason for close
204  */
205 static void aoecmd_close ( struct aoe_command *aoecmd, int rc ) {
206  struct aoe_device *aoedev = aoecmd->aoedev;
207 
208  /* Stop timer */
209  stop_timer ( &aoecmd->timer );
210 
211  /* Preserve the timeout value for subsequent commands */
212  aoedev->timeout = aoecmd->timer.timeout;
213 
214  /* Remove from list of commands */
215  if ( ! list_empty ( &aoecmd->list ) ) {
216  list_del ( &aoecmd->list );
217  INIT_LIST_HEAD ( &aoecmd->list );
218  aoecmd_put ( aoecmd );
219  }
220 
221  /* Shut down interfaces */
222  intf_shutdown ( &aoecmd->ata, rc );
223 }
224 
225 /**
226  * Transmit AoE command request
227  *
228  * @v aoecmd AoE command
229  * @ret rc Return status code
230  */
231 static int aoecmd_tx ( struct aoe_command *aoecmd ) {
232  struct aoe_device *aoedev = aoecmd->aoedev;
233  struct net_device *netdev = aoedev->netdev;
234  struct io_buffer *iobuf;
235  struct aoehdr *aoehdr;
236  size_t cmd_len;
237  int rc;
238 
239  /* Sanity check */
240  assert ( netdev != NULL );
241 
242  /* If we are transmitting anything that requires a response,
243  * start the retransmission timer. Do this before attempting
244  * to allocate the I/O buffer, in case allocation itself
245  * fails.
246  */
247  start_timer ( &aoecmd->timer );
248 
249  /* Create outgoing I/O buffer */
250  cmd_len = aoecmd->type->cmd_len ( aoecmd );
251  iobuf = alloc_iob ( MAX_LL_HEADER_LEN + cmd_len );
252  if ( ! iobuf )
253  return -ENOMEM;
254  iob_reserve ( iobuf, MAX_LL_HEADER_LEN );
255  aoehdr = iob_put ( iobuf, cmd_len );
256 
257  /* Fill AoE header */
258  memset ( aoehdr, 0, sizeof ( *aoehdr ) );
260  aoehdr->major = htons ( aoedev->major );
261  aoehdr->minor = aoedev->minor;
262  aoehdr->tag = htonl ( aoecmd->tag );
263  aoecmd->type->cmd ( aoecmd, iobuf->data, iob_len ( iobuf ) );
264 
265  /* Send packet */
266  if ( ( rc = net_tx ( iobuf, netdev, &aoe_protocol, aoedev->target,
267  netdev->ll_addr ) ) != 0 ) {
268  DBGC ( aoedev, "AoE %s/%08x could not transmit: %s\n",
269  aoedev_name ( aoedev ), aoecmd->tag,
270  strerror ( rc ) );
271  return rc;
272  }
273 
274  return 0;
275 }
276 
277 /**
278  * Receive AoE command response
279  *
280  * @v aoecmd AoE command
281  * @v iobuf I/O buffer
282  * @v ll_source Link-layer source address
283  * @ret rc Return status code
284  */
285 static int aoecmd_rx ( struct aoe_command *aoecmd, struct io_buffer *iobuf,
286  const void *ll_source ) {
287  struct aoe_device *aoedev = aoecmd->aoedev;
288  struct aoehdr *aoehdr = iobuf->data;
289  int rc;
290 
291  /* Sanity check */
292  if ( iob_len ( iobuf ) < sizeof ( *aoehdr ) ) {
293  DBGC ( aoedev, "AoE %s/%08x received underlength response "
294  "(%zd bytes)\n", aoedev_name ( aoedev ),
295  aoecmd->tag, iob_len ( iobuf ) );
296  rc = -EINVAL;
297  goto done;
298  }
299  if ( ( ntohs ( aoehdr->major ) != aoedev->major ) ||
300  ( aoehdr->minor != aoedev->minor ) ) {
301  DBGC ( aoedev, "AoE %s/%08x received response for incorrect "
302  "device e%d.%d\n", aoedev_name ( aoedev ), aoecmd->tag,
303  ntohs ( aoehdr->major ), aoehdr->minor );
304  rc = -EINVAL;
305  goto done;
306  }
307 
308  /* Catch command failures */
309  if ( aoehdr->ver_flags & AOE_FL_ERROR ) {
310  DBGC ( aoedev, "AoE %s/%08x terminated in error\n",
311  aoedev_name ( aoedev ), aoecmd->tag );
312  aoecmd_close ( aoecmd, -EIO );
313  rc = -EIO;
314  goto done;
315  }
316 
317  /* Hand off to command completion handler */
318  if ( ( rc = aoecmd->type->rsp ( aoecmd, iobuf->data, iob_len ( iobuf ),
319  ll_source ) ) != 0 )
320  goto done;
321 
322  done:
323  /* Free I/O buffer */
324  free_iob ( iobuf );
325 
326  /* Terminate command */
327  aoecmd_close ( aoecmd, rc );
328 
329  return rc;
330 }
331 
332 /**
333  * Handle AoE retry timer expiry
334  *
335  * @v timer AoE retry timer
336  * @v fail Failure indicator
337  */
338 static void aoecmd_expired ( struct retry_timer *timer, int fail ) {
339  struct aoe_command *aoecmd =
340  container_of ( timer, struct aoe_command, timer );
341 
342  if ( fail ) {
344  } else {
345  aoecmd_tx ( aoecmd );
346  }
347 }
348 
349 /**
350  * Calculate length of AoE ATA command IU
351  *
352  * @v aoecmd AoE command
353  * @ret len Length of command IU
354  */
355 static size_t aoecmd_ata_cmd_len ( struct aoe_command *aoecmd ) {
356  struct ata_cmd *command = &aoecmd->command;
357 
358  return ( sizeof ( struct aoehdr ) + sizeof ( struct aoeata ) +
359  command->data_out_len );
360 }
361 
362 /**
363  * Build AoE ATA command IU
364  *
365  * @v aoecmd AoE command
366  * @v data Command IU
367  * @v len Length of command IU
368  */
369 static void aoecmd_ata_cmd ( struct aoe_command *aoecmd,
370  void *data, size_t len ) {
371  struct aoe_device *aoedev = aoecmd->aoedev;
372  struct ata_cmd *command = &aoecmd->command;
373  struct aoehdr *aoehdr = data;
374  struct aoeata *aoeata = &aoehdr->payload[0].ata;
375 
376  /* Sanity check */
378  assert ( len == ( sizeof ( *aoehdr ) + sizeof ( *aoeata ) +
379  command->data_out_len ) );
380 
381  /* Build IU */
383  memset ( aoeata, 0, sizeof ( *aoeata ) );
384  aoeata->aflags = ( ( command->cb.lba48 ? AOE_FL_EXTENDED : 0 ) |
385  ( command->cb.device & ATA_DEV_SLAVE ) |
386  ( command->data_out_len ? AOE_FL_WRITE : 0 ) );
387  aoeata->err_feat = command->cb.err_feat.bytes.cur;
388  aoeata->count = command->cb.count.native;
389  aoeata->cmd_stat = command->cb.cmd_stat;
390  aoeata->lba.u64 = cpu_to_le64 ( command->cb.lba.native );
391  if ( ! command->cb.lba48 )
392  aoeata->lba.bytes[3] |=
393  ( command->cb.device & ATA_DEV_MASK );
394  copy_from_user ( aoeata->data, command->data_out, 0,
395  command->data_out_len );
396 
397  DBGC2 ( aoedev, "AoE %s/%08x ATA cmd %02x:%02x:%02x:%02x:%08llx",
398  aoedev_name ( aoedev ), aoecmd->tag, aoeata->aflags,
400  aoeata->lba.u64 );
401  if ( command->data_out_len )
402  DBGC2 ( aoedev, " out %04zx", command->data_out_len );
403  if ( command->data_in_len )
404  DBGC2 ( aoedev, " in %04zx", command->data_in_len );
405  DBGC2 ( aoedev, "\n" );
406 }
407 
408 /**
409  * Handle AoE ATA response IU
410  *
411  * @v aoecmd AoE command
412  * @v data Response IU
413  * @v len Length of response IU
414  * @v ll_source Link-layer source address
415  * @ret rc Return status code
416  */
417 static int aoecmd_ata_rsp ( struct aoe_command *aoecmd, const void *data,
418  size_t len, const void *ll_source __unused ) {
419  struct aoe_device *aoedev = aoecmd->aoedev;
420  struct ata_cmd *command = &aoecmd->command;
421  const struct aoehdr *aoehdr = data;
422  const struct aoeata *aoeata = &aoehdr->payload[0].ata;
423  size_t data_len;
424 
425  /* Sanity check */
426  if ( len < ( sizeof ( *aoehdr ) + sizeof ( *aoeata ) ) ) {
427  DBGC ( aoedev, "AoE %s/%08x received underlength ATA response "
428  "(%zd bytes)\n", aoedev_name ( aoedev ),
429  aoecmd->tag, len );
430  return -EINVAL;
431  }
432  data_len = ( len - ( sizeof ( *aoehdr ) + sizeof ( *aoeata ) ) );
433  DBGC2 ( aoedev, "AoE %s/%08x ATA rsp %02x in %04zx\n",
434  aoedev_name ( aoedev ), aoecmd->tag, aoeata->cmd_stat,
435  data_len );
436 
437  /* Check for command failure */
438  if ( aoeata->cmd_stat & ATA_STAT_ERR ) {
439  DBGC ( aoedev, "AoE %s/%08x status %02x\n",
440  aoedev_name ( aoedev ), aoecmd->tag, aoeata->cmd_stat );
441  return -EIO;
442  }
443 
444  /* Check data-in length is sufficient. (There may be trailing
445  * garbage due to Ethernet minimum-frame-size padding.)
446  */
447  if ( data_len < command->data_in_len ) {
448  DBGC ( aoedev, "AoE %s/%08x data-in underrun (received %zd, "
449  "expected %zd)\n", aoedev_name ( aoedev ), aoecmd->tag,
450  data_len, command->data_in_len );
451  return -ERANGE;
452  }
453 
454  /* Copy out data payload */
455  copy_to_user ( command->data_in, 0, aoeata->data,
456  command->data_in_len );
457 
458  return 0;
459 }
460 
461 /** AoE ATA command */
462 static struct aoe_command_type aoecmd_ata = {
464  .cmd = aoecmd_ata_cmd,
465  .rsp = aoecmd_ata_rsp,
466 };
467 
468 /**
469  * Calculate length of AoE configuration command IU
470  *
471  * @v aoecmd AoE command
472  * @ret len Length of command IU
473  */
474 static size_t aoecmd_cfg_cmd_len ( struct aoe_command *aoecmd __unused ) {
475  return ( sizeof ( struct aoehdr ) + sizeof ( struct aoecfg ) );
476 }
477 
478 /**
479  * Build AoE configuration command IU
480  *
481  * @v aoecmd AoE command
482  * @v data Command IU
483  * @v len Length of command IU
484  */
485 static void aoecmd_cfg_cmd ( struct aoe_command *aoecmd,
486  void *data, size_t len ) {
487  struct aoe_device *aoedev = aoecmd->aoedev;
488  struct aoehdr *aoehdr = data;
489  struct aoecfg *aoecfg = &aoehdr->payload[0].cfg;
490 
491  /* Sanity check */
492  assert ( len == ( sizeof ( *aoehdr ) + sizeof ( *aoecfg ) ) );
493 
494  /* Build IU */
496  memset ( aoecfg, 0, sizeof ( *aoecfg ) );
497 
498  DBGC ( aoedev, "AoE %s/%08x CONFIG cmd\n",
499  aoedev_name ( aoedev ), aoecmd->tag );
500 }
501 
502 /**
503  * Handle AoE configuration response IU
504  *
505  * @v aoecmd AoE command
506  * @v data Response IU
507  * @v len Length of response IU
508  * @v ll_source Link-layer source address
509  * @ret rc Return status code
510  */
511 static int aoecmd_cfg_rsp ( struct aoe_command *aoecmd, const void *data,
512  size_t len, const void *ll_source ) {
513  struct aoe_device *aoedev = aoecmd->aoedev;
514  struct ll_protocol *ll_protocol = aoedev->netdev->ll_protocol;
515  const struct aoehdr *aoehdr = data;
516  const struct aoecfg *aoecfg = &aoehdr->payload[0].cfg;
517 
518  /* Sanity check */
519  if ( len < ( sizeof ( *aoehdr ) + sizeof ( *aoecfg ) ) ) {
520  DBGC ( aoedev, "AoE %s/%08x received underlength "
521  "configuration response (%zd bytes)\n",
522  aoedev_name ( aoedev ), aoecmd->tag, len );
523  return -EINVAL;
524  }
525  DBGC ( aoedev, "AoE %s/%08x CONFIG rsp buf %04x fw %04x scnt %02x\n",
526  aoedev_name ( aoedev ), aoecmd->tag, ntohs ( aoecfg->bufcnt ),
527  aoecfg->fwver, aoecfg->scnt );
528 
529  /* Record target MAC address */
530  memcpy ( aoedev->target, ll_source, ll_protocol->ll_addr_len );
531  DBGC ( aoedev, "AoE %s has MAC address %s\n",
532  aoedev_name ( aoedev ), ll_protocol->ntoa ( aoedev->target ) );
533 
534  return 0;
535 }
536 
537 /** AoE configuration command */
538 static struct aoe_command_type aoecmd_cfg = {
540  .cmd = aoecmd_cfg_cmd,
541  .rsp = aoecmd_cfg_rsp,
542 };
543 
544 /** AoE command ATA interface operations */
547 };
548 
549 /** AoE command ATA interface descriptor */
551  INTF_DESC ( struct aoe_command, ata, aoecmd_ata_op );
552 
553 /**
554  * Identify AoE command by tag
555  *
556  * @v tag Command tag
557  * @ret aoecmd AoE command, or NULL
558  */
560  struct aoe_command *aoecmd;
561 
562  list_for_each_entry ( aoecmd, &aoe_commands, list ) {
563  if ( aoecmd->tag == tag )
564  return aoecmd;
565  }
566  return NULL;
567 }
568 
569 /**
570  * Choose an AoE command tag
571  *
572  * @ret tag New tag, or negative error
573  */
574 static int aoecmd_new_tag ( void ) {
575  static uint16_t tag_idx;
576  unsigned int i;
577 
578  for ( i = 0 ; i < 65536 ; i++ ) {
579  tag_idx++;
580  if ( aoecmd_find_tag ( tag_idx ) == NULL )
581  return ( AOE_TAG_MAGIC | tag_idx );
582  }
583  return -EADDRINUSE;
584 }
585 
586 /**
587  * Create AoE command
588  *
589  * @v aoedev AoE device
590  * @v type AoE command type
591  * @ret aoecmd AoE command
592  */
593 static struct aoe_command * aoecmd_create ( struct aoe_device *aoedev,
594  struct aoe_command_type *type ) {
595  struct aoe_command *aoecmd;
596  int tag;
597 
598  /* Allocate command tag */
599  tag = aoecmd_new_tag();
600  if ( tag < 0 )
601  return NULL;
602 
603  /* Allocate and initialise structure */
604  aoecmd = zalloc ( sizeof ( *aoecmd ) );
605  if ( ! aoecmd )
606  return NULL;
607  ref_init ( &aoecmd->refcnt, aoecmd_free );
608  list_add ( &aoecmd->list, &aoe_commands );
609  intf_init ( &aoecmd->ata, &aoecmd_ata_desc, &aoecmd->refcnt );
610  timer_init ( &aoecmd->timer, aoecmd_expired, &aoecmd->refcnt );
611  aoecmd->aoedev = aoedev_get ( aoedev );
612  aoecmd->type = type;
613  aoecmd->tag = tag;
614 
615  /* Preserve timeout from last completed command */
616  aoecmd->timer.timeout = aoedev->timeout;
617 
618  /* Return already mortalised. (Reference is held by command list.) */
619  return aoecmd;
620 }
621 
622 /**
623  * Issue AoE ATA command
624  *
625  * @v aoedev AoE device
626  * @v parent Parent interface
627  * @v command ATA command
628  * @ret tag Command tag, or negative error
629  */
630 static int aoedev_ata_command ( struct aoe_device *aoedev,
631  struct interface *parent,
632  struct ata_cmd *command ) {
633  struct net_device *netdev = aoedev->netdev;
634  struct aoe_command *aoecmd;
635 
636  /* Fail immediately if net device is closed */
637  if ( ! netdev_is_open ( netdev ) ) {
638  DBGC ( aoedev, "AoE %s cannot issue command while net device "
639  "is closed\n", aoedev_name ( aoedev ) );
640  return -EWOULDBLOCK;
641  }
642 
643  /* Create command */
645  if ( ! aoecmd )
646  return -ENOMEM;
647  memcpy ( &aoecmd->command, command, sizeof ( aoecmd->command ) );
648 
649  /* Attempt to send command. Allow failures to be handled by
650  * the retry timer.
651  */
652  aoecmd_tx ( aoecmd );
653 
654  /* Attach to parent interface, leave reference with command
655  * list, and return.
656  */
657  intf_plug_plug ( &aoecmd->ata, parent );
658  return aoecmd->tag;
659 }
660 
661 /**
662  * Issue AoE configuration command
663  *
664  * @v aoedev AoE device
665  * @v parent Parent interface
666  * @ret tag Command tag, or negative error
667  */
668 static int aoedev_cfg_command ( struct aoe_device *aoedev,
669  struct interface *parent ) {
670  struct aoe_command *aoecmd;
671 
672  /* Create command */
674  if ( ! aoecmd )
675  return -ENOMEM;
676 
677  /* Attempt to send command. Allow failures to be handled by
678  * the retry timer.
679  */
680  aoecmd_tx ( aoecmd );
681 
682  /* Attach to parent interface, leave reference with command
683  * list, and return.
684  */
685  intf_plug_plug ( &aoecmd->ata, parent );
686  return aoecmd->tag;
687 }
688 
689 /**
690  * Free AoE device
691  *
692  * @v refcnt Reference count
693  */
694 static void aoedev_free ( struct refcnt *refcnt ) {
695  struct aoe_device *aoedev =
696  container_of ( refcnt, struct aoe_device, refcnt );
697 
698  netdev_put ( aoedev->netdev );
699  free ( aoedev );
700 }
701 
702 /**
703  * Close AoE device
704  *
705  * @v aoedev AoE device
706  * @v rc Reason for close
707  */
708 static void aoedev_close ( struct aoe_device *aoedev, int rc ) {
709  struct aoe_command *aoecmd;
710  struct aoe_command *tmp;
711 
712  /* Shut down interfaces */
713  intf_shutdown ( &aoedev->ata, rc );
714  intf_shutdown ( &aoedev->config, rc );
715 
716  /* Shut down any active commands */
717  list_for_each_entry_safe ( aoecmd, tmp, &aoe_commands, list ) {
718  if ( aoecmd->aoedev != aoedev )
719  continue;
720  aoecmd_get ( aoecmd );
721  aoecmd_close ( aoecmd, rc );
722  aoecmd_put ( aoecmd );
723  }
724 }
725 
726 /**
727  * Check AoE device flow-control window
728  *
729  * @v aoedev AoE device
730  * @ret len Length of window
731  */
732 static size_t aoedev_window ( struct aoe_device *aoedev ) {
733  return ( aoedev->configured ? ~( ( size_t ) 0 ) : 0 );
734 }
735 
736 /**
737  * Handle AoE device configuration completion
738  *
739  * @v aoedev AoE device
740  * @v rc Reason for completion
741  */
742 static void aoedev_config_done ( struct aoe_device *aoedev, int rc ) {
743 
744  /* Shut down interface */
745  intf_shutdown ( &aoedev->config, rc );
746 
747  /* Close device on failure */
748  if ( rc != 0 ) {
749  aoedev_close ( aoedev, rc );
750  return;
751  }
752 
753  /* Mark device as configured */
754  aoedev->configured = 1;
756 }
757 
758 /**
759  * Identify device underlying AoE device
760  *
761  * @v aoedev AoE device
762  * @ret device Underlying device
763  */
764 static struct device * aoedev_identify_device ( struct aoe_device *aoedev ) {
765  return aoedev->netdev->dev;
766 }
767 
768 /**
769  * Get AoE ACPI descriptor
770  *
771  * @v aoedev AoE device
772  * @ret desc ACPI descriptor
773  */
774 static struct acpi_descriptor * aoedev_describe ( struct aoe_device *aoedev ) {
775  return &aoedev->desc;
776 }
777 
778 /** AoE device ATA interface operations */
782  INTF_OP ( intf_close, struct aoe_device *, aoedev_close ),
784  INTF_OP ( identify_device, struct aoe_device *,
787 };
788 
789 /** AoE device ATA interface descriptor */
791  INTF_DESC ( struct aoe_device, ata, aoedev_ata_op );
792 
793 /** AoE device configuration interface operations */
796 };
797 
798 /** AoE device configuration interface descriptor */
800  INTF_DESC ( struct aoe_device, config, aoedev_config_op );
801 
802 /**
803  * Open AoE device
804  *
805  * @v parent Parent interface
806  * @v netdev Network device
807  * @v major Device major number
808  * @v minor Device minor number
809  * @ret rc Return status code
810  */
811 static int aoedev_open ( struct interface *parent, struct net_device *netdev,
812  unsigned int major, unsigned int minor ) {
813  struct aoe_device *aoedev;
814  int rc;
815 
816  /* Allocate and initialise structure */
817  aoedev = zalloc ( sizeof ( *aoedev ) );
818  if ( ! aoedev ) {
819  rc = -ENOMEM;
820  goto err_zalloc;
821  }
822  ref_init ( &aoedev->refcnt, aoedev_free );
823  intf_init ( &aoedev->ata, &aoedev_ata_desc, &aoedev->refcnt );
824  intf_init ( &aoedev->config, &aoedev_config_desc, &aoedev->refcnt );
825  aoedev->netdev = netdev_get ( netdev );
826  aoedev->major = major;
827  aoedev->minor = minor;
828  memcpy ( aoedev->target, netdev->ll_broadcast,
830  acpi_init ( &aoedev->desc, &abft_model, &aoedev->refcnt );
831 
832  /* Initiate configuration */
833  if ( ( rc = aoedev_cfg_command ( aoedev, &aoedev->config ) ) < 0 ) {
834  DBGC ( aoedev, "AoE %s could not initiate configuration: %s\n",
835  aoedev_name ( aoedev ), strerror ( rc ) );
836  goto err_config;
837  }
838 
839  /* Attach ATA device to parent interface */
840  if ( ( rc = ata_open ( parent, &aoedev->ata, ATA_DEV_MASTER,
841  AOE_MAX_COUNT ) ) != 0 ) {
842  DBGC ( aoedev, "AoE %s could not create ATA device: %s\n",
843  aoedev_name ( aoedev ), strerror ( rc ) );
844  goto err_ata_open;
845  }
846 
847  /* Mortalise self and return */
848  ref_put ( &aoedev->refcnt );
849  return 0;
850 
851  err_ata_open:
852  err_config:
853  aoedev_close ( aoedev, rc );
854  ref_put ( &aoedev->refcnt );
855  err_zalloc:
856  return rc;
857 }
858 
859 /******************************************************************************
860  *
861  * AoE network protocol
862  *
863  ******************************************************************************
864  */
865 
866 /**
867  * Process incoming AoE packets
868  *
869  * @v iobuf I/O buffer
870  * @v netdev Network device
871  * @v ll_dest Link-layer destination address
872  * @v ll_source Link-layer source address
873  * @v flags Packet flags
874  * @ret rc Return status code
875  */
876 static int aoe_rx ( struct io_buffer *iobuf,
877  struct net_device *netdev __unused,
878  const void *ll_dest __unused,
879  const void *ll_source,
880  unsigned int flags __unused ) {
881  struct aoehdr *aoehdr = iobuf->data;
882  struct aoe_command *aoecmd;
883  int rc;
884 
885  /* Sanity check */
886  if ( iob_len ( iobuf ) < sizeof ( *aoehdr ) ) {
887  DBG ( "AoE received underlength packet (%zd bytes)\n",
888  iob_len ( iobuf ) );
889  rc = -EINVAL;
890  goto err_sanity;
891  }
892  if ( ( aoehdr->ver_flags & AOE_VERSION_MASK ) != AOE_VERSION ) {
893  DBG ( "AoE received packet for unsupported protocol version "
894  "%02x\n", ( aoehdr->ver_flags & AOE_VERSION_MASK ) );
895  rc = -EPROTONOSUPPORT;
896  goto err_sanity;
897  }
898  if ( ! ( aoehdr->ver_flags & AOE_FL_RESPONSE ) ) {
899  DBG ( "AoE received request packet\n" );
900  rc = -EOPNOTSUPP;
901  goto err_sanity;
902  }
903 
904  /* Demultiplex amongst active AoE commands */
906  if ( ! aoecmd ) {
907  DBG ( "AoE received packet for unused tag %08x\n",
908  ntohl ( aoehdr->tag ) );
909  rc = -ENOENT;
910  goto err_demux;
911  }
912 
913  /* Pass received frame to command */
914  aoecmd_get ( aoecmd );
915  if ( ( rc = aoecmd_rx ( aoecmd, iob_disown ( iobuf ),
916  ll_source ) ) != 0 )
917  goto err_rx;
918 
919  err_rx:
920  aoecmd_put ( aoecmd );
921  err_demux:
922  err_sanity:
923  free_iob ( iobuf );
924  return rc;
925 }
926 
927 /** AoE protocol */
928 struct net_protocol aoe_protocol __net_protocol = {
929  .name = "AoE",
930  .net_proto = htons ( ETH_P_AOE ),
931  .rx = aoe_rx,
932 };
933 
934 /******************************************************************************
935  *
936  * AoE URIs
937  *
938  ******************************************************************************
939  */
940 
941 /**
942  * Parse AoE URI
943  *
944  * @v uri URI
945  * @ret major Major device number
946  * @ret minor Minor device number
947  * @ret rc Return status code
948  *
949  * An AoE URI has the form "aoe:e<major>.<minor>".
950  */
951 static int aoe_parse_uri ( struct uri *uri, unsigned int *major,
952  unsigned int *minor ) {
953  const char *ptr;
954  char *end;
955 
956  /* Check for URI with opaque portion */
957  if ( ! uri->opaque )
958  return -EINVAL;
959  ptr = uri->opaque;
960 
961  /* Check for initial 'e' */
962  if ( *ptr != 'e' )
963  return -EINVAL;
964  ptr++;
965 
966  /* Parse major device number */
967  *major = strtoul ( ptr, &end, 10 );
968  if ( *end != '.' )
969  return -EINVAL;
970  ptr = ( end + 1 );
971 
972  /* Parse minor device number */
973  *minor = strtoul ( ptr, &end, 10 );
974  if ( *end )
975  return -EINVAL;
976 
977  return 0;
978 }
979 
980 /**
981  * Open AoE URI
982  *
983  * @v parent Parent interface
984  * @v uri URI
985  * @ret rc Return status code
986  */
987 static int aoe_open ( struct interface *parent, struct uri *uri ) {
988  struct net_device *netdev;
989  unsigned int major;
990  unsigned int minor;
991  int rc;
992 
993  /* Identify network device. This is something of a hack, but
994  * the AoE URI scheme that has been in use for some time now
995  * provides no way to specify a particular device.
996  */
998  if ( ! netdev ) {
999  DBG ( "AoE cannot identify network device\n" );
1000  return -ENODEV;
1001  }
1002 
1003  /* Parse URI */
1004  if ( ( rc = aoe_parse_uri ( uri, &major, &minor ) ) != 0 ) {
1005  DBG ( "AoE cannot parse URI\n" );
1006  return rc;
1007  }
1008 
1009  /* Open AoE device */
1010  if ( ( rc = aoedev_open ( parent, netdev, major, minor ) ) != 0 )
1011  return rc;
1012 
1013  return 0;
1014 }
1015 
1016 /** AoE URI opener */
1017 struct uri_opener aoe_uri_opener __uri_opener = {
1018  .scheme = "aoe",
1019  .open = aoe_open,
1020 };
1021 
1022 /******************************************************************************
1023  *
1024  * AoE boot firmware table (aBFT)
1025  *
1026  ******************************************************************************
1027  */
1028 
1029 /**
1030  * Check if AoE boot firmware table descriptor is complete
1031  *
1032  * @v desc ACPI descriptor
1033  * @ret rc Return status code
1034  */
1035 static int abft_complete ( struct acpi_descriptor *desc __unused ) {
1036  return 0;
1037 }
1038 
1039 /**
1040  * Install AoE boot firmware table(s)
1041  *
1042  * @v install Installation method
1043  * @ret rc Return status code
1044  */
1045 static int abft_install ( int ( * install ) ( struct acpi_header *acpi ) ) {
1046  struct aoe_device *aoedev;
1047  struct abft_table abft;
1048  int rc;
1049 
1050  list_for_each_entry ( aoedev, &abft_model.descs, desc.list ) {
1051 
1052  /* Populate table */
1053  memset ( &abft, 0, sizeof ( abft ) );
1054  abft.acpi.signature = cpu_to_le32 ( ABFT_SIG );
1055  abft.acpi.length = cpu_to_le32 ( sizeof ( abft ) );
1056  abft.acpi.revision = 1;
1057  abft.shelf = cpu_to_le16 ( aoedev->major );
1058  abft.slot = aoedev->minor;
1059  memcpy ( abft.mac, aoedev->netdev->ll_addr,
1060  sizeof ( abft.mac ) );
1061 
1062  /* Install table */
1063  if ( ( rc = install ( &abft.acpi ) ) != 0 ) {
1064  DBGC ( aoedev, "AoE %s could not install aBFT: %s\n",
1065  aoedev_name ( aoedev ), strerror ( rc ) );
1066  return rc;
1067  }
1068  }
1069 
1070  return 0;
1071 }
1072 
1073 /** aBFT model */
1074 struct acpi_model abft_model __acpi_model = {
1075  .descs = LIST_HEAD_INIT ( abft_model.descs ),
1076  .complete = abft_complete,
1077  .install = abft_install,
1078 };
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
#define __attribute__(x)
Definition: compiler.h:10
#define EINVAL
Invalid argument.
Definition: errno.h:428
An object interface operation.
Definition: interface.h:17
struct aoecfg cfg
Config command.
Definition: aoe.h:64
union aoeata::@499 lba
Logical block address, in little-endian order.
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void xfer_window_changed(struct interface *intf)
Report change of flow control window.
Definition: xfer.c:146
unsigned short uint16_t
Definition: stdint.h:11
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition: interface.c:249
static struct aoe_command * aoecmd_find_tag(uint32_t tag)
Identify AoE command by tag.
Definition: aoe.c:559
const char * name
Protocol name.
Definition: netdevice.h:66
struct acpi_header acpi
ACPI header.
Definition: aoe.h:151
#define iob_put(iobuf, len)
Definition: iobuf.h:120
#define AOE_TAG_MAGIC
AoE tag magic marker.
Definition: aoe.h:109
static struct aoe_device * aoedev_get(struct aoe_device *aoedev)
Get reference to AoE device.
Definition: aoe.c:132
void intf_shutdown(struct interface *intf, int rc)
Shut down an object interface.
Definition: interface.c:278
static size_t aoecmd_ata_cmd_len(struct aoe_command *aoecmd)
Calculate length of AoE ATA command IU.
Definition: aoe.c:355
static struct interface_operation aoedev_ata_op[]
AoE device ATA interface operations.
Definition: aoe.c:779
uint8_t ll_addr_len
Link-layer address length.
Definition: netdevice.h:198
static int aoe_parse_uri(struct uri *uri, unsigned int *major, unsigned int *minor)
Parse AoE URI.
Definition: aoe.c:951
unsigned long strtoul(const char *string, char **endp, int base)
Convert string to numeric value.
Definition: string.c:484
static int abft_complete(struct acpi_descriptor *desc __unused)
Check if AoE boot firmware table descriptor is complete.
Definition: aoe.c:1035
uint8_t err_feat
ATA error/feature register.
Definition: aoe.h:42
struct acpi_model abft_model __acpi_model
aBFT model
Definition: aoe.c:57
uint32_t signature
ACPI signature (4 ASCII characters)
Definition: acpi.h:165
An AoE ATA command.
Definition: aoe.h:38
int(* rsp)(struct aoe_command *aoecmd, const void *data, size_t len, const void *ll_source)
Handle AoE response IU.
Definition: aoe.c:121
#define FEATURE_PROTOCOL
Network protocols.
Definition: features.h:21
static struct interface_descriptor aoedev_config_desc
AoE device configuration interface descriptor.
Definition: aoe.c:799
static int aoe_open(struct interface *parent, struct uri *uri)
Open AoE URI.
Definition: aoe.c:987
#define list_add(new, head)
Add a new entry to the head of a list.
Definition: list.h:69
#define AOE_MAX_COUNT
Maximum number of sectors per packet.
Definition: aoe.h:112
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition: refcnt.h:64
Error codes.
__SIZE_TYPE__ size_t
Definition: stdint.h:6
struct list_head descs
List of descriptors.
Definition: acpi.h:306
A command-line command.
Definition: command.h:9
I/O buffers.
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:146
uint8_t bytes[6]
Definition: aoe.h:50
static struct interface_descriptor aoecmd_ata_desc
AoE command ATA interface descriptor.
Definition: aoe.c:550
uint32_t type
Operating system type.
Definition: ena.h:12
static __always_inline void copy_from_user(void *dest, userptr_t src, off_t src_off, size_t len)
Copy data from user buffer.
Definition: uaccess.h:337
#define EADDRINUSE
Address already in use.
Definition: errno.h:303
uint16_t major
Major number.
Definition: aoe.h:125
uint64_t desc
Microcode descriptor list physical address.
Definition: ucode.h:12
uint8_t data[0]
Data payload.
Definition: aoe.h:53
#define DBGC(...)
Definition: compiler.h:505
union aoecmd payload[0]
Payload.
Definition: aoe.h:84
static size_t aoedev_window(struct aoe_device *aoedev)
Check AoE device flow-control window.
Definition: aoe.c:732
#define AOE_VERSION_MASK
Version part of ver_flags field.
Definition: aoe.h:88
static struct aoe_command_type aoecmd_cfg
AoE configuration command.
Definition: aoe.c:538
static int aoecmd_new_tag(void)
Choose an AoE command tag.
Definition: aoe.c:574
A retry timer.
Definition: retry.h:21
#define ENOENT
No such file or directory.
Definition: errno.h:514
void intf_plug_plug(struct interface *a, struct interface *b)
Plug two object interfaces together.
Definition: interface.c:107
const uint8_t * ll_broadcast
Link-layer broadcast address.
Definition: netdevice.h:389
uint16_t major
Major device number, in network byte order.
Definition: aoe.h:76
static int aoedev_ata_command(struct aoe_device *aoedev, struct interface *parent, struct ata_cmd *command)
Issue AoE ATA command.
Definition: aoe.c:630
static int aoecmd_tx(struct aoe_command *aoecmd)
Transmit AoE command request.
Definition: aoe.c:231
#define ntohl(value)
Definition: byteswap.h:134
uint16_t fwver
ATA target firmware version.
Definition: aoe.h:26
static int abft_install(int(*install)(struct acpi_header *acpi))
Install AoE boot firmware table(s)
Definition: aoe.c:1045
#define cpu_to_le64(value)
Definition: byteswap.h:108
uint32_t data_len
Microcode data size (or 0 to indicate 2000 bytes)
Definition: ucode.h:26
static int aoe_rx(struct io_buffer *iobuf, struct net_device *netdev __unused, const void *ll_dest __unused, const void *ll_source, unsigned int flags __unused)
Process incoming AoE packets.
Definition: aoe.c:876
#define ntohs(value)
Definition: byteswap.h:136
#define static_assert(x)
Assert a condition at build time.
Definition: assert.h:65
Uniform Resource Identifiers.
struct list_head list
List of active commands.
Definition: aoe.c:79
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:129
unsigned long timeout
Saved timeout value.
Definition: aoe.h:132
Access to external ("user") memory.
#define htonl(value)
Definition: byteswap.h:133
uint8_t cmd_stat
ATA command/status register.
Definition: aoe.h:46
size_t xfer_window(struct interface *intf)
Check flow control window.
Definition: xfer.c:116
A link-layer protocol.
Definition: netdevice.h:114
FEATURE(FEATURE_PROTOCOL, "AoE", DHCP_EB_FEATURE_AOE, 1)
An AoE device.
Definition: aoe.h:115
A doubly-linked list entry (or list head)
Definition: list.h:18
uint8_t command
Command number.
Definition: aoe.h:80
Data transfer interfaces.
A reference counter.
Definition: refcnt.h:26
A timer.
Definition: timer.h:28
struct net_protocol aoe_protocol __net_protocol
AoE protocol.
Definition: aoe.c:56
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:136
uint8_t mac[ETH_ALEN]
MAC address.
Definition: aoe.h:159
unsigned long tmp
Definition: linux_pci.h:63
static void aoecmd_ata_cmd(struct aoe_command *aoecmd, void *data, size_t len)
Build AoE ATA command IU.
Definition: aoe.c:369
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
#define ENOMEM
Not enough space.
Definition: errno.h:534
A hardware device.
Definition: device.h:73
#define iob_disown(iobuf)
Disown an I/O buffer.
Definition: iobuf.h:212
AoE protocol.
void * memcpy(void *dest, const void *src, size_t len) __nonnull
static void aoecmd_cfg_cmd(struct aoe_command *aoecmd, void *data, size_t len)
Build AoE configuration command IU.
Definition: aoe.c:485
uint32_t major
Major version.
Definition: netvsc.h:14
uint32_t minor
Minor version.
Definition: netvsc.h:16
#define __unused
Declare a variable or data structure as unused.
Definition: compiler.h:573
static int netdev_is_open(struct net_device *netdev)
Check whether or not network device is open.
Definition: netdevice.h:658
#define AOE_FL_WRITE
Write command.
Definition: aoe.h:59
Assertions.
#define ATA_DEV_MASTER
Master ("device 0") flag in the ATA device register.
Definition: ata.h:120
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:572
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
An object interface.
Definition: interface.h:124
#define EWOULDBLOCK
Operation would block.
Definition: errno.h:679
An ACPI table model.
Definition: acpi.h:304
uint32_t length
Length of table, in bytes, including header.
Definition: acpi.h:167
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:431
size_t(* cmd_len)(struct aoe_command *aoecmd)
Calculate length of AoE command IU.
Definition: aoe.c:103
void(* cmd)(struct aoe_command *aoecmd, void *data, size_t len)
Build AoE command IU.
Definition: aoe.c:111
Object interfaces.
static EFI_ACPI_TABLE_PROTOCOL * acpi
ACPI table protocol protocol.
Definition: efi_block.c:65
struct aoe_device * aoedev
AOE device.
Definition: aoe.c:77
#define AOE_VERSION
Version 1.
Definition: aoe.h:87
static struct net_device * netdev
Definition: gdbudp.c:52
const char * scheme
URI protocol name.
Definition: open.h:53
struct net_device * last_opened_netdev(void)
Get most recently opened network device.
Definition: netdevice.c:1047
An ATA command information unit.
Definition: ata.h:168
#define MAX_LL_HEADER_LEN
Maximum length of a link-layer header.
Definition: netdevice.h:45
struct acpi_descriptor desc
ACPI descriptor.
Definition: aoe.h:140
uint8_t minor
Minor device number.
Definition: aoe.h:78
Feature list.
static int aoedev_cfg_command(struct aoe_device *aoedev, struct interface *parent)
Issue AoE configuration command.
Definition: aoe.c:668
struct interface ata
ATA command issuing interface.
Definition: aoe.h:122
uint8_t slot
AoE slot.
Definition: aoe.h:155
#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
#define cpu_to_le32(value)
Definition: byteswap.h:107
struct aoe_command_type * type
Command type.
Definition: aoe.c:87
static struct aoe_command * aoecmd_create(struct aoe_device *aoedev, struct aoe_command_type *type)
Create AoE command.
Definition: aoe.c:593
An AoE command.
Definition: aoe.h:62
Linked lists.
#define EFI_INTF_OP
Definition: efi.h:350
#define DHCP_EB_FEATURE_AOE
AoE protocol.
Definition: features.h:38
An object interface descriptor.
Definition: interface.h:55
uint8_t target[MAX_LL_ADDR_LEN]
Target MAC address.
Definition: aoe.h:129
uint8_t flags
Flags.
Definition: ena.h:18
#define ERANGE
Result too large.
Definition: errno.h:639
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
An AoE config command.
Definition: aoe.h:22
static void aoedev_close(struct aoe_device *aoedev, int rc)
Close AoE device.
Definition: aoe.c:708
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
#define ETH_P_AOE
Definition: if_ether.h:25
static struct interface_operation aoecmd_ata_op[]
AoE command ATA interface operations.
Definition: aoe.c:545
#define ref_get(refcnt)
Get additional reference to object.
Definition: refcnt.h:92
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:155
#define INTF_OP(op_type, object_type, op_func)
Define an object interface operation.
Definition: interface.h:32
static __always_inline void copy_to_user(userptr_t dest, off_t dest_off, const void *src, size_t len)
Copy data to user buffer.
Definition: uaccess.h:324
uint32_t tag
Tag, in network byte order.
Definition: aoe.h:82
uint16_t bufcnt
AoE queue depth.
Definition: aoe.h:24
#define EOPNOTSUPP
Operation not supported on socket.
Definition: errno.h:604
struct refcnt refcnt
Reference counter.
Definition: aoe.h:117
A network device.
Definition: netdevice.h:352
struct interface config
Configuration command interface.
Definition: aoe.h:135
#define ENODEV
No such device.
Definition: errno.h:509
Data transfer interface opening.
EFI device paths.
uint8_t aflags
AoE command flags.
Definition: aoe.h:40
static struct net_device * netdev_get(struct net_device *netdev)
Get reference to network device.
Definition: netdevice.h:561
AoE Boot Firmware Table (aBFT)
Definition: aoe.h:149
ATA devices.
uint32_t tag
Command tag.
Definition: aoe.c:89
An ACPI description header.
Definition: acpi.h:163
static int aoecmd_rx(struct aoe_command *aoecmd, struct io_buffer *iobuf, const void *ll_source)
Receive AoE command response.
Definition: aoe.c:285
unsigned int uint32_t
Definition: stdint.h:12
struct acpi_descriptor * acpi_describe(struct interface *intf)
Get object's ACPI descriptor.
Definition: acpi.c:313
#define ATA_STAT_ERR
Command completed in error.
Definition: ata.h:141
uint64_t u64
Definition: aoe.h:49
struct uri_opener aoe_uri_opener __uri_opener
AoE URI opener.
Definition: aoe.c:1017
#define AOE_CMD_CONFIG
Query Config Information.
Definition: aoe.h:97
struct device * dev
Underlying hardware device.
Definition: netdevice.h:364
void start_timer(struct retry_timer *timer)
Start timer.
Definition: retry.c:93
A network-layer protocol.
Definition: netdevice.h:64
Network device management.
#define iob_reserve(iobuf, len)
Definition: iobuf.h:67
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:45
#define INTF_DESC(object_type, intf, operations)
Define an object interface descriptor.
Definition: interface.h:80
An ACPI descriptor (used to construct ACPI tables)
Definition: acpi.h:278
static void aoedev_config_done(struct aoe_device *aoedev, int rc)
Handle AoE device configuration completion.
Definition: aoe.c:742
void stop_timer(struct retry_timer *timer)
Stop timer.
Definition: retry.c:117
static int aoecmd_cfg_rsp(struct aoe_command *aoecmd, const void *data, size_t len, const void *ll_source)
Handle AoE configuration response IU.
Definition: aoe.c:511
#define ABFT_SIG
AoE boot firmware table signature.
Definition: aoe.h:144
static struct device * aoedev_identify_device(struct aoe_device *aoedev)
Identify device underlying AoE device.
Definition: aoe.c:764
EFI_DEVICE_PATH_PROTOCOL * efi_describe(struct interface *intf)
Describe object as an EFI device path.
Definition: efi_path.c:680
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:362
int net_tx(struct io_buffer *iobuf, struct net_device *netdev, struct net_protocol *net_protocol, const void *ll_dest, const void *ll_source)
Transmit network-layer packet.
Definition: netdevice.c:1073
const char * opaque
Opaque part.
Definition: uri.h:70
#define DBGC2(...)
Definition: compiler.h:522
#define EPROTONOSUPPORT
Protocol not supported.
Definition: errno.h:629
static void aoecmd_expired(struct retry_timer *timer, int fail)
Handle AoE retry timer expiry.
Definition: aoe.c:338
EFI_DEVICE_PATH_PROTOCOL * efi_aoe_path(struct aoe_device *aoedev)
Construct EFI device path for AoE device.
Definition: efi_path.c:499
int configured
Device is configued.
Definition: aoe.h:137
void * data
Start of data.
Definition: iobuf.h:48
uint8_t count
ATA sector count register.
Definition: aoe.h:44
static void aoecmd_put(struct aoe_command *aoecmd)
Drop reference to AoE command.
Definition: aoe.c:165
#define EIO
Input/output error.
Definition: errno.h:433
static void aoecmd_free(struct refcnt *refcnt)
Free AoE command.
Definition: aoe.c:188
static struct aoe_command_type aoecmd_ata
AoE ATA command.
Definition: aoe.c:462
static size_t aoecmd_cfg_cmd_len(struct aoe_command *aoecmd __unused)
Calculate length of AoE configuration command IU.
Definition: aoe.c:474
static int aoecmd_ata_rsp(struct aoe_command *aoecmd, const void *data, size_t len, const void *ll_source __unused)
Handle AoE ATA response IU.
Definition: aoe.c:417
#define cpu_to_le16(value)
Definition: byteswap.h:106
uint8_t minor
Minor number.
Definition: aoe.h:127
uint32_t end
Ending offset.
Definition: netvsc.h:18
struct net_device * netdev
Network device.
Definition: aoe.h:120
uint8_t data[48]
Additional event data.
Definition: ena.h:22
uint8_t ver_flags
Protocol version number and flags.
Definition: aoe.h:72
static void aoedev_free(struct refcnt *refcnt)
Free AoE device.
Definition: aoe.c:694
#define AOE_FL_ERROR
Command generated an error.
Definition: aoe.h:91
const char *(* ntoa)(const void *ll_addr)
Transcribe link-layer address.
Definition: netdevice.h:163
static int aoedev_open(struct interface *parent, struct net_device *netdev, unsigned int major, unsigned int minor)
Open AoE device.
Definition: aoe.c:811
Device model.
int ata_open(struct interface *block, struct interface *ata, unsigned int device, unsigned int max_count)
Open ATA device.
Definition: ata.c:662
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:382
A Uniform Resource Identifier.
Definition: uri.h:64
uint8_t scnt
ATA target sector count.
Definition: aoe.h:28
struct aoeata ata
ATA command.
Definition: aoe.h:66
uint8_t revision
ACPI Specification minor version number.
Definition: acpi.h:169
#define AOE_CMD_ATA
Issue ATA command.
Definition: aoe.h:96
struct device * identify_device(struct interface *intf)
Identify a device behind an interface.
Definition: device.c:125
static void aoecmd_close(struct aoe_command *aoecmd, int rc)
Close AoE command.
Definition: aoe.c:205
An AoE header.
Definition: aoe.h:70
static void aoedev_put(struct aoe_device *aoedev)
Drop reference to AoE device.
Definition: aoe.c:143
static LIST_HEAD(aoe_devices)
List of all AoE devices.
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:387
#define AOE_FL_RESPONSE
Message is a response.
Definition: aoe.h:90
#define AOE_FL_EXTENDED
LBA48 extended addressing.
Definition: aoe.h:56
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
static struct interface_descriptor aoedev_ata_desc
AoE device ATA interface descriptor.
Definition: aoe.c:790
#define LIST_HEAD_INIT(list)
Initialise a static list head.
Definition: list.h:30
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition: interface.h:203
A URI opener.
Definition: open.h:47
uint64_t tag
Identity tag.
Definition: edd.h:30
static struct aoe_command * aoecmd_get(struct aoe_command *aoecmd)
Get reference to AoE command.
Definition: aoe.c:154
#define ATA_DEV_SLAVE
Slave ("device 1") flag in the ATA device register.
Definition: ata.h:117
An AoE command.
Definition: aoe.c:73
uint32_t len
Length.
Definition: ena.h:14
#define ATA_DEV_MASK
Mask of non-LBA portion of device register.
Definition: ata.h:123
An ATA command.
Definition: ata.c:109
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
#define AOE_FL_DEV_HEAD
Device/head flag.
Definition: aoe.h:57
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:669
String functions.
static struct acpi_descriptor * aoedev_describe(struct aoe_device *aoedev)
Get AoE ACPI descriptor.
Definition: aoe.c:774
uint16_t shelf
AoE shelf.
Definition: aoe.h:153
#define htons(value)
Definition: byteswap.h:135
struct bofm_section_header done
Definition: bofm_test.c:46
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:372
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106
static void acpi_init(struct acpi_descriptor *desc, struct acpi_model *model, struct refcnt *refcnt)
Initialise ACPI descriptor.
Definition: acpi.h:295
struct interface ata
ATA command interface.
Definition: aoe.c:82
void * memset(void *dest, int character, size_t len) __nonnull
static const char * aoedev_name(struct aoe_device *aoedev)
Name AoE device.
Definition: aoe.c:175
A persistent I/O buffer.
Definition: iobuf.h:33
An AoE command type.
Definition: aoe.c:96
static struct interface_operation aoedev_config_op[]
AoE device configuration interface operations.
Definition: aoe.c:794