2010-08-28 05:59:27 +08:00
|
|
|
/*
|
|
|
|
* Written by Oron Peled <oron@actcom.co.il>
|
|
|
|
* Copyright (C) 2004-2006, Xorcom
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include "xdefs.h"
|
|
|
|
#include "xpd.h"
|
|
|
|
#include "xpp_dahdi.h"
|
|
|
|
#include "xproto.h"
|
|
|
|
#include "dahdi_debug.h"
|
|
|
|
#include "xbus-core.h"
|
|
|
|
#include "parport_debug.h"
|
|
|
|
|
|
|
|
static const char rcsid[] = "$Id$";
|
|
|
|
|
2012-01-11 23:22:46 +08:00
|
|
|
DEF_PARM(charp, initdir, "/usr/share/dahdi", 0644,
|
|
|
|
"The directory of card initialization scripts");
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
#define CHIP_REGISTERS "chipregs"
|
|
|
|
|
2012-01-11 23:22:46 +08:00
|
|
|
extern int debug;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
/*---------------- GLOBAL PROC handling -----------------------------------*/
|
|
|
|
|
2012-01-11 23:22:46 +08:00
|
|
|
static int send_magic_request(xbus_t *xbus, unsigned unit, xportno_t portno,
|
|
|
|
bool eoftx)
|
2012-01-02 22:06:50 +08:00
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
xframe_t *xframe;
|
|
|
|
xpacket_t *pack;
|
|
|
|
reg_cmd_t *reg_cmd;
|
|
|
|
int ret;
|
2012-01-02 22:06:50 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Zero length multibyte is legal and has special meaning for the
|
|
|
|
* firmware:
|
|
|
|
* eoftx==1: Start sending us D-channel packets.
|
|
|
|
* eoftx==0: Stop sending us D-channel packets.
|
|
|
|
*/
|
|
|
|
XFRAME_NEW_CMD(xframe, pack, xbus, GLOBAL, REGISTER_REQUEST, unit);
|
|
|
|
reg_cmd = &RPACKET_FIELD(pack, GLOBAL, REGISTER_REQUEST, reg_cmd);
|
|
|
|
reg_cmd->bytes = 0;
|
|
|
|
reg_cmd->is_multibyte = 1;
|
|
|
|
reg_cmd->portnum = portno;
|
|
|
|
reg_cmd->eoframe = eoftx;
|
|
|
|
PORT_DBG(REGS, xbus, unit, portno, "Magic Packet (eoftx=%d)\n", eoftx);
|
|
|
|
if (debug & DBG_REGS)
|
|
|
|
dump_xframe(__func__, xbus, xframe, debug);
|
|
|
|
ret = send_cmd_frame(xbus, xframe);
|
|
|
|
if (ret < 0)
|
2012-01-11 23:22:46 +08:00
|
|
|
PORT_ERR(xbus, unit, portno, "%s: failed sending xframe\n",
|
|
|
|
__func__);
|
2012-01-02 22:06:50 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-08-28 05:59:27 +08:00
|
|
|
static int parse_hexbyte(const char *buf)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
char *endp;
|
|
|
|
unsigned val;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
val = simple_strtoul(buf, &endp, 16);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (*endp != '\0' || val > 0xFF)
|
2010-08-28 05:59:27 +08:00
|
|
|
return -EBADR;
|
2012-01-11 23:21:54 +08:00
|
|
|
return (__u8)val;
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int execute_chip_command(xpd_t *xpd, const int argc, char *argv[])
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
int argno;
|
|
|
|
char num_args;
|
|
|
|
int portno;
|
|
|
|
bool writing;
|
|
|
|
int op; /* [W]rite, [R]ead */
|
|
|
|
int addr_mode; /* [D]irect, [I]ndirect, [Mm]ulti */
|
|
|
|
bool do_subreg = 0;
|
|
|
|
int regnum;
|
|
|
|
int subreg;
|
|
|
|
int data_low;
|
|
|
|
bool do_datah;
|
|
|
|
int data_high;
|
|
|
|
int ret = -EBADR;
|
|
|
|
|
|
|
|
num_args = 2; /* port + operation */
|
2012-01-11 23:20:05 +08:00
|
|
|
if (argc < num_args) {
|
2010-08-28 05:59:27 +08:00
|
|
|
XPD_ERR(xpd, "Not enough arguments (%d)\n", argc);
|
|
|
|
XPD_ERR(xpd,
|
2012-01-12 03:56:35 +08:00
|
|
|
"Any Command is composed of at least %d words "
|
|
|
|
"(got only %d)\n",
|
2012-01-11 23:22:46 +08:00
|
|
|
num_args, argc);
|
2010-08-28 05:59:27 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
/* Process the arguments */
|
|
|
|
argno = 0;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (strcmp(argv[argno], "*") == 0) {
|
2010-08-28 05:59:27 +08:00
|
|
|
portno = PORT_BROADCAST;
|
|
|
|
//XPD_DBG(REGS, xpd, "Port broadcast\n");
|
|
|
|
} else {
|
|
|
|
portno = parse_hexbyte(argv[argno]);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (portno < 0 || portno >= 8) {
|
2010-08-28 05:59:27 +08:00
|
|
|
XPD_ERR(xpd, "Illegal port number '%s'\n", argv[argno]);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
//XPD_DBG(REGS, xpd, "Port is %d\n", portno);
|
|
|
|
}
|
|
|
|
argno++;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (strlen(argv[argno]) != 2) {
|
2010-08-28 05:59:27 +08:00
|
|
|
XPD_ERR(xpd, "Wrong operation codes '%s'\n", argv[argno]);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
op = argv[argno][0];
|
2012-01-11 23:20:05 +08:00
|
|
|
switch (op) {
|
2012-01-11 23:22:46 +08:00
|
|
|
case 'W':
|
|
|
|
writing = 1;
|
|
|
|
num_args++; /* data low */
|
|
|
|
//XPD_DBG(REGS, xpd, "WRITING\n");
|
|
|
|
break;
|
|
|
|
case 'R':
|
|
|
|
writing = 0;
|
|
|
|
//XPD_DBG(REGS, xpd, "READING\n");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
XPD_ERR(xpd, "Unknown operation type '%c'\n", op);
|
|
|
|
goto out;
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
addr_mode = argv[argno][1];
|
2012-01-11 23:20:05 +08:00
|
|
|
switch (addr_mode) {
|
2012-01-11 23:22:46 +08:00
|
|
|
case 'I':
|
|
|
|
XPD_NOTICE(xpd,
|
2012-01-12 03:56:35 +08:00
|
|
|
"'I' is deprecated in register commands. "
|
|
|
|
"Use 'S' instead.\n");
|
2012-01-11 23:22:46 +08:00
|
|
|
/* fall through */
|
|
|
|
case 'S':
|
|
|
|
do_subreg = 1;
|
|
|
|
num_args += 2; /* register + subreg */
|
|
|
|
//XPD_DBG(REGS, xpd, "SUBREG\n");
|
|
|
|
break;
|
|
|
|
case 'D':
|
|
|
|
do_subreg = 0;
|
|
|
|
num_args++; /* register */
|
|
|
|
//XPD_DBG(REGS, xpd, "DIRECT\n");
|
|
|
|
break;
|
|
|
|
case 'M':
|
|
|
|
case 'm':
|
|
|
|
if (op != 'W') {
|
|
|
|
XPD_ERR(xpd,
|
|
|
|
"Can use Multibyte (%c) only with op 'W'\n",
|
|
|
|
addr_mode);
|
2010-08-28 05:59:27 +08:00
|
|
|
goto out;
|
2012-01-11 23:22:46 +08:00
|
|
|
}
|
|
|
|
num_args--; /* No data low */
|
|
|
|
//XPD_DBG(REGS, xpd, "Multibyte (%c)\n", addr_mode);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
XPD_ERR(xpd, "Unknown addressing type '%c'\n", addr_mode);
|
|
|
|
goto out;
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2012-01-11 23:20:05 +08:00
|
|
|
if (argv[argno][2] != '\0') {
|
2010-08-28 05:59:27 +08:00
|
|
|
XPD_ERR(xpd, "Bad operation field '%s'\n", argv[argno]);
|
|
|
|
goto out;
|
|
|
|
}
|
2012-01-11 23:20:05 +08:00
|
|
|
if (argc < num_args) {
|
2010-08-28 05:59:27 +08:00
|
|
|
XPD_ERR(xpd,
|
2012-01-12 03:56:35 +08:00
|
|
|
"Command \"%s\" is composed of at least %d words "
|
|
|
|
"(got only %d)\n",
|
2012-01-11 23:22:46 +08:00
|
|
|
argv[argno], num_args, argc);
|
2010-08-28 05:59:27 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
argno++;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (addr_mode == 'M' || addr_mode == 'm') {
|
|
|
|
if (argno < argc) {
|
2010-08-28 05:59:27 +08:00
|
|
|
XPD_ERR(xpd,
|
2012-01-11 23:22:46 +08:00
|
|
|
"Magic-Multibyte(%c) with %d extra arguments\n",
|
|
|
|
addr_mode, argc - argno);
|
2010-08-28 05:59:27 +08:00
|
|
|
goto out;
|
|
|
|
}
|
2012-01-11 23:22:46 +08:00
|
|
|
ret =
|
|
|
|
send_magic_request(xpd->xbus, xpd->addr.unit, portno,
|
|
|
|
addr_mode == 'm');
|
2010-08-28 05:59:27 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
/* Normal (non-Magic) register commands */
|
|
|
|
do_datah = 0;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (argno >= argc) {
|
2010-08-28 05:59:27 +08:00
|
|
|
XPD_ERR(xpd, "Missing register number\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
regnum = parse_hexbyte(argv[argno]);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (regnum < 0) {
|
2010-08-28 05:59:27 +08:00
|
|
|
XPD_ERR(xpd, "Illegal register number '%s'\n", argv[argno]);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
//XPD_DBG(REGS, xpd, "Register is %X\n", regnum);
|
|
|
|
argno++;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (do_subreg) {
|
|
|
|
if (argno >= argc) {
|
2010-08-28 05:59:27 +08:00
|
|
|
XPD_ERR(xpd, "Missing subregister number\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
subreg = parse_hexbyte(argv[argno]);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (subreg < 0) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XPD_ERR(xpd, "Illegal subregister number '%s'\n",
|
|
|
|
argv[argno]);
|
2010-08-28 05:59:27 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
//XPD_DBG(REGS, xpd, "Subreg is %X\n", subreg);
|
|
|
|
argno++;
|
|
|
|
} else
|
|
|
|
subreg = 0;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (writing) {
|
|
|
|
if (argno >= argc) {
|
2010-08-28 05:59:27 +08:00
|
|
|
XPD_ERR(xpd, "Missing data low number\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
data_low = parse_hexbyte(argv[argno]);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (data_low < 0) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XPD_ERR(xpd, "Illegal data_low number '%s'\n",
|
|
|
|
argv[argno]);
|
2010-08-28 05:59:27 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
//XPD_DBG(REGS, xpd, "Data Low is %X\n", data_low);
|
|
|
|
argno++;
|
|
|
|
} else
|
|
|
|
data_low = 0;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (argno < argc) {
|
2010-08-28 05:59:27 +08:00
|
|
|
do_datah = 1;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!argv[argno]) {
|
2010-08-28 05:59:27 +08:00
|
|
|
XPD_ERR(xpd, "Missing data high number\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
data_high = parse_hexbyte(argv[argno]);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (data_high < 0) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XPD_ERR(xpd, "Illegal data_high number '%s'\n",
|
|
|
|
argv[argno]);
|
2010-08-28 05:59:27 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
//XPD_DBG(REGS, xpd, "Data High is %X\n", data_high);
|
|
|
|
argno++;
|
|
|
|
} else
|
|
|
|
data_high = 0;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (argno < argc) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XPD_ERR(xpd, "Command contains an extra %d argument\n",
|
|
|
|
argc - argno);
|
2010-08-28 05:59:27 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
#if 0
|
2012-01-12 01:04:36 +08:00
|
|
|
XPD_DBG(REGS, xpd,
|
2012-01-12 03:56:35 +08:00
|
|
|
"portno=%d writing=%d regnum=%d do_subreg=%d subreg=%d "
|
|
|
|
"dataL=%d do_datah=%d dataH=%d\n",
|
|
|
|
portno, /* portno */
|
|
|
|
writing, /* writing */
|
|
|
|
regnum, do_subreg, /* use subreg */
|
|
|
|
subreg, /* subreg */
|
2012-01-13 01:12:48 +08:00
|
|
|
data_low, do_datah, /* use data_high */
|
2012-01-11 23:22:46 +08:00
|
|
|
data_high);
|
2010-08-28 05:59:27 +08:00
|
|
|
#endif
|
2012-01-12 01:04:36 +08:00
|
|
|
ret = xpp_register_request(xpd->xbus, xpd, portno,
|
|
|
|
writing, regnum, do_subreg, subreg,
|
|
|
|
data_low, do_datah, data_high, 1);
|
2010-08-28 05:59:27 +08:00
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-01-12 01:04:36 +08:00
|
|
|
#define MAX_ARGS 10
|
|
|
|
|
2010-08-28 05:59:27 +08:00
|
|
|
int parse_chip_command(xpd_t *xpd, char *cmdline)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
xbus_t *xbus;
|
|
|
|
int ret = -EBADR;
|
|
|
|
__u8 buf[MAX_PROC_WRITE];
|
|
|
|
char *str;
|
|
|
|
char *p;
|
|
|
|
char *argv[MAX_ARGS + 1];
|
|
|
|
int argc;
|
|
|
|
int i;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!xpd);
|
|
|
|
xbus = xpd->xbus;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!XBUS_FLAGS(xbus, CONNECTED)) {
|
2010-08-28 05:59:27 +08:00
|
|
|
XBUS_DBG(GENERAL, xbus, "Dropped packet. Disconnected.\n");
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
strlcpy(buf, cmdline, MAX_PROC_WRITE); /* Save a copy */
|
2012-01-11 23:20:05 +08:00
|
|
|
if (buf[0] == '#' || buf[0] == ';')
|
2010-08-28 05:59:27 +08:00
|
|
|
XPD_DBG(REGS, xpd, "Note: '%s'\n", buf);
|
2012-01-11 23:20:05 +08:00
|
|
|
if ((p = strchr(buf, '#')) != NULL) /* Truncate comments */
|
2010-08-28 05:59:27 +08:00
|
|
|
*p = '\0';
|
2012-01-11 23:20:05 +08:00
|
|
|
if ((p = strchr(buf, ';')) != NULL) /* Truncate comments */
|
2010-08-28 05:59:27 +08:00
|
|
|
*p = '\0';
|
2012-01-12 03:56:35 +08:00
|
|
|
/* Trim leading whitespace */
|
|
|
|
for (p = buf; *p && (*p == ' ' || *p == '\t'); p++)
|
2010-08-28 05:59:27 +08:00
|
|
|
;
|
|
|
|
str = p;
|
2012-01-11 23:22:46 +08:00
|
|
|
for (i = 0; (p = strsep(&str, " \t")) != NULL && i < MAX_ARGS;) {
|
2012-01-11 23:20:05 +08:00
|
|
|
if (*p != '\0') {
|
2010-08-28 05:59:27 +08:00
|
|
|
argv[i] = p;
|
|
|
|
// XPD_DBG(REGS, xpd, "ARG %d = '%s'\n", i, p);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
argv[i] = NULL;
|
|
|
|
argc = i;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (p) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XPD_ERR(xpd, "Too many words (%d) to process. Last was '%s'\n",
|
|
|
|
i, p);
|
2010-08-28 05:59:27 +08:00
|
|
|
goto out;
|
|
|
|
}
|
2012-01-11 23:20:05 +08:00
|
|
|
if (argc)
|
2010-08-28 05:59:27 +08:00
|
|
|
ret = execute_chip_command(xpd, argc, argv);
|
|
|
|
else
|
|
|
|
ret = 0; /* empty command - no op */
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------- GLOBAL Protocol Commands -------------------------------*/
|
|
|
|
|
|
|
|
static bool global_packet_is_valid(xpacket_t *pack);
|
|
|
|
static void global_packet_dump(const char *msg, xpacket_t *pack);
|
|
|
|
|
|
|
|
/*---------------- GLOBAL: HOST COMMANDS ----------------------------------*/
|
|
|
|
|
|
|
|
/* 0x07 */ HOSTCMD(GLOBAL, AB_REQUEST)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
int ret = -ENODEV;
|
|
|
|
xframe_t *xframe;
|
|
|
|
xpacket_t *pack;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xbus) {
|
2010-08-28 05:59:27 +08:00
|
|
|
DBG(DEVICES, "NO XBUS\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
if (xbus_check_unique(xbus))
|
|
|
|
return -EBUSY;
|
|
|
|
XFRAME_NEW_CMD(xframe, pack, xbus, GLOBAL, AB_REQUEST, 0);
|
|
|
|
RPACKET_FIELD(pack, GLOBAL, AB_REQUEST, rev) = XPP_PROTOCOL_VERSION;
|
|
|
|
RPACKET_FIELD(pack, GLOBAL, AB_REQUEST, reserved) = 0;
|
|
|
|
XBUS_DBG(DEVICES, xbus, "Protocol Version %d\n", XPP_PROTOCOL_VERSION);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (xbus_setstate(xbus, XBUS_STATE_SENT_REQUEST))
|
2010-08-28 05:59:27 +08:00
|
|
|
ret = send_cmd_frame(xbus, xframe);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int xpp_register_request(xbus_t *xbus, xpd_t *xpd, xportno_t portno,
|
2012-01-11 23:22:46 +08:00
|
|
|
bool writing, __u8 regnum, bool do_subreg, __u8 subreg,
|
|
|
|
__u8 data_low, bool do_datah, __u8 data_high,
|
|
|
|
bool should_reply)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
int ret = 0;
|
|
|
|
xframe_t *xframe;
|
|
|
|
xpacket_t *pack;
|
|
|
|
reg_cmd_t *reg_cmd;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xbus) {
|
2010-08-28 05:59:27 +08:00
|
|
|
DBG(REGS, "NO XBUS\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2012-01-11 23:22:46 +08:00
|
|
|
XFRAME_NEW_CMD(xframe, pack, xbus, GLOBAL, REGISTER_REQUEST,
|
|
|
|
xpd->xbus_idx);
|
2010-08-28 05:59:27 +08:00
|
|
|
LINE_DBG(REGS, xpd, portno, "%c%c %02X %02X %02X %02X\n",
|
2012-01-11 23:22:46 +08:00
|
|
|
(writing) ? 'W' : 'R', (do_subreg) ? 'S' : 'D', regnum, subreg,
|
|
|
|
data_low, data_high);
|
2010-08-28 05:59:27 +08:00
|
|
|
reg_cmd = &RPACKET_FIELD(pack, GLOBAL, REGISTER_REQUEST, reg_cmd);
|
2012-01-12 03:56:35 +08:00
|
|
|
/* do not count the 'bytes' field */
|
|
|
|
reg_cmd->bytes = sizeof(*reg_cmd) - 1;
|
2010-08-28 05:59:27 +08:00
|
|
|
reg_cmd->is_multibyte = 0;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (portno == PORT_BROADCAST) {
|
2010-08-28 05:59:27 +08:00
|
|
|
reg_cmd->portnum = 0;
|
|
|
|
REG_FIELD(reg_cmd, all_ports_broadcast) = 1;
|
|
|
|
} else {
|
|
|
|
reg_cmd->portnum = portno;
|
|
|
|
REG_FIELD(reg_cmd, all_ports_broadcast) = 0;
|
|
|
|
}
|
|
|
|
reg_cmd->eoframe = 0;
|
|
|
|
REG_FIELD(reg_cmd, reserved) = 0; /* force reserved bits to 0 */
|
|
|
|
REG_FIELD(reg_cmd, read_request) = (writing) ? 0 : 1;
|
|
|
|
REG_FIELD(reg_cmd, do_subreg) = do_subreg;
|
|
|
|
REG_FIELD(reg_cmd, regnum) = regnum;
|
|
|
|
REG_FIELD(reg_cmd, subreg) = subreg;
|
|
|
|
REG_FIELD(reg_cmd, do_datah) = do_datah;
|
|
|
|
REG_FIELD(reg_cmd, data_low) = data_low;
|
|
|
|
REG_FIELD(reg_cmd, data_high) = data_high;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (should_reply)
|
2010-08-28 05:59:27 +08:00
|
|
|
xpd->requested_reply = *reg_cmd;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (debug & DBG_REGS) {
|
2012-01-11 23:22:46 +08:00
|
|
|
dump_reg_cmd("REG_REQ", 1, xbus, xpd->addr.unit,
|
|
|
|
reg_cmd->portnum, reg_cmd);
|
2010-08-28 05:59:27 +08:00
|
|
|
dump_packet("REG_REQ", pack, 1);
|
|
|
|
}
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xframe->usec_towait) { /* default processing time of SPI */
|
|
|
|
if (subreg)
|
2010-08-28 05:59:27 +08:00
|
|
|
xframe->usec_towait = 2000;
|
|
|
|
else
|
|
|
|
xframe->usec_towait = 1000;
|
|
|
|
}
|
|
|
|
ret = send_cmd_frame(xbus, xframe);
|
|
|
|
return ret;
|
|
|
|
}
|
2012-01-12 04:01:32 +08:00
|
|
|
EXPORT_SYMBOL(xpp_register_request);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The XPD parameter is totaly ignored by the driver and firmware as well.
|
|
|
|
*/
|
|
|
|
/* 0x19 */ HOSTCMD(GLOBAL, SYNC_SOURCE, enum sync_mode mode, int drift)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
xframe_t *xframe;
|
|
|
|
xpacket_t *pack;
|
|
|
|
const char *mode_name;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!xbus);
|
2012-01-11 23:20:05 +08:00
|
|
|
if ((mode_name = sync_mode_name(mode)) == NULL) {
|
2010-08-28 05:59:27 +08:00
|
|
|
XBUS_ERR(xbus, "SYNC_SOURCE: bad sync_mode=0x%X\n", mode);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
XBUS_DBG(SYNC, xbus, "%s (0x%X), drift=%d\n", mode_name, mode, drift);
|
|
|
|
XFRAME_NEW_CMD(xframe, pack, xbus, GLOBAL, SYNC_SOURCE, 0);
|
|
|
|
RPACKET_FIELD(pack, GLOBAL, SYNC_SOURCE, sync_mode) = mode;
|
|
|
|
RPACKET_FIELD(pack, GLOBAL, SYNC_SOURCE, drift) = drift;
|
|
|
|
send_cmd_frame(xbus, xframe);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 0x23 */ HOSTCMD(GLOBAL, RESET_SYNC_COUNTERS)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
xframe_t *xframe;
|
|
|
|
xpacket_t *pack;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!xbus);
|
|
|
|
//XBUS_DBG(SYNC, xbus, "\n");
|
|
|
|
XFRAME_NEW_CMD(xframe, pack, xbus, GLOBAL, RESET_SYNC_COUNTERS, 0);
|
|
|
|
RPACKET_FIELD(pack, GLOBAL, RESET_SYNC_COUNTERS, mask) = 0x10;
|
|
|
|
send_cmd_frame(xbus, xframe);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------- GLOBAL: Astribank Reply Handlers -----------------------*/
|
|
|
|
|
|
|
|
HANDLER_DEF(GLOBAL, NULL_REPLY)
|
|
|
|
{
|
|
|
|
XBUS_DBG(GENERAL, xbus, "got len=%d\n", XPACKET_LEN(pack));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-01-11 23:22:46 +08:00
|
|
|
HANDLER_DEF(GLOBAL, AB_DESCRIPTION)
|
|
|
|
{ /* 0x08 */
|
|
|
|
struct xbus_workqueue *worker;
|
|
|
|
__u8 rev;
|
|
|
|
struct unit_descriptor *units;
|
|
|
|
int count_units;
|
|
|
|
int i;
|
|
|
|
int ret = 0;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
if (!xbus) {
|
|
|
|
NOTICE("%s: xbus is gone!!!\n", __func__);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
rev = RPACKET_FIELD(pack, GLOBAL, AB_DESCRIPTION, rev);
|
|
|
|
units = RPACKET_FIELD(pack, GLOBAL, AB_DESCRIPTION, unit_descriptor);
|
2012-01-11 23:21:54 +08:00
|
|
|
count_units = XPACKET_LEN(pack) - ((__u8 *)units - (__u8 *)pack);
|
2010-08-28 05:59:27 +08:00
|
|
|
count_units /= sizeof(*units);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (rev != XPP_PROTOCOL_VERSION) {
|
2010-08-28 05:59:27 +08:00
|
|
|
XBUS_NOTICE(xbus, "Bad protocol version %d (should be %d)\n",
|
2012-01-11 23:22:46 +08:00
|
|
|
rev, XPP_PROTOCOL_VERSION);
|
2010-08-28 05:59:27 +08:00
|
|
|
ret = -EPROTO;
|
|
|
|
goto proto_err;
|
|
|
|
}
|
2012-01-11 23:20:05 +08:00
|
|
|
if (count_units > NUM_UNITS) {
|
2010-08-28 05:59:27 +08:00
|
|
|
XBUS_NOTICE(xbus, "Too many units %d (should be %d)\n",
|
2012-01-11 23:22:46 +08:00
|
|
|
count_units, NUM_UNITS);
|
2010-08-28 05:59:27 +08:00
|
|
|
ret = -EPROTO;
|
|
|
|
goto proto_err;
|
|
|
|
}
|
2012-01-11 23:20:05 +08:00
|
|
|
if (count_units <= 0) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XBUS_NOTICE(xbus, "Empty astribank? (%d units)\n", count_units);
|
2010-08-28 05:59:27 +08:00
|
|
|
ret = -EPROTO;
|
|
|
|
goto proto_err;
|
|
|
|
}
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xbus_setstate(xbus, XBUS_STATE_RECVD_DESC)) {
|
2010-08-28 05:59:27 +08:00
|
|
|
ret = -EPROTO;
|
|
|
|
goto proto_err;
|
|
|
|
}
|
2012-01-11 23:22:46 +08:00
|
|
|
XBUS_INFO(xbus, "DESCRIPTOR: %d cards, protocol revision %d\n",
|
|
|
|
count_units, rev);
|
2010-08-28 05:59:27 +08:00
|
|
|
if (xbus_check_unique(xbus))
|
|
|
|
return -EBUSY;
|
|
|
|
xbus->revision = rev;
|
|
|
|
worker = &xbus->worker;
|
|
|
|
if (!worker->wq) {
|
|
|
|
XBUS_ERR(xbus, "missing worker thread\n");
|
|
|
|
ret = -ENODEV;
|
|
|
|
goto out;
|
|
|
|
}
|
2012-01-11 23:20:05 +08:00
|
|
|
for (i = 0; i < count_units; i++) {
|
2012-01-11 23:22:46 +08:00
|
|
|
struct unit_descriptor *this_unit = &units[i];
|
|
|
|
struct card_desc_struct *card_desc;
|
|
|
|
unsigned long flags;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:22:46 +08:00
|
|
|
if ((card_desc =
|
|
|
|
KZALLOC(sizeof(struct card_desc_struct),
|
|
|
|
GFP_ATOMIC)) == NULL) {
|
2010-08-28 05:59:27 +08:00
|
|
|
XBUS_ERR(xbus, "Card description allocation failed.\n");
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
card_desc->magic = CARD_DESC_MAGIC;
|
|
|
|
INIT_LIST_HEAD(&card_desc->card_list);
|
|
|
|
card_desc->type = this_unit->type;
|
|
|
|
card_desc->subtype = this_unit->subtype;
|
|
|
|
card_desc->xpd_addr = this_unit->addr;
|
|
|
|
card_desc->numchips = this_unit->numchips;
|
|
|
|
card_desc->ports_per_chip = this_unit->ports_per_chip;
|
|
|
|
card_desc->port_dir = this_unit->port_dir;
|
2012-01-11 23:22:46 +08:00
|
|
|
card_desc->ports =
|
|
|
|
card_desc->numchips * card_desc->ports_per_chip;
|
|
|
|
XBUS_INFO(xbus,
|
2012-01-12 03:56:35 +08:00
|
|
|
" CARD %d type=%d.%d ports=%d (%dx%d), "
|
|
|
|
"port-dir=0x%02X\n",
|
|
|
|
card_desc->xpd_addr.unit, card_desc->type,
|
|
|
|
card_desc->subtype, card_desc->ports,
|
|
|
|
card_desc->numchips, card_desc->ports_per_chip,
|
|
|
|
card_desc->port_dir);
|
2010-08-28 05:59:27 +08:00
|
|
|
spin_lock_irqsave(&worker->worker_lock, flags);
|
|
|
|
worker->num_units++;
|
|
|
|
XBUS_COUNTER(xbus, UNITS)++;
|
|
|
|
list_add_tail(&card_desc->card_list, &worker->card_list);
|
|
|
|
spin_unlock_irqrestore(&worker->worker_lock, flags);
|
|
|
|
}
|
|
|
|
if (!xbus_process_worker(xbus)) {
|
|
|
|
ret = -ENODEV;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
goto out;
|
|
|
|
proto_err:
|
|
|
|
dump_packet("AB_DESCRIPTION", pack, DBG_ANY);
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
HANDLER_DEF(GLOBAL, REGISTER_REPLY)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
reg_cmd_t *reg = &RPACKET_FIELD(pack, GLOBAL, REGISTER_REPLY, regcmd);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xpd) {
|
2012-01-11 23:22:46 +08:00
|
|
|
static int rate_limit;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if ((rate_limit++ % 1003) < 5)
|
2012-01-11 23:17:09 +08:00
|
|
|
notify_bad_xpd(__func__, xbus, XPACKET_ADDR(pack), "");
|
2010-08-28 05:59:27 +08:00
|
|
|
return -EPROTO;
|
|
|
|
}
|
2012-01-11 23:20:05 +08:00
|
|
|
if (debug & DBG_REGS) {
|
2012-01-11 23:22:46 +08:00
|
|
|
dump_reg_cmd("REG_REPLY", 0, xbus, xpd->addr.unit, reg->portnum,
|
|
|
|
reg);
|
2010-08-28 05:59:27 +08:00
|
|
|
dump_packet("REG_REPLY", pack, 1);
|
|
|
|
}
|
2012-01-11 23:22:46 +08:00
|
|
|
if (!XMETHOD(card_register_reply, xpd)) {
|
|
|
|
XPD_ERR(xpd,
|
2012-01-12 03:56:35 +08:00
|
|
|
"REGISTER_REPLY: missing card_register_reply()\n");
|
2011-01-30 22:14:14 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
return CALL_XMETHOD(card_register_reply, xpd, reg);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
HANDLER_DEF(GLOBAL, SYNC_REPLY)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
__u8 mode = RPACKET_FIELD(pack, GLOBAL, SYNC_REPLY, sync_mode);
|
|
|
|
__u8 drift = RPACKET_FIELD(pack, GLOBAL, SYNC_REPLY, drift);
|
|
|
|
const char *mode_name;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!xbus);
|
2012-01-11 23:20:05 +08:00
|
|
|
if ((mode_name = sync_mode_name(mode)) == NULL) {
|
2010-08-28 05:59:27 +08:00
|
|
|
XBUS_ERR(xbus, "SYNC_REPLY: bad sync_mode=0x%X\n", mode);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
XBUS_DBG(SYNC, xbus, "%s (0x%X), drift=%d\n", mode_name, mode, drift);
|
|
|
|
//dump_packet("SYNC_REPLY", pack, debug & DBG_SYNC);
|
|
|
|
got_new_syncer(xbus, mode, drift);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define TMP_NAME_LEN (XBUS_NAMELEN + XPD_NAMELEN + 5)
|
|
|
|
|
|
|
|
HANDLER_DEF(GLOBAL, ERROR_CODE)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
char tmp_name[TMP_NAME_LEN];
|
|
|
|
static long rate_limit;
|
|
|
|
__u8 category_code;
|
|
|
|
__u8 errorbits;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!xbus);
|
2012-01-11 23:20:05 +08:00
|
|
|
if ((rate_limit++ % 5003) > 200)
|
2010-08-28 05:59:27 +08:00
|
|
|
return 0;
|
|
|
|
category_code = RPACKET_FIELD(pack, GLOBAL, ERROR_CODE, category_code);
|
|
|
|
errorbits = RPACKET_FIELD(pack, GLOBAL, ERROR_CODE, errorbits);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xpd) {
|
2010-08-28 05:59:27 +08:00
|
|
|
snprintf(tmp_name, TMP_NAME_LEN, "%s(%1d%1d)", xbus->busname,
|
2012-01-11 23:22:46 +08:00
|
|
|
XPACKET_ADDR_UNIT(pack), XPACKET_ADDR_SUBUNIT(pack));
|
2010-08-28 05:59:27 +08:00
|
|
|
} else {
|
2012-01-11 23:22:46 +08:00
|
|
|
snprintf(tmp_name, TMP_NAME_LEN, "%s/%s", xbus->busname,
|
|
|
|
xpd->xpdname);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2012-01-11 23:22:46 +08:00
|
|
|
NOTICE
|
|
|
|
("%s: FIRMWARE %s: category=%d errorbits=0x%02X (rate_limit=%ld)\n",
|
|
|
|
tmp_name, cmd->name, category_code, errorbits, rate_limit);
|
2010-08-28 05:59:27 +08:00
|
|
|
dump_packet("FIRMWARE: ", pack, 1);
|
|
|
|
/*
|
|
|
|
* FIXME: Should implement an error recovery plan
|
|
|
|
*/
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
xproto_table_t PROTO_TABLE(GLOBAL) = {
|
|
|
|
.entries = {
|
2012-01-13 01:12:48 +08:00
|
|
|
/* Prototable Card Opcode */
|
|
|
|
XENTRY( GLOBAL, GLOBAL, NULL_REPLY ),
|
|
|
|
XENTRY( GLOBAL, GLOBAL, AB_DESCRIPTION ),
|
|
|
|
XENTRY( GLOBAL, GLOBAL, SYNC_REPLY ),
|
|
|
|
XENTRY( GLOBAL, GLOBAL, ERROR_CODE ),
|
|
|
|
XENTRY( GLOBAL, GLOBAL, REGISTER_REPLY ),
|
|
|
|
},
|
|
|
|
.name = "GLOBAL",
|
|
|
|
.packet_is_valid = global_packet_is_valid,
|
|
|
|
.packet_dump = global_packet_dump,
|
|
|
|
};
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
static bool global_packet_is_valid(xpacket_t *pack)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
const xproto_entry_t *xe;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
//DBG(GENERAL, "\n");
|
|
|
|
xe = xproto_global_entry(XPACKET_OP(pack));
|
|
|
|
return xe != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void global_packet_dump(const char *msg, xpacket_t *pack)
|
|
|
|
{
|
|
|
|
DBG(GENERAL, "%s\n", msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MAX_PATH_STR 128
|
|
|
|
|
|
|
|
int run_initialize_registers(xpd_t *xpd)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
int ret;
|
|
|
|
xbus_t *xbus;
|
|
|
|
char busstr[MAX_ENV_STR];
|
|
|
|
char busnumstr[MAX_ENV_STR];
|
|
|
|
char modelstr[MAX_ENV_STR];
|
|
|
|
char unitstr[MAX_ENV_STR];
|
|
|
|
char subunitsstr[MAX_ENV_STR];
|
|
|
|
char typestr[MAX_ENV_STR];
|
|
|
|
char directionstr[MAX_ENV_STR];
|
|
|
|
char revstr[MAX_ENV_STR];
|
|
|
|
char connectorstr[MAX_ENV_STR];
|
|
|
|
char xbuslabel[MAX_ENV_STR];
|
|
|
|
char init_card[MAX_PATH_STR];
|
|
|
|
__u8 direction_mask;
|
|
|
|
int i;
|
|
|
|
char *argv[] = {
|
2010-08-28 05:59:27 +08:00
|
|
|
init_card,
|
|
|
|
NULL
|
|
|
|
};
|
2012-01-11 23:22:46 +08:00
|
|
|
char *envp[] = {
|
2010-08-28 05:59:27 +08:00
|
|
|
busstr,
|
|
|
|
busnumstr,
|
2011-11-02 22:08:12 +08:00
|
|
|
modelstr,
|
2010-08-28 05:59:27 +08:00
|
|
|
unitstr,
|
|
|
|
subunitsstr,
|
|
|
|
typestr,
|
|
|
|
directionstr,
|
|
|
|
revstr,
|
|
|
|
connectorstr,
|
|
|
|
xbuslabel,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
BUG_ON(!xpd);
|
|
|
|
xbus = xpd->xbus;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!initdir || !initdir[0]) {
|
2010-08-28 05:59:27 +08:00
|
|
|
XPD_NOTICE(xpd, "Missing initdir parameter\n");
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto err;
|
|
|
|
}
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xpd_setstate(xpd, XPD_STATE_INIT_REGS)) {
|
2010-08-28 05:59:27 +08:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
direction_mask = 0;
|
2012-01-11 23:20:05 +08:00
|
|
|
for (i = 0; i < xpd->subunits; i++) {
|
2012-01-11 23:22:46 +08:00
|
|
|
xpd_t *su = xpd_byaddr(xbus, xpd->addr.unit, i);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!su) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XPD_ERR(xpd, "Have %d subunits, but not subunit #%d\n",
|
2010-08-28 05:59:27 +08:00
|
|
|
xpd->subunits, i);
|
|
|
|
continue;
|
|
|
|
}
|
2012-01-11 23:22:46 +08:00
|
|
|
direction_mask |=
|
|
|
|
(PHONEDEV(su).direction == TO_PHONE) ? BIT(i) : 0;
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
snprintf(busstr, MAX_ENV_STR, "XBUS_NAME=%s", xbus->busname);
|
|
|
|
snprintf(busnumstr, MAX_ENV_STR, "XBUS_NUMBER=%d", xbus->num);
|
2012-01-11 23:22:46 +08:00
|
|
|
snprintf(modelstr, MAX_ENV_STR, "XBUS_MODEL_STRING=%s",
|
|
|
|
xbus->transport.model_string);
|
2010-08-28 05:59:27 +08:00
|
|
|
snprintf(unitstr, MAX_ENV_STR, "UNIT_NUMBER=%d", xpd->addr.unit);
|
|
|
|
snprintf(typestr, MAX_ENV_STR, "UNIT_TYPE=%d", xpd->type);
|
|
|
|
snprintf(subunitsstr, MAX_ENV_STR, "UNIT_SUBUNITS=%d", xpd->subunits);
|
2012-01-11 23:22:46 +08:00
|
|
|
snprintf(directionstr, MAX_ENV_STR, "UNIT_SUBUNITS_DIR=%d",
|
|
|
|
direction_mask);
|
2010-08-28 05:59:27 +08:00
|
|
|
snprintf(revstr, MAX_ENV_STR, "XBUS_REVISION=%d", xbus->revision);
|
2012-01-11 23:22:46 +08:00
|
|
|
snprintf(connectorstr, MAX_ENV_STR, "XBUS_CONNECTOR=%s",
|
|
|
|
xbus->connector);
|
2010-08-28 05:59:27 +08:00
|
|
|
snprintf(xbuslabel, MAX_ENV_STR, "XBUS_LABEL=%s", xbus->label);
|
2012-01-11 23:22:46 +08:00
|
|
|
if (snprintf
|
|
|
|
(init_card, MAX_PATH_STR, "%s/init_card_%d_%d", initdir, xpd->type,
|
|
|
|
xbus->revision) > MAX_PATH_STR) {
|
|
|
|
XPD_NOTICE(xpd,
|
2012-01-12 03:56:35 +08:00
|
|
|
"Cannot initialize. pathname is longer "
|
|
|
|
"than %d characters.\n",
|
|
|
|
MAX_PATH_STR);
|
2010-08-28 05:59:27 +08:00
|
|
|
ret = -E2BIG;
|
|
|
|
goto err;
|
|
|
|
}
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!XBUS_IS(xbus, RECVD_DESC)) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XBUS_ERR(xbus,
|
|
|
|
"Skipped register initialization. In state %s.\n",
|
|
|
|
xbus_statename(XBUS_STATE(xbus)));
|
2010-08-28 05:59:27 +08:00
|
|
|
ret = -ENODEV;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
XPD_DBG(DEVICES, xpd, "running '%s' for type=%d revision=%d\n",
|
2012-01-11 23:22:46 +08:00
|
|
|
init_card, xpd->type, xbus->revision);
|
2010-08-28 05:59:27 +08:00
|
|
|
ret = call_usermodehelper(init_card, argv, envp, 1);
|
|
|
|
/*
|
|
|
|
* Carefully report results
|
|
|
|
*/
|
2012-01-11 23:20:05 +08:00
|
|
|
if (ret == 0)
|
2010-08-28 05:59:27 +08:00
|
|
|
XPD_DBG(DEVICES, xpd, "'%s' finished OK\n", init_card);
|
2012-01-11 23:20:05 +08:00
|
|
|
else if (ret < 0) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XPD_ERR(xpd, "Failed running '%s' (errno %d)\n", init_card,
|
|
|
|
ret);
|
2010-08-28 05:59:27 +08:00
|
|
|
} else {
|
2012-01-11 23:22:46 +08:00
|
|
|
__u8 exitval = ((unsigned)ret >> 8) & 0xFF;
|
|
|
|
__u8 sigval = ret & 0xFF;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!exitval) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XPD_ERR(xpd, "'%s' killed by signal %d\n", init_card,
|
|
|
|
sigval);
|
2010-08-28 05:59:27 +08:00
|
|
|
} else {
|
2012-01-11 23:22:46 +08:00
|
|
|
XPD_ERR(xpd, "'%s' aborted with exitval %d\n",
|
|
|
|
init_card, exitval);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
ret = -EINVAL;
|
|
|
|
}
|
|
|
|
err:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(run_initialize_registers);
|