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 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  */
57 
58 /**
59  * iSCSI string buffer
60  *
61  * This is an internal structure that we use to keep track of the
62  * allocation of string data.
63  */
64 struct ibft_strings {
65  /** Strings data */
66  char *data;
67  /** Starting offset of strings */
68  size_t start;
69  /** Total length */
70  size_t len;
71 };
72 
73 /**
74  * Align structure within iBFT
75  *
76  * @v len Unaligned length (or offset)
77  * @ret len Aligned length (or offset)
78  */
79 static inline size_t ibft_align ( size_t len ) {
80 
81  return ( ( len + IBFT_ALIGN - 1 ) & ~( IBFT_ALIGN - 1 ) );
82 }
83 
84 /**
85  * Fill in an IP address field within iBFT
86  *
87  * @v ipaddr IP address field
88  * @v in IPv4 address
89  */
90 static void ibft_set_ipaddr ( struct ibft_ipaddr *ipaddr, struct in_addr in ) {
91  memset ( ipaddr, 0, sizeof ( *ipaddr ) );
92  if ( in.s_addr ) {
93  ipaddr->in = in;
94  ipaddr->ones = 0xffff;
95  }
96 }
97 
98 /**
99  * Fill in an IP address within iBFT from configuration setting
100  *
101  * @v settings Parent settings block, or NULL
102  * @v ipaddr IP address field
103  * @v setting Configuration setting
104  * @v count Maximum number of IP addresses
105  */
107  struct ibft_ipaddr *ipaddr,
108  const struct setting *setting,
109  unsigned int count ) {
110  struct in_addr in[count];
111  unsigned int i;
112 
114  for ( i = 0 ; i < count ; i++ ) {
115  ibft_set_ipaddr ( &ipaddr[i], in[i] );
116  }
117 }
118 
119 /**
120  * Read IP address from iBFT (for debugging)
121  *
122  * @v strings iBFT string block descriptor
123  * @v string String field
124  * @ret ipaddr IP address string
125  */
126 static const char * ibft_ipaddr ( struct ibft_ipaddr *ipaddr ) {
127  return inet_ntoa ( ipaddr->in );
128 }
129 
130 /**
131  * Allocate a string within iBFT
132  *
133  * @v strings iBFT string block descriptor
134  * @v string String field to fill in
135  * @v len Length of string to allocate (excluding NUL)
136  * @ret dest String destination, or NULL
137  */
138 static char * ibft_alloc_string ( struct ibft_strings *strings,
139  struct ibft_string *string, size_t len ) {
140  size_t new_len;
141  char *new_data;
142  char *dest;
143 
144  /* Extend string data buffer */
145  new_len = ( strings->len + len + 1 /* NUL */ );
146  new_data = realloc ( strings->data, new_len );
147  if ( ! new_data )
148  return NULL;
149  strings->data = new_data;
150 
151  /* Fill in string field */
152  string->offset = cpu_to_le16 ( strings->start + strings->len );
153  string->len = cpu_to_le16 ( len );
154 
155  /* Zero string */
156  dest = ( strings->data + strings->len );
157  memset ( dest, 0, ( len + 1 /* NUL */ ) );
158 
159  /* Update allocated length */
160  strings->len = new_len;
161 
162  return dest;
163 }
164 
165 /**
166  * Fill in a string field within iBFT
167  *
168  * @v strings iBFT string block descriptor
169  * @v string String field
170  * @v data String to fill in, or NULL
171  * @ret rc Return status code
172  */
173 static int ibft_set_string ( struct ibft_strings *strings,
174  struct ibft_string *string, const char *data ) {
175  char *dest;
176 
177  if ( ! data )
178  return 0;
179 
180  dest = ibft_alloc_string ( strings, string, strlen ( data ) );
181  if ( ! dest )
182  return -ENOBUFS;
183  strcpy ( dest, data );
184 
185  return 0;
186 }
187 
188 /**
189  * Fill in a string field within iBFT from configuration setting
190  *
191  * @v settings Parent settings block, or NULL
192  * @v strings iBFT string block descriptor
193  * @v string String field
194  * @v setting Configuration setting
195  * @ret rc Return status code
196  */
198  struct ibft_strings *strings,
199  struct ibft_string *string,
200  const struct setting *setting ) {
201  struct settings *origin;
202  struct setting fetched;
203  int len;
204  char *dest;
205 
206  len = fetch_setting ( settings, setting, &origin, &fetched, NULL, 0 );
207  if ( len < 0 ) {
208  string->offset = 0;
209  string->len = 0;
210  return 0;
211  }
212 
213  dest = ibft_alloc_string ( strings, string, len );
214  if ( ! dest )
215  return -ENOBUFS;
216  fetch_string_setting ( origin, &fetched, dest, ( len + 1 ));
217 
218  return 0;
219 }
220 
221 /**
222  * Read string from iBFT (for debugging)
223  *
224  * @v strings iBFT string block descriptor
225  * @v string String field
226  * @ret data String content (or "<empty>")
227  */
228 static const char * ibft_string ( struct ibft_strings *strings,
229  struct ibft_string *string ) {
230  size_t offset = le16_to_cpu ( string->offset );
231 
232  return ( offset ? ( strings->data + offset - strings->start ) : NULL );
233 }
234 
235 /**
236  * Check if network device is required for the iBFT
237  *
238  * @v netdev Network device
239  * @ret is_required Network device is required
240  */
241 static int ibft_netdev_is_required ( struct net_device *netdev ) {
242  struct iscsi_session *iscsi;
243  struct sockaddr_tcpip *st_target;
244 
245  list_for_each_entry ( iscsi, &ibft_model.descs, desc.list ) {
246  st_target = ( struct sockaddr_tcpip * ) &iscsi->target_sockaddr;
247  if ( tcpip_netdev ( st_target ) == netdev )
248  return 1;
249  }
250 
251  return 0;
252 }
253 
254 /**
255  * Fill in NIC portion of iBFT
256  *
257  * @v nic NIC portion of iBFT
258  * @v strings iBFT string block descriptor
259  * @v netdev Network device
260  * @ret rc Return status code
261  */
262 static int ibft_fill_nic ( struct ibft_nic *nic,
263  struct ibft_strings *strings,
264  struct net_device *netdev ) {
266  struct in_addr netmask_addr = { 0 };
267  unsigned int netmask_count = 0;
268  struct settings *parent = netdev_settings ( netdev );
269  struct settings *origin;
270  int rc;
271 
272  /* Fill in common header */
273  nic->header.structure_id = IBFT_STRUCTURE_ID_NIC;
274  nic->header.version = 1;
275  nic->header.length = cpu_to_le16 ( sizeof ( *nic ) );
276  nic->header.flags = ( IBFT_FL_NIC_BLOCK_VALID |
278  DBG ( "iBFT NIC %d is %s\n", nic->header.index, netdev->name );
279 
280  /* Determine origin of IP address */
281  fetch_setting ( parent, &ip_setting, &origin, NULL, NULL, 0 );
282  nic->origin = ( ( origin == parent ) ?
284  DBG ( "iBFT NIC %d origin = %d\n", nic->header.index, nic->origin );
285 
286  /* Extract values from configuration settings */
287  ibft_set_ipaddr_setting ( parent, &nic->ip_address, &ip_setting, 1 );
288  DBG ( "iBFT NIC %d IP = %s\n",
289  nic->header.index, ibft_ipaddr ( &nic->ip_address ) );
290  ibft_set_ipaddr_setting ( parent, &nic->gateway, &gateway_setting, 1 );
291  DBG ( "iBFT NIC %d gateway = %s\n",
292  nic->header.index, ibft_ipaddr ( &nic->gateway ) );
293  ibft_set_ipaddr_setting ( NULL, &nic->dns[0], &dns_setting,
294  ( sizeof ( nic->dns ) /
295  sizeof ( nic->dns[0] ) ) );
296  ibft_set_ipaddr_setting ( parent, &nic->dhcp, &dhcp_server_setting, 1 );
297  DBG ( "iBFT NIC %d DNS = %s",
298  nic->header.index, ibft_ipaddr ( &nic->dns[0] ) );
299  DBG ( ", %s\n", ibft_ipaddr ( &nic->dns[1] ) );
300  if ( ( rc = ibft_set_string_setting ( NULL, strings, &nic->hostname,
301  &hostname_setting ) ) != 0 )
302  return rc;
303  DBG ( "iBFT NIC %d hostname = %s\n",
304  nic->header.index, ibft_string ( strings, &nic->hostname ) );
305 
306  /* Derive subnet mask prefix from subnet mask */
307  fetch_ipv4_setting ( parent, &netmask_setting, &netmask_addr );
308  while ( netmask_addr.s_addr ) {
309  if ( netmask_addr.s_addr & 0x1 )
310  netmask_count++;
311  netmask_addr.s_addr >>= 1;
312  }
313  nic->subnet_mask_prefix = netmask_count;
314  DBG ( "iBFT NIC %d subnet = /%d\n",
315  nic->header.index, nic->subnet_mask_prefix );
316 
317  /* Extract values from net-device configuration */
318  nic->vlan = cpu_to_le16 ( vlan_tag ( netdev ) );
319  DBG ( "iBFT NIC %d VLAN = %02x\n",
320  nic->header.index, le16_to_cpu ( nic->vlan ) );
321  if ( ( rc = ll_protocol->eth_addr ( netdev->ll_addr,
322  nic->mac_address ) ) != 0 ) {
323  DBG ( "Could not determine %s MAC: %s\n",
324  netdev->name, strerror ( rc ) );
325  return rc;
326  }
327  DBG ( "iBFT NIC %d MAC = %s\n",
328  nic->header.index, eth_ntoa ( nic->mac_address ) );
329  nic->pci_bus_dev_func = cpu_to_le16 ( netdev->dev->desc.location );
330  DBG ( "iBFT NIC %d PCI = %04x\n",
331  nic->header.index, le16_to_cpu ( nic->pci_bus_dev_func ) );
332 
333  return 0;
334 }
335 
336 /**
337  * Fill in Initiator portion of iBFT
338  *
339  * @v initiator Initiator portion of iBFT
340  * @v strings iBFT string block descriptor
341  * @v initiator_iqn Initiator IQN
342  * @ret rc Return status code
343  */
344 static int ibft_fill_initiator ( struct ibft_initiator *initiator,
345  struct ibft_strings *strings,
346  const char *initiator_iqn ) {
347  int rc;
348 
349  /* Fill in common header */
351  initiator->header.version = 1;
352  initiator->header.length = cpu_to_le16 ( sizeof ( *initiator ) );
355 
356  /* Fill in initiator name */
357  if ( ( rc = ibft_set_string ( strings, &initiator->initiator_name,
358  initiator_iqn ) ) != 0 )
359  return rc;
360  DBG ( "iBFT initiator name = %s\n",
361  ibft_string ( strings, &initiator->initiator_name ) );
362 
363  return 0;
364 }
365 
366 /**
367  * Fill in Target NIC association
368  *
369  * @v target Target portion of iBFT
370  * @v iscsi iSCSI session
371  * @ret rc Return status code
372  */
373 static int ibft_fill_target_nic_association ( struct ibft_target *target,
374  struct iscsi_session *iscsi ) {
375  struct sockaddr_tcpip *st_target =
376  ( struct sockaddr_tcpip * ) &iscsi->target_sockaddr;
377  struct net_device *associated;
378  struct net_device *netdev;
379 
380  /* Find network device used to reach target */
381  associated = tcpip_netdev ( st_target );
382  if ( ! associated ) {
383  DBG ( "iBFT target %d has no net device\n",
384  target->header.index );
385  return -EHOSTUNREACH;
386  }
387 
388  /* Calculate association */
389  for_each_netdev ( netdev ) {
390  if ( netdev == associated ) {
391  DBG ( "iBFT target %d uses NIC %d (%s)\n",
392  target->header.index, target->nic_association,
393  netdev->name );
394  return 0;
395  }
396  if ( ! ibft_netdev_is_required ( netdev ) )
397  continue;
398  target->nic_association++;
399  }
400 
401  DBG ( "iBFT target %d has impossible NIC %s\n",
402  target->header.index, netdev->name );
403  return -EINVAL;
404 }
405 
406 /**
407  * Fill in Target CHAP portion of iBFT
408  *
409  * @v target Target portion of iBFT
410  * @v strings iBFT string block descriptor
411  * @v iscsi iSCSI session
412  * @ret rc Return status code
413  */
414 static int ibft_fill_target_chap ( struct ibft_target *target,
415  struct ibft_strings *strings,
416  struct iscsi_session *iscsi ) {
417  int rc;
418 
419  if ( ! ( iscsi->status & ISCSI_STATUS_AUTH_FORWARD_REQUIRED ) )
420  return 0;
421 
422  assert ( iscsi->initiator_username );
423  assert ( iscsi->initiator_password );
424 
425  target->chap_type = IBFT_CHAP_ONE_WAY;
426  if ( ( rc = ibft_set_string ( strings, &target->chap_name,
427  iscsi->initiator_username ) ) != 0 )
428  return rc;
429  DBG ( "iBFT target %d username = %s\n", target->header.index,
430  ibft_string ( strings, &target->chap_name ) );
431  if ( ( rc = ibft_set_string ( strings, &target->chap_secret,
432  iscsi->initiator_password ) ) != 0 )
433  return rc;
434  DBG ( "iBFT target %d password = <redacted>\n", target->header.index );
435 
436  return 0;
437 }
438 
439 /**
440  * Fill in Target Reverse CHAP portion of iBFT
441  *
442  * @v target Target portion of iBFT
443  * @v strings iBFT string block descriptor
444  * @v iscsi iSCSI session
445  * @ret rc Return status code
446  */
447 static int ibft_fill_target_reverse_chap ( struct ibft_target *target,
448  struct ibft_strings *strings,
449  struct iscsi_session *iscsi ) {
450  int rc;
451 
452  if ( ! ( iscsi->status & ISCSI_STATUS_AUTH_REVERSE_REQUIRED ) )
453  return 0;
454 
455  assert ( iscsi->initiator_username );
456  assert ( iscsi->initiator_password );
457  assert ( iscsi->target_username );
458  assert ( iscsi->target_password );
459 
460  target->chap_type = IBFT_CHAP_MUTUAL;
461  if ( ( rc = ibft_set_string ( strings, &target->reverse_chap_name,
462  iscsi->target_username ) ) != 0 )
463  return rc;
464  DBG ( "iBFT target %d reverse username = %s\n", target->header.index,
465  ibft_string ( strings, &target->chap_name ) );
466  if ( ( rc = ibft_set_string ( strings, &target->reverse_chap_secret,
467  iscsi->target_password ) ) != 0 )
468  return rc;
469  DBG ( "iBFT target %d reverse password = <redacted>\n",
470  target->header.index );
471 
472  return 0;
473 }
474 
475 /**
476  * Fill in Target portion of iBFT
477  *
478  * @v target Target portion of iBFT
479  * @v strings iBFT string block descriptor
480  * @v iscsi iSCSI session
481  * @ret rc Return status code
482  */
483 static int ibft_fill_target ( struct ibft_target *target,
484  struct ibft_strings *strings,
485  struct iscsi_session *iscsi ) {
486  struct sockaddr_tcpip *st_target =
487  ( struct sockaddr_tcpip * ) &iscsi->target_sockaddr;
488  struct sockaddr_in *sin_target =
489  ( struct sockaddr_in * ) &iscsi->target_sockaddr;
490  int rc;
491 
492  /* Fill in common header */
494  target->header.version = 1;
495  target->header.length = cpu_to_le16 ( sizeof ( *target ) );
498 
499  /* Fill in Target values */
500  ibft_set_ipaddr ( &target->ip_address, sin_target->sin_addr );
501  DBG ( "iBFT target %d IP = %s\n",
502  target->header.index, ibft_ipaddr ( &target->ip_address ) );
503  target->socket = cpu_to_le16 ( ntohs ( st_target->st_port ) );
504  DBG ( "iBFT target %d port = %d\n",
505  target->header.index, target->socket );
506  memcpy ( &target->boot_lun, &iscsi->lun, sizeof ( target->boot_lun ) );
507  DBG ( "iBFT target %d boot LUN = " SCSI_LUN_FORMAT "\n",
508  target->header.index, SCSI_LUN_DATA ( target->boot_lun ) );
509  if ( ( rc = ibft_set_string ( strings, &target->target_name,
510  iscsi->target_iqn ) ) != 0 )
511  return rc;
512  DBG ( "iBFT target %d name = %s\n", target->header.index,
513  ibft_string ( strings, &target->target_name ) );
514  if ( ( rc = ibft_fill_target_nic_association ( target, iscsi ) ) != 0 )
515  return rc;
516  if ( ( rc = ibft_fill_target_chap ( target, strings, iscsi ) ) != 0 )
517  return rc;
518  if ( ( rc = ibft_fill_target_reverse_chap ( target, strings,
519  iscsi ) ) != 0 )
520  return rc;
521 
522  return 0;
523 }
524 
525 /**
526  * Check if iBFT descriptor is complete
527  *
528  * @v desc ACPI descriptor
529  * @ret rc Return status code
530  */
531 static int ibft_complete ( struct acpi_descriptor *desc ) {
532  struct iscsi_session *iscsi =
533  container_of ( desc, struct iscsi_session, desc );
534 
535  /* Fail if we do not yet have the target address */
536  if ( ! iscsi->target_sockaddr.sa_family )
537  return -EAGAIN;
538 
539  return 0;
540 }
541 
542 /**
543  * Install iBFT
544  *
545  * @v install Installation method
546  * @ret rc Return status code
547  */
548 static int ibft_install ( int ( * install ) ( struct acpi_header *acpi ) ) {
549  struct net_device *netdev;
550  struct iscsi_session *iscsi;
551  struct ibft_table *table;
552  struct ibft_initiator *initiator;
553  struct ibft_nic *nic;
554  struct ibft_target *target;
555  struct ibft_strings strings;
556  struct acpi_header *acpi;
557  void *data;
558  unsigned int targets = 0;
559  unsigned int pairs = 0;
560  size_t offset = 0;
561  size_t table_len;
562  size_t control_len;
563  size_t initiator_offset;
564  size_t nic_offset;
565  size_t target_offset;
566  size_t strings_offset;
567  size_t len;
568  unsigned int i;
569  int rc;
570 
571  /* Calculate table sizes and offsets */
572  list_for_each_entry ( iscsi, &ibft_model.descs, desc.list )
573  targets++;
574  pairs = ( sizeof ( table->control.pair ) /
575  sizeof ( table->control.pair[0] ) );
576  if ( pairs < targets )
577  pairs = targets;
578  offset = offsetof ( typeof ( *table ), control.pair );
579  offset += ( pairs * sizeof ( table->control.pair[0] ) );
580  table_len = offset;
581  control_len = ( table_len - offsetof ( typeof ( *table ), control ) );
582  offset = ibft_align ( offset );
583  initiator_offset = offset;
584  offset += ibft_align ( sizeof ( *initiator ) );
585  nic_offset = offset;
586  offset += ( pairs * ibft_align ( sizeof ( *nic ) ) );
587  target_offset = offset;
588  offset += ( pairs * ibft_align ( sizeof ( *target ) ) );
589  strings_offset = offset;
590  strings.data = NULL;
591  strings.start = strings_offset;
592  strings.len = 0;
593  len = offset;
594 
595  /* Do nothing if no targets exist */
596  if ( ! targets ) {
597  rc = 0;
598  goto no_targets;
599  }
600 
601  /* Allocate table */
602  data = zalloc ( len );
603  if ( ! data ) {
604  rc = -ENOMEM;
605  goto err_alloc;
606  }
607 
608  /* Fill in Control block */
609  table = data;
611  table->control.header.version = 1;
612  table->control.header.length = cpu_to_le16 ( control_len );
613 
614  /* Fill in Initiator block */
615  initiator = ( data + initiator_offset );
616  table->control.initiator = cpu_to_le16 ( initiator_offset );
617  iscsi = list_first_entry ( &ibft_model.descs, struct iscsi_session,
618  desc.list );
619  if ( ( rc = ibft_fill_initiator ( initiator, &strings,
620  iscsi->initiator_iqn ) ) != 0 )
621  goto err_initiator;
622 
623  /* Fill in NIC blocks */
624  i = 0;
625  for_each_netdev ( netdev ) {
626  if ( ! ibft_netdev_is_required ( netdev ) )
627  continue;
628  assert ( i < pairs );
629  table->control.pair[i].nic = nic_offset;
630  nic = ( data + nic_offset );
631  nic->header.index = i;
632  if ( ( rc = ibft_fill_nic ( nic, &strings, netdev ) ) != 0 )
633  goto err_nic;
634  i++;
635  nic_offset += ibft_align ( sizeof ( *nic ) );
636  }
637 
638  /* Fill in Target blocks */
639  i = 0;
640  list_for_each_entry ( iscsi, &ibft_model.descs, desc.list ) {
641  assert ( i < pairs );
642  table->control.pair[i].target = target_offset;
643  target = ( data + target_offset );
644  target->header.index = i;
645  if ( ( rc = ibft_fill_target ( target, &strings, iscsi ) ) != 0)
646  goto err_target;
647  i++;
648  target_offset += ibft_align ( sizeof ( *target ) );
649  }
650 
651  /* Reallocate table to include space for strings */
652  len += strings.len;
653  acpi = realloc ( data, len );
654  if ( ! acpi )
655  goto err_realloc;
656  data = NULL;
657 
658  /* Fill in ACPI header */
659  acpi->signature = cpu_to_le32 ( IBFT_SIG );
660  acpi->length = cpu_to_le32 ( len );
661  acpi->revision = 1;
662 
663  /* Append strings */
664  memcpy ( ( ( ( void * ) acpi ) + strings_offset ), strings.data,
665  strings.len );
666 
667  /* Install ACPI table */
668  if ( ( rc = install ( acpi ) ) != 0 ) {
669  DBG ( "iBFT could not install: %s\n", strerror ( rc ) );
670  goto err_install;
671  }
672 
673  err_install:
674  free ( acpi );
675  err_realloc:
676  err_target:
677  err_nic:
678  err_initiator:
679  free ( data );
680  err_alloc:
681  no_targets:
682  free ( strings.data );
683  return rc;
684 }
685 
686 /** iBFT model */
687 struct acpi_model ibft_model __acpi_model = {
688  .descs = LIST_HEAD_INIT ( ibft_model.descs ),
689  .complete = ibft_complete,
690  .install = ibft_install,
691 };
#define ISCSI_STATUS_AUTH_REVERSE_REQUIRED
Initiator requires target (reverse) authentication.
Definition: iscsi.h:696
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:531
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:563
An iSCSI session.
Definition: iscsi.h:535
__be32 in[4]
Definition: CIB_PRM.h:35
struct sockaddr target_sockaddr
Target socket address (for boot firmware table)
Definition: iscsi.h:649
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:106
size_t len
Total length.
Definition: ibft.c:70
int flags
Definition: nic.h:51
Error codes.
struct list_head descs
List of descriptors.
Definition: acpi.h:303
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:916
static const char * ibft_ipaddr(struct ibft_ipaddr *ipaddr)
Read IP address from iBFT (for debugging)
Definition: ibft.c:126
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
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:548
struct ibft_control control
Control structure.
Definition: ibft.h:280
IPv4 socket address.
Definition: in.h:82
#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:241
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:577
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:565
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:262
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:301
static int ibft_fill_target_nic_association(struct ibft_target *target, struct iscsi_session *iscsi)
Fill in Target NIC association.
Definition: ibft.c:373
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:420
static EFI_ACPI_TABLE_PROTOCOL * acpi
ACPI table protocol protocol.
Definition: efi_block.c:61
struct ibft_ipaddr ip_address
IP address.
Definition: ibft.h:227
int status
Session status.
Definition: iscsi.h:560
iSCSI protocol
#define IBFT_FL_NIC_BLOCK_VALID
NIC block valid.
Definition: ibft.h:203
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
static struct net_device * netdev
Definition: gdbudp.c:52
Transport-network layer interface.
#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:845
struct acpi_descriptor desc
ACPI descriptor.
Definition: iscsi.h:653
char * strcpy(char *dest, const char *src)
Copy string.
Definition: string.c:311
unsigned int location
Location.
Definition: device.h:29
static void * dest
Definition: strings.h:176
#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:670
#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:79
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:651
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
IP address structure.
Definition: in.h:39
#define for_each_netdev(netdev)
Iterate over all network devices.
Definition: netdevice.h:526
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:344
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:173
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:348
size_t strlen(const char *src)
Get length of string.
Definition: string.c:228
char * inet_ntoa(struct in_addr in)
Convert IPv4 address to dotted-quad notation.
Definition: ipv4.c:658
A settings block.
Definition: settings.h:132
iSCSI string buffer
Definition: ibft.c:64
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:160
#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:197
static const char * ibft_string(struct ibft_strings *strings, struct ibft_string *string)
Read string from iBFT (for debugging)
Definition: ibft.c:228
struct device * dev
Underlying hardware device.
Definition: netdevice.h:360
uint32_t s_addr
Definition: in.h:40
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:275
char * target_iqn
Target IQN.
Definition: iscsi.h:553
struct ibft_header header
Common header.
Definition: ibft.h:123
iSCSI boot firmware table
__weak unsigned int vlan_tag(struct net_device *netdev __unused)
Get the VLAN tag (when VLAN support is not present)
Definition: netdevice.c:1124
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:358
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:894
uint32_t len
Length.
Definition: ena.h:14
#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
uint16_t count
Number of entries.
Definition: ena.h:22
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
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:68
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:414
uint16_t socket
TCP port.
Definition: ibft.h:229
char * initiator_iqn
Initiator IQN.
Definition: iscsi.h:547
A string within the iBFT.
Definition: ibft.h:62
struct ibft_string reverse_chap_name
Reverse CHAP name.
Definition: ibft.h:246
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:381
char * target_password
Target password (if any)
Definition: iscsi.h:569
#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:483
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:567
#define EHOSTUNREACH
Host is unreachable.
Definition: errno.h:403
struct acpi_model ibft_model __acpi_model
iBFT model
Definition: ibft.c:687
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:447
#define ISCSI_STATUS_AUTH_FORWARD_REQUIRED
Target has requested forward (initiator) authentication.
Definition: iscsi.h:693
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
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:66
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:366
static void ibft_set_ipaddr(struct ibft_ipaddr *ipaddr, struct in_addr in)
Fill in an IP address field within iBFT.
Definition: ibft.c:90
#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:138
#define IBFT_SIG
iSCSI Boot Firmware Table signature
Definition: ibft.h:50