/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <dhcp_impl.h>
#include <socket_impl.h>
#include <socket_inet.h>
#include <netinet/in_systm.h>
#include <netinet/if_ether.h>
#include <sys/prom_plat.h>
#include <sys/bootdebug.h>
#include "ipv4.h"
#include "dhcpv4.h"
#include "ipv4_impl.h"
#include "mac.h"
#include "mac_impl.h"
#include "ibd_inet.h"
struct ibd_arp {
};
extern int errno;
/*
* Assumptions about OBP behavior (refer FWARC 2002/702, 2003/251):
* 1. prom_write() accepts the 20 byte destination address as the
* first component in the send buffer. The buffer pointer points
* to the start of this 20 byte address. The length parameter is
* the IPoIB datagram size with the 20 byte of destination
* address.
* 2. OBP will not provide max-frame-size, since obp can only
* determine that by querying the IBA mcg, and thus the property
* has to be /chosen:ipib-frame-size. This will refer to the IPoIB
* link MTU as per section 4.0 of ietf i/d, ie, the 4 byte IPoIB
* header plus the IP payload mtu. Plus the 20 bytes of addressing
* information.
* 3. OBP will not provide mac-address property for IPoIB since there
* are built in assumptions about 6 byte address with that. Instead,
* /chosen:ipib-address will provide the local address.
* 4. prom_read() returns 20 byte 0'ed filler followed by 4 byte
* IPoIB header followed by IP payload. The return value is -2,
* -1, 0, or the length of the received IPoIB datagram alongwith
* the 20 bytes MBZ. The buffer pointer points to the start of
* the 20 MBZ bytes. The length parameter reflects the max data
* size that should be copied into the buffer including the 20
* MBZ bytes.
* 5. OBP will not provide chosen-network-type, only
* network-interface-type = ipib. On an Infiniband device, this
* however does not guarantee that it is a network device.
* 6. OBP will provide the DHCP client id in /chosen:client-id.
* 7. /chosen:ipib-broadcast will provide the broadcast address.
* 8. OBP will validate that RARP is not being used before
* allowing boot to proceed to inetboot.
*/
struct arp_packet {
};
static char *
{
int i;
for (i = 0; i < (IPOIB_ADDRL - 1); i++)
return (pbuf);
}
/*
* Common ARP code. Broadcast the packet and wait for the right response.
*
* If arp is called for, caller expects a hardware address in the
* source hardware address (sha) field of the "out" argument.
*
* IPoIB does not support RARP (see ibd_revarp()).
*
* Returns TRUE if transaction succeeded, FALSE otherwise.
*
* The timeout argument is the number of milliseconds to wait for a
* response. An infinite timeout can be specified as 0xffffffff.
*/
static int
{
sizeof (struct in_addr));
feedback = 0;
if (count == IBD_WAITCNT) {
/*
* Since IPoIB does not support RARP (see ibd_revarp),
* we know that out->arp_ea.arp_op == ARPOP_REQUEST.
*/
printf("\nRequesting MAC address for: %s\n",
}
if (count >= IBD_WAITCNT)
while (prom_gettime() <= time) {
if (len < sizeof (struct arp_packet))
continue;
continue;
/*
* Since IPoIB does not support RARP (see ibd_revarp),
* we know that out->arp_ea.arp_op == ARPOP_REQUEST.
*/
continue;
continue;
sizeof (struct in_addr)) != 0)
continue;
if (boothowto & RB_VERBOSE) {
sizeof (struct in_addr));
printf("Found %s @ %s\n",
}
/* copy hardware addr into "out" for caller */
return (TRUE);
}
delay = 64;
}
return (FALSE);
}
/*
* ARP client side
* Broadcasts to determine MAC address given network order IP address.
* See RFC 826
*
* Returns TRUE if successful, FALSE otherwise.
*/
static int
{
int result;
if (!initialized)
prom_panic("IPoIB device is not initialized.");
sizeof (struct in_addr));
}
return (result);
}
/*
* Reverse ARP client side
* Determine our Internet address given our MAC address
* See RFC 903
*/
static void
ibd_revarp(void)
{
prom_panic("IPoIB can not boot with RARP.");
}
/* ARGSUSED */
static int
{
/*
* We indicate to upper layers to leave enough space
* in output buffers for filling in the IPoIB header
* and the 20 byte destination address in ibd_output().
*/
return (IPOIB_HDRSIZE + IPOIB_ADDRL);
}
/*
* Handle a IP datagram addressed to our MAC address or to the link
* layer broadcast address. Also respond to ARP requests. Generates
* inetgrams as long as there's data and the mac level IP timeout timer
* hasn't expired. As soon as there is no data, we try for
* IBD_INPUT_ATTEMPTS for more, then exit the loop, even if there is time
* left, since we expect to have data waiting for us when we're called, we just
* don't know how much.
*
* We workaround slow proms (some proms have hard sleeps for as much as 3msec)
* even though there are is data waiting.
*
* Returns the total number of MEDIA_LVL frames placed on the socket.
* Caller is expected to free up the inetgram resources.
*/
static int
{
#ifdef DEBUG
#endif /* DEBUG */
if (!initialized)
prom_panic("IPoIB device is not initialized.");
do {
if (frames > IBD_MAX_FRAMES) {
/* someone is trying a denial of service attack */
break;
}
/*
* The following is being paranoid about possible bugs
* where prom_read() returns a nonzero length, even when
* it's not read a packet; it zeroes out the header to
* compensate. Paranoia from calvin prom (V2) days.
*/
/*
* Prom_read() will return 0 or -2 if no data is present. A
* return value of -1 means an error has occurred. We adjust
* the timeout by calling the time spent in prom_read() "free".
* prom_read() returns the number of bytes actually read, but
* will only copy "len" bytes into our buffer. Adjust in
* case the MTU is wrong.
*/
pre_pr = prom_gettime();
post_pr = prom_gettime();
#ifdef DEBUG
#endif /* DEBUG */
dprintf("ibd_input: adjusting MTU %d -> %d\n",
prom_panic("ibd_input: Cannot reallocate "
"netbuf memory.");
}
len = 0; /* pretend there was no data */
}
if (len == -1) {
#ifdef DEBUG
failures++;
#endif /* DEBUG */
break;
}
if (frames != 0)
attempts++;
#ifdef DEBUG
no_data++;
#endif /* DEBUG */
continue;
}
int offset;
#ifdef DEBUG
pre_pc = prom_gettime();
#endif /* DEBUG */
sizeof (struct inetgram));
}
offset = sizeof (ipoib_ptxhdr_t);
sizeof (struct inetgram));
}
frames++;
attempts = 0;
#ifdef DEBUG
#endif /* DEBUG */
continue;
}
len >= sizeof (struct arp_packet)) {
#ifdef DEBUG
printf("ibd_input: ARP message received\n");
arps++;
#endif /* DEBUG */
sizeof (ipoib_ptxhdr_t));
continue;
ipv4_getipaddr(&ip);
sizeof (struct in_addr)) == 0)) {
sizeof (struct in_addr));
sizeof (struct in_addr));
sizeof (struct arp_packet), 0, NETWORK);
/* don't charge for ARP replies */
}
}
} while (attempts < IBD_INPUT_ATTEMPTS &&
#ifdef DEBUG
#else
prom_gettime() < timeout);
#endif /* DEBUG */
#ifdef DEBUG
printf("ibd_input(%d): T/S/N/A/F/P/M: %d/%d/%d/%d/%d/%d/%d "
#endif /* DEBUG */
return (frames);
}
/*
* Send out an IPoIB datagram. We expect a IP frame appropriately fragmented
* at this level.
*
* Errno is set and -1 is returned if an error occurs. Number of bytes sent
* is returned on success.
*/
/* ARGSUSED */
static int
{
int size;
if (!initialized)
prom_panic("IPoIB device is not initialized.");
dprintf("ibd_output: frame type wrong: socket: %d\n",
index * SOCKETTYPE);
return (-1);
}
return (-1);
}
size += header_len;
if (!broadcast) {
} else {
else
if (!result) {
dprintf("ibd_output: ARP request for %s "
return (-1);
}
}
}
if (broadcast)
/* add the ibd header */
#ifdef DEBUG
printf("ibd_output(%d): level(%d) frame(0x%x) len(%d)\n",
#endif /* DEBUG */
0, NETWORK));
}
void
ibd_init(void)
{
int cidlen;
prom_panic("ibd_init: Cannot allocate memory.");
prom_panic("ibd_init: Cannot find /chosen.");
prom_panic("ibd_init: Cannot find /chosen:ipib-address\n.");
prom_panic("ibd_init: Cannot find /chosen:ipib-broadcast\n.");
prom_panic("ibd_init: Invalid /chosen:client-id\n.");
/*
* Note that prom reports mtu including 20 bytes of
* addressing information.
*/
/*
* Tell upper layers that we can support a little
* more. We will be taking off these 20 bytes at
* the start before we invoke prom_write() to send
* over the wire.
*/
}