Changeset 1634

Show
Ignore:
Timestamp:
11/21/02 02:32:35 (11 years ago)
Author:
mds
Message:

support multiple clients; guard against clients vanishing

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/trunk/kernel/busses/i2c-ipmi.c

    r1625 r1634  
    110110/************** Message Sending **************/ 
    111111 
     112static int find_client(struct i2c_client * client) 
     113{ 
     114        int i; 
     115 
     116        for (i = 0; i < I2C_CLIENT_MAX; i++) 
     117                if (client == i2c_ipmi_adapter.clients[i]) 
     118                        return i; 
     119        return -1; 
     120} 
     121 
    112122static void ipmi_i2c_send_message(int id, struct ipmi_msg * msg) 
    113123{ 
    114         ipmi_request(i2c_ipmi_user, &address, id, msg, 0); 
     124        ipmi_request(i2c_ipmi_user, &address, (long) id, msg, 0); 
    115125} 
    116126 
     
    124134        struct ipmi_msg *msg = (struct ipmi_msg *) mesg; 
    125135        struct i2c_client *client = (struct i2c_client *) clnt; 
    126  
    127         /* todo: keep track of multiple clients and save callback for each */ 
    128         id = (id & 0xffffff) | 0x1000000; 
    129         rcv_callback = client->driver->command; 
     136        int clientid; 
     137         
     138#ifdef DEBUG 
     139        if(msg->data == NULL) 
     140                printk(KERN_INFO "i2c-ipmi.o: Send 0x%x\n", msg->cmd); 
     141        else 
     142                printk(KERN_INFO "i2c-ipmi.o: Send 0x%x 0x%x 0x%x\n", msg->cmd, msg->data[0], msg->data[1]); 
     143#endif 
     144        /* save the client number in the upper 8 bits of the message id */ 
     145        if((clientid = find_client(client)) < 0) { 
     146                printk(KERN_WARNING "i2c-ipmi.o: Request from unknown client\n"); 
     147                return -1;       
     148        } 
     149 
     150        id = (id & 0xffffff) | (clientid << 24); 
    130151        ipmi_i2c_send_message(id, msg); 
    131152        return 0; 
     
    138159{ 
    139160        int rcvid = msg->msgid & 0xffffff; 
    140         int client = (msg->msgid >> 24) & 0xf; 
     161        int clientid = (msg->msgid >> 24) & 0xff; 
    141162 
    142163#ifdef DEBUG 
    143164        if (msg->msg.data[0] != 0) 
    144                 printk(KERN_WARNING "IPMI BMC response: Error 0x%x on cmd 0x%x/0x%x\n", 
     165                printk(KERN_WARNING "i2c-ipmi.o: Error 0x%x on cmd 0x%x/0x%x\n", 
    145166                       msg->msg.data[0], msg->msg.netfn, msg->msg.cmd); 
    146167#endif 
    147         /* todo: keep track of multiple clients */ 
    148         if(client == 1 && rcv_callback != NULL) 
    149                 (*rcv_callback)(NULL, client, msg); 
    150         else 
     168        /* Protect ourselves here; verify the client and its callback 
     169           since the client may have gone away since 
     170           the message was sent! */ 
     171        if(clientid < I2C_CLIENT_MAX && 
     172           i2c_ipmi_adapter.clients[clientid] != NULL && 
     173           i2c_ipmi_adapter.clients[clientid]->driver->command != NULL) 
     174                (* i2c_ipmi_adapter.clients[clientid]->driver->command) 
     175                     (i2c_ipmi_adapter.clients[clientid], rcvid, msg); 
     176        else { 
     177                printk(KERN_WARNING "i2c-ipmi.o: Response for unknown client\n"); 
    151178                ipmi_free_recv_msg(msg); 
     179        } 
    152180} 
    153181