iPXE
ibft.c
Go to the documentation of this file.
1 /*
2  * Copyright Fen Systems Ltd. 2007. Portions of this code are derived
3  * from IBM Corporation Sample Programs. Copyright IBM Corporation
4  * 2004, 2007. All rights reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person
7  * obtaining a copy of this software and associated documentation
8  * files (the "Software"), to deal in the Software without
9  * restriction, including without limitation the rights to use, copy,
10  * modify, merge, publish, distribute, sublicense, and/or sell copies
11  * of the Software, and to permit persons to whom the Software is
12  * furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be
15  * included in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24  * SOFTWARE.
25  *
26  */
27 
28 FILE_LICENCE ( BSD2 );
29 
30 #include <stdint.h>
31 #include <stdlib.h>
32 #include <stdio.h>
33 #include <string.h>
34 #include <errno.h>
35 #include <byteswap.h>
36 #include <ipxe/pci.h>
37 #include <ipxe/acpi.h>
38 #include <ipxe/in.h>
39 #include <ipxe/netdevice.h>
40 #include <ipxe/ethernet.h>
41 #include <ipxe/vlan.h>
42 #include <ipxe/tcpip.h>
43 #include <ipxe/dhcp.h>
44 #include <ipxe/iscsi.h>
45 #include <ipxe/ibft.h>
46 
47 /** @file
48  *
49  * iSCSI boot firmware table
50  *
51  * The information in this file is originally derived from the document "iSCSI
52  * Boot Firmware Table (iBFT)" as published by IBM at:
53  *
54  * ftp://ftp.software.ibm.com/systems/support/system_x_pdf/ibm_iscsi_boot_firmware_table_v1.02.pdf
55  *
56  * That file is no longer available, but a more recent version is available:
57  *
58  * ftp://ftp.software.ibm.com/systems/support/bladecenter/iscsi_boot_firmware_table_v1.03.pdf
59  *
60  */
61 
62 /**
63  * iSCSI string buffer
64  *
65  * This is an internal structure that we use to keep track of the
66  * allocation of string data.
67  */
68 struct ibft_strings {
69  /** Strings data */
70  char *data;
71  /** Starting offset of strings */
72  size_t start;
73  /** Total length */
74  size_t len;
75 };
76 
77 /**
78  * Align structure within iBFT
79  *
80  * @v len Unaligned length (or offset)
81  * @ret len Aligned length (or offset)
82  */
83 static inline size_t ibft_align ( size_t len ) {
84 
85  return ( ( len + IBFT_ALIGN - 1 ) & ~( IBFT_ALIGN - 1 ) );
86 }
87 
88 /**
89  * Fill in an IP address field within iBFT
90  *
91  * @v ipaddr IP address field
92  * @v in IPv4 address
93  */
94 static void ibft_set_ipaddr ( struct ibft_ipaddr *ipaddr, struct in_addr in ) {
95  memset ( ipaddr, 0, sizeof ( *ipaddr ) );
96  if ( in.s_addr ) {
97  ipaddr->in = in;
98  ipaddr->ones = 0xffff;
99  }
100 }
101 
102 /**
103  * Fill in an IP address within iBFT from configuration setting
104  *
105  * @v settings Parent settings block, or NULL
106  * @v ipaddr IP address field
107  * @v setting Configuration setting
108  * @v count Maximum number of IP addresses
109  */
111  struct ibft_ipaddr *ipaddr,
112  const struct setting *setting,
113  unsigned int count ) {
114  struct in_addr in[count];
115  unsigned int i;
116 
118  for ( i = 0 ; i < count ; i++ ) {
119  ibft_set_ipaddr ( &ipaddr[i], in[i] );
120  }
121 }
122 
123 /**
124  * Read IP address from iBFT (for debugging)
125  *
126  * @v strings iBFT string block descriptor
127  * @v string String field
128  * @ret ipaddr IP address string
129  */
130 static const char * ibft_ipaddr ( struct ibft_ipaddr *ipaddr ) {
131  return inet_ntoa ( ipaddr->in );
132 }
133 
134 /**
135  * Allocate a string within iBFT
136  *
137  * @v strings iBFT string block descriptor
138  * @v string String field to fill in
139  * @v len Length of string to allocate (excluding NUL)
140  * @ret dest String destination, or NULL
141  */
142 static char * ibft_alloc_string ( struct ibft_strings *strings,
143  struct ibft_string *string, size_t len ) {
144  size_t new_len;
145  char *new_data;
146  char *dest;
147 
148  /* Extend string data buffer */
149  new_len = ( strings->len + len + 1 /* NUL */ );
150  new_data = realloc ( strings->data, new_len );
151  if ( ! new_data )
152  return NULL;
153  strings->data = new_data;
154 
155  /* Fill in string field */
156  string->offset = cpu_to_le16 ( strings->start + strings->len );
157  string->len = cpu_to_le16 ( len );
158 
159  /* Zero string */
160  dest = ( strings->data + strings->len );
161  memset ( dest, 0, ( len + 1 /* NUL */ ) );
162 
163  /* Update allocated length */
164  strings->len = new_len;
165 
166  return dest;
167 }
168 
169 /**
170  * Fill in a string field within iBFT
171  *
172  * @v strings iBFT string block descriptor
173  * @v string String field
174  * @v data String to fill in, or NULL
175  * @ret rc Return status code
176  */
177 static int ibft_set_string ( struct ibft_strings *strings,
178  struct ibft_string *string, const char *data ) {
179  char *dest;
180 
181  if ( ! data )
182  return 0;
183 
184  dest = ibft_alloc_string ( strings, string, strlen ( data ) );
185  if ( ! dest )
186  return -ENOBUFS;
187  strcpy ( dest, data );
188 
189  return 0;
190 }
191 
192 /**
193  * Fill in a string field within iBFT from configuration setting
194  *
195  * @v settings Parent settings block, or NULL
196  * @v strings iBFT string block descriptor
197  * @v string String field
198  * @v setting Configuration setting
199  * @ret rc Return status code
200  */
202  struct ibft_strings *strings,
203  struct ibft_string *string,
204  const struct setting *setting ) {
205  struct settings *origin;
206  struct setting fetched;
207  int len;
208  char *dest;
209 
210  len = fetch_setting ( settings, setting, &origin, &fetched, NULL, 0 );
211  if ( len < 0 ) {
212  string->offset = 0;
213  string->len = 0;
214  return 0;
215  }
216 
217  dest = ibft_alloc_string ( strings, string, len );
218  if ( ! dest )
219  return -ENOBUFS;
220  fetch_string_setting ( origin, &fetched, dest, ( len + 1 ));
221 
222  return 0;
223 }
224 
225 /**
226  * Read string from iBFT (for debugging)
227  *
228  * @v strings iBFT string block descriptor
229  * @v string String field
230  * @ret data String content (or "<empty>")
231  */
232 static const char * ibft_string ( struct ibft_strings *strings,
233  struct ibft_string *string ) {
234  size_t offset = le16_to_cpu ( string->offset );
235 
236  return ( offset ? ( strings->data + offset - strings->start ) : NULL );
237 }
238 
239 /**
240  * Check if network device is required for the iBFT
241  *
242  * @v netdev Network device
243  * @ret is_required Network device is required
244  */
245 static int ibft_netdev_is_required ( struct net_device *netdev ) {
246  struct iscsi_session *iscsi;
247  struct sockaddr_tcpip *st_target;
248 
249  list_for_each_entry ( iscsi, &ibft_model.descs, desc.list ) {
250  st_target = ( struct sockaddr_tcpip * ) &iscsi->target_sockaddr;
251  if ( tcpip_netdev ( st_target ) == netdev )
252  return 1;
253  }
254 
255  return 0;
256 }
257 
258 /**
259  * Fill in NIC portion of iBFT
260  *
261  * @v nic NIC portion of iBFT
262  * @v strings iBFT string block descriptor
263  * @v netdev Network device
264  * @ret rc Return status code
265  */
266 static int ibft_fill_nic ( struct ibft_nic *nic,
267  struct ibft_strings *strings,
268  struct net_device *netdev ) {
270  struct in_addr netmask_addr = { 0 };
271  unsigned int netmask_count = 0;
272  struct settings *parent = netdev_settings ( netdev );
273  struct settings *origin;
274  int rc;
275 
276  /* Fill in common header */
277  nic->header.structure_id = IBFT_STRUCTURE_ID_NIC;
278  nic->header.version = 1;
279  nic->header.length = cpu_to_le16 ( sizeof ( *nic ) );
280  nic->header.flags = ( IBFT_FL_NIC_BLOCK_VALID |
282  DBG ( "iBFT NIC %d is %s\n", nic->header.index, netdev->name );
283 
284  /* Determine origin of IP address */
285  fetch_setting ( parent, &ip_setting, &origin, NULL, NULL, 0 );
286  nic->origin = ( ( origin == parent ) ?
288  DBG ( "iBFT NIC %d origin = %d\n", nic->header.index, nic->origin );
289 
290  /* Extract values from configuration settings */
291  ibft_set_ipaddr_setting ( parent, &nic->ip_address, &ip_setting, 1 );
292  DBG ( "iBFT NIC %d IP = %s\n",
293  nic->header.index, ibft_ipaddr ( &nic->ip_address ) );
294  ibft_set_ipaddr_setting ( parent, &nic->gateway, &gateway_setting, 1 );
295  DBG ( "iBFT NIC %d gateway = %s\n",
296  nic->header.index, ibft_ipaddr ( &nic->gateway ) );
297  ibft_set_ipaddr_setting ( NULL, &nic->dns[0], &dns_setting,
298  ( sizeof ( nic->dns ) /
299  sizeof ( nic->dns[0] ) ) );
300  ibft_set_ipaddr_setting ( parent, &nic->dhcp, &dhcp_server_setting, 1 );
301  DBG ( "iBFT NIC %d DNS = %s",
302  nic->header.index, ibft_ipaddr ( &nic->dns[0] ) );
303  DBG ( ", %s\n", ibft_ipaddr ( &nic->dns[1] ) );
304  if ( ( rc = ibft_set_string_setting ( NULL, strings, &nic->hostname,
305  &hostname_setting ) ) != 0 )
306  return rc;
307  DBG ( "iBFT NIC %d hostname = %s\n",
308  nic->header.index, ibft_string ( strings, &nic->hostname ) );
309 
310  /* Derive subnet mask prefix from subnet mask */
311  fetch_ipv4_setting ( parent, &netmask_setting, &netmask_addr );
312  while ( netmask_addr.s_addr ) {
313  if ( netmask_addr.s_addr & 0x1 )
314  netmask_count++;
315  netmask_addr.s_addr >>= 1;
316  }
317  nic->subnet_mask_prefix = netmask_count;
318  DBG ( "iBFT NIC %d subnet = /%d\n",
319  nic->header.index, nic->subnet_mask_prefix );
320 
321  /* Extract values from net-device configuration */
322  nic->vlan = cpu_to_le16 ( vlan_tag ( netdev ) );
323  DBG ( "iBFT NIC %d VLAN = %02x\n",
324  nic->header.index, le16_to_cpu ( nic->vlan ) );
325  if ( ( rc = ll_protocol->eth_addr ( netdev->ll_addr,
326  nic->mac_address ) ) != 0 ) {
327  DBG ( "Could not determine %s MAC: %s\n",
328  netdev->name, strerror ( rc ) );
329  return rc;
330  }
331  DBG ( "iBFT NIC %d MAC = %s\n",
332  nic->header.index, eth_ntoa ( nic->mac_address ) );
333  nic->pci_bus_dev_func = cpu_to_le16 ( netdev->dev->desc.location );
334  DBG ( "iBFT NIC %d PCI = %04x\n",
335  nic->header.index, le16_to_cpu ( nic->pci_bus_dev_func ) );
336 
337  return 0;
338 }
339 
340 /**
341  * Fill in Initiator portion of iBFT
342  *
343  * @v initiator Initiator portion of iBFT
344  * @v strings iBFT string block descriptor
345  * @v initiator_iqn Initiator IQN
346  * @ret rc Return status code
347  */
348 static int ibft_fill_initiator ( struct ibft_initiator *initiator,
349  struct ibft_strings *strings,
350  const char *initiator_iqn ) {
351  int rc;
352 
353  /* Fill in common header */
355  initiator->header.version = 1;
356  initiator->header.length = cpu_to_le16 ( sizeof ( *initiator ) );
359 
360  /* Fill in initiator name */
361  if ( ( rc = ibft_set_string ( strings, &initiator->initiator_name,
362  initiator_iqn ) ) != 0 )
363  return rc;
364  DBG ( "iBFT initiator name = %s\n",
365  ibft_string ( strings, &initiator->initiator_name ) );
366 
367  return 0;
368 }
369 
370 /**
371  * Fill in Target NIC association
372  *
373  * @v target Target portion of iBFT
374  * @v iscsi iSCSI session
375  * @ret rc Return status code
376  */
377 static int ibft_fill_target_nic_association ( struct ibft_target *target,
378  struct iscsi_session *iscsi ) {
379  struct sockaddr_tcpip *st_target =
380  ( struct sockaddr_tcpip * ) &iscsi->target_sockaddr;
381  struct net_device *associated;
382  struct net_device *netdev;
383 
384  /* Find network device used to reach target */
385  associated = tcpip_netdev ( st_target );
386  if ( ! associated ) {
387  DBG ( "iBFT target %d has no net device\n",
388  target->header.index );
389  return -EHOSTUNREACH;
390  }
391 
392  /* Calculate association */
393  for_each_netdev ( netdev ) {
394  if ( netdev == associated ) {
395  DBG ( "iBFT target %d uses NIC %d (%s)\n",
396  target->header.index, target->nic_association,
397  netdev->name );
398  return 0;
399  }
400  if ( ! ibft_netdev_is_required ( netdev ) )
401  continue;
402  target->nic_association++;
403  }
404 
405  DBG ( "iBFT target %d has impossible NIC %s\n",
406  target->header.index, netdev->name );
407  return -EINVAL;
408 }
409 
410 /**
411  * Fill in Target CHAP portion of iBFT
412  *
413  * @v target Target portion of iBFT
414  * @v strings iBFT string block descriptor
415  * @v iscsi iSCSI session
416  * @ret rc Return status code
417  */
418 static int ibft_fill_target_chap ( struct ibft_target *target,
419  struct ibft_strings *strings,
420  struct iscsi_session *iscsi ) {
421  int rc;
422 
423  if ( ! ( iscsi->status & ISCSI_STATUS_AUTH_FORWARD_REQUIRED ) )
424  return 0;
425 
426  assert ( iscsi->initiator_username );
427  assert ( iscsi->initiator_password );
428 
429  target->chap_type = IBFT_CHAP_ONE_WAY;
430  if ( ( rc = ibft_set_string ( strings, &target->chap_name,
431  iscsi->initiator_username ) ) != 0 )
432  return rc;
433  DBG ( "iBFT target %d username = %s\n", target->header.index,
434  ibft_string ( strings, &target->chap_name ) );
435  if ( ( rc = ibft_set_string ( strings, &target->chap_secret,
436  iscsi->initiator_password ) ) != 0 )
437  return rc;
438  DBG ( "iBFT target %d password = <redacted>\n", target->header.index );
439 
440  return 0;
441 }
442 
443 /**
444  * Fill in Target Reverse CHAP portion of iBFT
445  *
446  * @v target Target portion of iBFT
447  * @v strings iBFT string block descriptor
448  * @v iscsi iSCSI session
449  * @ret rc Return status code
450  */
451 static int ibft_fill_target_reverse_chap ( struct ibft_target *target,
452  struct ibft_strings *strings,
453  struct iscsi_session *iscsi ) {
454  int rc;
455 
456  if ( ! ( iscsi->status & ISCSI_STATUS_AUTH_REVERSE_REQUIRED ) )
457  return 0;
458 
459  assert ( iscsi->initiator_username );
460  assert ( iscsi->initiator_password );
461  assert ( iscsi->target_username );
462  assert ( iscsi->target_password );
463 
464  target->chap_type = IBFT_CHAP_MUTUAL;
465  if ( ( rc = ibft_set_string ( strings, &target->reverse_chap_name,
466  iscsi->target_username ) ) != 0 )
467  return rc;
468  DBG ( "iBFT target %d reverse username = %s\n", target->header.index,
469  ibft_string ( strings, &target->chap_name ) );
470  if ( ( rc = ibft_set_string ( strings, &target->reverse_chap_secret,
471  iscsi->target_password ) ) != 0 )
472  return rc;
473  DBG ( "iBFT target %d reverse password = <redacted>\n",
474  target->header.index );
475 
476  return 0;
477 }
478 
479 /**
480  * Fill in Target portion of iBFT
481  *
482  * @v target Target portion of iBFT
483  * @v strings iBFT string block descriptor
484  * @v iscsi iSCSI session
485  * @ret rc Return status code
486  */
487 static int ibft_fill_target ( struct ibft_target *target,
488  struct ibft_strings *strings,
489  struct iscsi_session *iscsi ) {
490  struct sockaddr_tcpip *st_target =
491  ( struct sockaddr_tcpip * ) &iscsi->target_sockaddr;
492  struct sockaddr_in *sin_target =
493  ( struct sockaddr_in * ) &iscsi->target_sockaddr;
494  int rc;
495 
496  /* Fill in common header */
498  target->header.version = 1;
499  target->header.length = cpu_to_le16 ( sizeof ( *target ) );
502 
503  /* Fill in Target values */
504  ibft_set_ipaddr ( &target->ip_address, sin_target->sin_addr );
505  DBG ( "iBFT target %d IP = %s\n",
506  target->header.index, ibft_ipaddr ( &target->ip_address ) );
507  target->socket = cpu_to_le16 ( ntohs ( st_target->st_port ) );
508  DBG ( "iBFT target %d port = %d\n",
509  target->header.index, target->socket );
510  memcpy ( &target->boot_lun, &iscsi->lun, sizeof ( target->boot_lun ) );
511  DBG ( "iBFT target %d boot LUN = " SCSI_LUN_FORMAT "\n",
512  target->header.index, SCSI_LUN_DATA ( target->boot_lun ) );
513  if ( ( rc = ibft_set_string ( strings, &target->target_name,
514  iscsi->target_iqn ) ) != 0 )
515  return rc;
516  DBG ( "iBFT target %d name = %s\n", target->header.index,
517  ibft_string ( strings, &target->target_name ) );
518  if ( ( rc = ibft_fill_target_nic_association ( target, iscsi ) ) != 0 )
519  return rc;
520  if ( ( rc = ibft_fill_target_chap ( target, strings, iscsi ) ) != 0 )
521  return rc;
522  if ( ( rc = ibft_fill_target_reverse_chap ( target, strings,
523  iscsi ) ) != 0 )
524  return rc;
525 
526  return 0;
527 }
528 
529 /**
530  * Check if iBFT descriptor is complete
531  *
532  * @v desc ACPI descriptor
533  * @ret rc Return status code
534  */
535 static int ibft_complete ( struct acpi_descriptor *desc ) {
536  struct iscsi_session *iscsi =
537  container_of ( desc, struct iscsi_session, desc );
538 
539  /* Fail if we do not yet have the target address */
540  if ( ! iscsi->target_sockaddr.sa_family )
541  return -EAGAIN;
542 
543  return 0;
544 }
545 
546 /**
547  * Install iBFT
548  *
549  * @v install Installation method
550  * @ret rc Return status code
551  */
552 static int ibft_install ( int ( * install ) ( struct acpi_header *acpi ) ) {
553  struct net_device *netdev;
554  struct iscsi_session *iscsi;
555  struct ibft_table *table;
556  struct ibft_initiator *initiator;
557  struct ibft_nic *nic;
558  struct ibft_target *target;
559  struct ibft_strings strings;
560  struct acpi_header *acpi;
561  void *data;
562  unsigned int targets = 0;
563  unsigned int pairs = 0;
564  size_t offset = 0;
565  size_t table_len;
566  size_t control_len;
567  size_t initiator_offset;
568  size_t nic_offset;
569  size_t target_offset;
570  size_t strings_offset;
571  size_t len;
572  unsigned int i;
573  int rc;
574 
575  /* Calculate table sizes and offsets */
576  list_for_each_entry ( iscsi, &ibft_model.descs, desc.list )
577  targets++;
578  pairs = ( sizeof ( table->control.pair ) /
579  sizeof ( table->control.pair[0] ) );
580  if ( pairs < targets )
581  pairs = targets;
582  offset = offsetof ( typeof ( *table ), control.pair );
583  offset += ( pairs * sizeof ( table->control.pair[0] ) );
584  table_len = offset;
585  control_len = ( table_len - offsetof ( typeof ( *table ), control ) );
586  offset = ibft_align ( offset );
587  initiator_offset = offset;
588  offset += ibft_align ( sizeof ( *initiator ) );
589  nic_offset = offset;
590  offset += ( pairs * ibft_align ( sizeof ( *nic ) ) );
591  target_offset = offset;
592  offset += ( pairs * ibft_align ( sizeof ( *target ) ) );
593  strings_offset = offset;
594  strings.data = NULL;
595  strings.start = strings_offset;
596  strings.len = 0;
597  len = offset;
598 
599  /* Do nothing if no targets exist */
600  if ( ! targets ) {
601  rc = 0;
602  goto no_targets;
603  }
604 
605  /* Allocate table */
606  data = zalloc ( len );
607  if ( ! data ) {
608  rc = -ENOMEM;
609  goto err_alloc;
610  }
611 
612  /* Fill in Control block */
613  table = data;
615  table->control.header.version = 1;
616  table->control.header.length = cpu_to_le16 ( control_len );
617 
618  /* Fill in Initiator block */
619  initiator = ( data + initiator_offset );
620  table->control.initiator = cpu_to_le16 ( initiator_offset );
621  iscsi = list_first_entry ( &ibft_model.descs, struct iscsi_session,
622  desc.list );
623  if ( ( rc = ibft_fill_initiator ( initiator, &strings,
624  iscsi->initiator_iqn ) ) != 0 )
625  goto err_initiator;
626 
627  /* Fill in NIC blocks */
628  i = 0;
629  for_each_netdev ( netdev ) {
630  if ( ! ibft_netdev_is_required ( netdev ) )
631  continue;
632  assert ( i < pairs );
633  table->control.pair[i].nic = nic_offset;
634  nic = ( data + nic_offset );
635  nic->header.index = i;
636  if ( ( rc = ibft_fill_nic ( nic, &strings, netdev ) ) != 0 )
637  goto err_nic;
638  i++;
639  nic_offset += ibft_align ( sizeof ( *nic ) );
640  }
641 
642  /* Fill in Target blocks */
643  i = 0;
644  list_for_each_entry ( iscsi, &ibft_model.descs, desc.list ) {
645  assert ( i < pairs );
646  table->control.pair[i].target = target_offset;
647  target = ( data + target_offset );
648  target->header.index = i;
649  if ( ( rc = ibft_fill_target ( target, &strings, iscsi ) ) != 0)
650  goto err_target;
651  i++;
652  target_offset += ibft_align ( sizeof ( *target ) );
653  }
654 
655  /* Reallocate table to include space for strings */
656  len += strings.len;
657  acpi = realloc ( data, len );
658  if ( ! acpi )
659  goto err_realloc;
660  data = NULL;
661 
662  /* Fill in ACPI header */
663  acpi->signature = cpu_to_le32 ( IBFT_SIG );
664  acpi->length = cpu_to_le32 ( len );
665  acpi->revision = 1;
666 
667  /* Append strings */
668  memcpy ( ( ( ( void * ) acpi ) + strings_offset ), strings.data,
669  strings.len );
670 
671  /* Install ACPI table */
672  if ( ( rc = install ( acpi ) ) != 0 ) {
673  DBG ( "iBFT could not install: %s\n", strerror ( rc ) );
674  goto err_install;
675  }
676 
677  err_install:
678  free ( acpi );
679  err_realloc:
680  err_target:
681  err_nic:
682  err_initiator:
683  free ( data );
684  err_alloc:
685  no_targets:
686  free ( strings.data );
687  return rc;
688 }
689 
690 /** iBFT model */
691 struct acpi_model ibft_model __acpi_model = {
692  .descs = LIST_HEAD_INIT ( ibft_model.descs ),
693  .complete = ibft_complete,
694  .install = ibft_install,
695 };
#define ISCSI_STATUS_AUTH_REVERSE_REQUIRED
Initiator requires target (reverse) authentication.
Definition: iscsi.h:708
struct ibft_string initiator_name
Initiator name.
Definition: ibft.h:155
#define EINVAL
Invalid argument.
Definition: errno.h:428
TCP/IP socket address.
Definition: tcpip.h:75
static int ibft_complete(struct acpi_descriptor *desc)
Check if iBFT descriptor is complete.
Definition: ibft.c:535
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define IBFT_FL_TARGET_FIRMWARE_BOOT_SELECTED
Target firmware boot selected.
Definition: ibft.h:258
Dynamic Host Configuration Protocol.
ibft_off_t nic
Offset to NIC structure.
Definition: ibft.h:112
struct net_device * tcpip_netdev(struct sockaddr_tcpip *st_dest)
Determine transmitting network device.
Definition: tcpip.c:114
uint64_t origin
Origin.
Definition: hyperv.h:20
uint8_t version
Version (always 1)
Definition: ibft.h:91
char * initiator_username
Initiator username (if any)
Definition: iscsi.h:572
An iSCSI session.
Definition: iscsi.h:544
__be32 in[4]
Definition: CIB_PRM.h:35
struct sockaddr target_sockaddr
Target socket address (for boot firmware table)
Definition: iscsi.h:661
struct ibft_string reverse_chap_secret
Reverse CHAP secret.
Definition: ibft.h:248
ibft_off_t initiator
Offset to Initiator structure.
Definition: ibft.h:127
static void ibft_set_ipaddr_setting(struct settings *settings, struct ibft_ipaddr *ipaddr, const struct setting *setting, unsigned int count)
Fill in an IP address within iBFT from configuration setting.
Definition: ibft.c:110
size_t len
Total length.
Definition: ibft.c:74
int flags
Definition: nic.h:51
Error codes.
struct list_head descs
List of descriptors.
Definition: acpi.h:306
struct settings * parent
Parent settings block.
Definition: settings.h:138
int fetch_ipv4_setting(struct settings *settings, const struct setting *setting, struct in_addr *inp)
Fetch value of IPv4 address setting.
Definition: settings.c:912
static const char * ibft_ipaddr(struct ibft_ipaddr *ipaddr)
Read IP address from iBFT (for debugging)
Definition: ibft.c:130
struct scsi_lun boot_lun
Boot LUN.
Definition: ibft.h:231
iBFT NIC structure
Definition: ibft.h:171
#define IBFT_CHAP_MUTUAL
Mutual CHAP.
Definition: ibft.h:269
uint64_t desc
Microcode descriptor list physical address.
Definition: ucode.h:12
sa_family_t sa_family
Socket address family.
Definition: socket.h:101
uint8_t chap_type
CHAP type.
Definition: ibft.h:236
struct ibft_string chap_name
CHAP name.
Definition: ibft.h:242
#define IBFT_ALIGN
Alignment of structures within iBFT.
Definition: ibft.h:53
uint32_t string
Definition: multiboot.h:14
static int ibft_install(int(*install)(struct acpi_header *acpi))
Install iBFT.
Definition: ibft.c:552
struct ibft_control control
Control structure.
Definition: ibft.h:280
IPv4 socket address.
Definition: in.h:84
#define ntohs(value)
Definition: byteswap.h:136
struct ibft_string chap_secret
CHAP secret.
Definition: ibft.h:244
#define offsetof(type, field)
Get offset of a field within a structure.
Definition: stddef.h:24
#define IBFT_STRUCTURE_ID_CONTROL
Structure ID for Control section.
Definition: ibft.h:133
static int ibft_netdev_is_required(struct net_device *netdev)
Check if network device is required for the iBFT.
Definition: ibft.c:245
struct ibft_string target_name
Target name.
Definition: ibft.h:240
#define IBFT_FL_INITIATOR_FIRMWARE_BOOT_SELECTED
Initiator firmware boot selected.
Definition: ibft.h:165
static struct settings * netdev_settings(struct net_device *netdev)
Get per-netdevice configuration settings block.
Definition: netdevice.h:583
A link-layer protocol.
Definition: netdevice.h:114
uint16_t length
Length, including this header.
Definition: ibft.h:93
char * initiator_password
Initiator password (if any)
Definition: iscsi.h:574
An IP address within the iBFT.
Definition: ibft.h:70
iBFT Target structure
Definition: ibft.h:223
#define list_first_entry(list, type, member)
Get the container of the first entry in a list.
Definition: list.h:333
iSCSI Boot Firmware Table (iBFT)
Definition: ibft.h:274
#define ENOMEM
Not enough space.
Definition: errno.h:534
uint8_t flags
Flags.
Definition: ibft.h:100
void * memcpy(void *dest, const void *src, size_t len) __nonnull
#define IBFT_CHAP_ONE_WAY
One-way CHAP.
Definition: ibft.h:268
struct ibft_header header
Common header.
Definition: ibft.h:147
static int ibft_fill_nic(struct ibft_nic *nic, struct ibft_strings *strings, struct net_device *netdev)
Fill in NIC portion of iBFT.
Definition: ibft.c:266
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
Ethernet protocol.
An ACPI table model.
Definition: acpi.h:304
static int ibft_fill_target_nic_association(struct ibft_target *target, struct iscsi_session *iscsi)
Fill in Target NIC association.
Definition: ibft.c:377
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:431
static EFI_ACPI_TABLE_PROTOCOL * acpi
ACPI table protocol protocol.
Definition: efi_block.c:65
struct ibft_ipaddr ip_address
IP address.
Definition: ibft.h:227
int status
Session status.
Definition: iscsi.h:569
iSCSI protocol
#define IBFT_FL_NIC_BLOCK_VALID
NIC block valid.
Definition: ibft.h:203
static struct net_device * netdev
Definition: gdbudp.c:52
Transport-network layer interface.
uint16_t count
Number of entries.
Definition: ena.h:22
#define IBFT_FL_INITIATOR_BLOCK_VALID
Initiator block valid.
Definition: ibft.h:162
int fetch_string_setting(struct settings *settings, const struct setting *setting, char *data, size_t len)
Fetch value of string setting.
Definition: settings.c:841
char * strcpy(char *dest, const char *src)
Copy string.
Definition: string.c:346
unsigned int location
Location.
Definition: device.h:29
#define cpu_to_le32(value)
Definition: byteswap.h:107
uint16_t st_port
TCP/IP port.
Definition: tcpip.h:81
#define IBFT_NIC_ORIGIN_DHCP
Definition: ibft.h:215
int fetch_setting(struct settings *settings, const struct setting *setting, struct settings **origin, struct setting *fetched, void *data, size_t len)
Fetch setting.
Definition: settings.c:666
#define IBFT_FL_TARGET_BLOCK_VALID
Target block valid.
Definition: ibft.h:255
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static size_t ibft_align(size_t len)
Align structure within iBFT.
Definition: ibft.c:83
ACPI data structures.
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
struct scsi_lun lun
SCSI LUN (for boot firmware table)
Definition: iscsi.h:663
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
IP address structure.
Definition: in.h:41
#define for_each_netdev(netdev)
Iterate over all network devices.
Definition: netdevice.h:543
PCI bus.
static int ibft_fill_initiator(struct ibft_initiator *initiator, struct ibft_strings *strings, const char *initiator_iqn)
Fill in Initiator portion of iBFT.
Definition: ibft.c:348
static int ibft_set_string(struct ibft_strings *strings, struct ibft_string *string, const char *data)
Fill in a string field within iBFT.
Definition: ibft.c:177
const char * eth_ntoa(const void *ll_addr)
Transcribe Ethernet address.
Definition: ethernet.c:175
uint32_t control
Control.
Definition: myson.h:14
FILE_LICENCE(BSD2)
A network device.
Definition: netdevice.h:352
size_t strlen(const char *src)
Get length of string.
Definition: string.c:243
char * inet_ntoa(struct in_addr in)
Convert IPv4 address to dotted-quad notation.
Definition: ipv4.c:668
A settings block.
Definition: settings.h:132
iSCSI string buffer
Definition: ibft.c:68
uint8_t index
Index.
Definition: ibft.h:98
uint8_t nic_association
NIC association.
Definition: ibft.h:238
An ACPI description header.
Definition: acpi.h:163
#define SCSI_LUN_FORMAT
printf() format for dumping a scsi_lun
Definition: scsi.h:241
#define le16_to_cpu(value)
Definition: byteswap.h:112
Definition: nic.h:49
#define EAGAIN
Resource temporarily unavailable.
Definition: errno.h:318
A setting.
Definition: settings.h:23
static int ibft_set_string_setting(struct settings *settings, struct ibft_strings *strings, struct ibft_string *string, const struct setting *setting)
Fill in a string field within iBFT from configuration setting.
Definition: ibft.c:201
static const char * ibft_string(struct ibft_strings *strings, struct ibft_string *string)
Read string from iBFT (for debugging)
Definition: ibft.c:232
struct device * dev
Underlying hardware device.
Definition: netdevice.h:364
uint32_t s_addr
Definition: in.h:42
Network device management.
#define IBFT_FL_NIC_FIRMWARE_BOOT_SELECTED
NIC firmware boot selected.
Definition: ibft.h:206
#define SCSI_LUN_DATA(lun)
printf() parameters for dumping a scsi_lun
Definition: scsi.h:244
An ACPI descriptor (used to construct ACPI tables)
Definition: acpi.h:278
char * target_iqn
Target IQN.
Definition: iscsi.h:562
struct ibft_header header
Common header.
Definition: ibft.h:123
iSCSI boot firmware table
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:362
int fetch_ipv4_array_setting(struct settings *settings, const struct setting *setting, struct in_addr *inp, unsigned int count)
Fetch value of IPv4 address setting.
Definition: settings.c:890
#define ENOBUFS
No buffer space available.
Definition: errno.h:498
struct ibft_header header
Common header.
Definition: ibft.h:225
#define IBFT_NIC_ORIGIN_MANUAL
Definition: ibft.h:213
struct in_addr in
The IPv4 address, or zero if not present.
Definition: ibft.h:76
struct ibft_offset_pair pair[2]
Offsets to NIC and Target structures.
Definition: ibft.h:129
#define cpu_to_le16(value)
Definition: byteswap.h:106
if(len >=6 *4) __asm__ __volatile__("movsl" if(len >=5 *4) __asm__ __volatile__("movsl" if(len >=4 *4) __asm__ __volatile__("movsl" if(len >=3 *4) __asm__ __volatile__("movsl" if(len >=2 *4) __asm__ __volatile__("movsl" if(len >=1 *4) __asm__ __volatile__("movsl" if((len % 4) >=2) __asm__ __volatile__("movsw" if((len % 2) >=1) __asm__ __volatile__("movsb" return dest
Definition: string.h:150
uint8_t data[48]
Additional event data.
Definition: ena.h:22
Virtual LANs.
struct device_description desc
Device description.
Definition: device.h:79
iBFT Initiator structure
Definition: ibft.h:145
size_t start
Starting offset of strings.
Definition: ibft.c:72
void * realloc(void *old_ptr, size_t new_size)
Reallocate memory.
Definition: malloc.c:521
ibft_off_t target
Offset to Target structure.
Definition: ibft.h:114
static int ibft_fill_target_chap(struct ibft_target *target, struct ibft_strings *strings, struct iscsi_session *iscsi)
Fill in Target CHAP portion of iBFT.
Definition: ibft.c:418
uint16_t socket
TCP port.
Definition: ibft.h:229
uint16_t offset
Offset to command line.
Definition: bzimage.h:8
char * initiator_iqn
Initiator IQN.
Definition: iscsi.h:556
A string within the iBFT.
Definition: ibft.h:62
typeof(acpi_finder=acpi_find)
ACPI table finder.
Definition: acpi.c:45
struct ibft_string reverse_chap_name
Reverse CHAP name.
Definition: ibft.h:246
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:387
char * target_password
Target password (if any)
Definition: iscsi.h:578
static unsigned int vlan_tag(struct net_device *netdev)
Get the VLAN tag.
Definition: vlan.h:73
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
#define LIST_HEAD_INIT(list)
Initialise a static list head.
Definition: list.h:30
static int ibft_fill_target(struct ibft_target *target, struct ibft_strings *strings, struct iscsi_session *iscsi)
Fill in Target portion of iBFT.
Definition: ibft.c:487
struct nic nic
Definition: legacy.c:22
uint8_t structure_id
Structure ID.
Definition: ibft.h:89
char * target_username
Target username (if any)
Definition: iscsi.h:576
#define EHOSTUNREACH
Host is unreachable.
Definition: errno.h:403
struct acpi_model ibft_model __acpi_model
iBFT model
Definition: ibft.c:691
static int ibft_fill_target_reverse_chap(struct ibft_target *target, struct ibft_strings *strings, struct iscsi_session *iscsi)
Fill in Target Reverse CHAP portion of iBFT.
Definition: ibft.c:451
uint32_t len
Length.
Definition: ena.h:14
#define ISCSI_STATUS_AUTH_FORWARD_REQUIRED
Target has requested forward (initiator) authentication.
Definition: iscsi.h:705
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
uint16_t ones
Must be 0xffff if IPv4 address is present, otherwise zero.
Definition: ibft.h:74
String functions.
#define IBFT_STRUCTURE_ID_NIC
Structure ID for NIC section.
Definition: ibft.h:200
char * data
Strings data.
Definition: ibft.c:70
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:372
static void ibft_set_ipaddr(struct ibft_ipaddr *ipaddr, struct in_addr in)
Fill in an IP address field within iBFT.
Definition: ibft.c:94
#define IBFT_STRUCTURE_ID_INITIATOR
Structure ID for Initiator section.
Definition: ibft.h:159
#define IBFT_STRUCTURE_ID_TARGET
Structure ID for Target section.
Definition: ibft.h:252
if(natsemi->flags &NATSEMI_64BIT) return 1
int(* eth_addr)(const void *ll_addr, void *eth_addr)
Generate Ethernet-compatible compressed link-layer address.
Definition: netdevice.h:181
void * memset(void *dest, int character, size_t len) __nonnull
static char * ibft_alloc_string(struct ibft_strings *strings, struct ibft_string *string, size_t len)
Allocate a string within iBFT.
Definition: ibft.c:142
#define IBFT_SIG
iSCSI Boot Firmware Table signature
Definition: ibft.h:50