/* You must explicitly specifiy the @generation for which the node ID is valid, to avoid sending packets to the wrong nodes when we race with a bus reset.  */
int hpsb_read(struct hpsb_host *host, nodeid_t node, unsigned int generation, u64 addr, quadlet_t *buffer, size_t length)
/* You must explicitly specifiy the @generation for which the node ID is valid, to avoid sending packets to the wrong nodes when we race with a bus reset.  */
int hpsb_read(struct hpsb_host *host, nodeid_t node, unsigned int generation, u64 addr, quadlet_t *buffer, size_t length)
{
	struct hpsb_packet *packet;
	int retval = 0;
	if (length == 0)
		return -EINVAL;
	packet = hpsb_make_readpacket(host, node, addr, length);
	if (!packet) {
		return -ENOMEM;
	}
	packet->generation = generation;
	retval = hpsb_send_packet_and_wait(packet);
	if (retval < 0)
		goto hpsb_read_fail;
	retval = hpsb_packet_success(packet);
	if (retval == 0) {
		if (length == 4) {
			*buffer = packet->header[3];
		} else {
			memcpy(buffer, packet->data, length);
		}
	}
      hpsb_read_fail:
	hpsb_free_tlabel(packet);
	hpsb_free_packet(packet);
	return retval;
}