ipmi_smic.c (163033) | ipmi_smic.c (163034) |
---|---|
1/*- 2 * Copyright (c) 2006 IronPort Systems Inc. <ambrisko@ironport.com> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2006 IronPort Systems Inc. <ambrisko@ironport.com> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> |
28__FBSDID("$FreeBSD: head/sys/dev/ipmi/ipmi_smic.c 163033 2006-10-05 15:33:43Z jhb $"); | 28__FBSDID("$FreeBSD: head/sys/dev/ipmi/ipmi_smic.c 163034 2006-10-05 15:35:11Z jhb $"); |
29 30#include <sys/param.h> 31#include <sys/systm.h> 32#include <sys/bus.h> 33#include <sys/condvar.h> 34#include <sys/eventhandler.h> 35#include <sys/kernel.h> 36#include <sys/kthread.h> --- 205 unchanged lines hidden (view full) --- 242smic_polled_request(struct ipmi_softc *sc, struct ipmi_request *req) 243{ 244 u_char *cp, data; 245 int i, state; 246 247 /* First, start the message with the address. */ 248 if (!smic_start_write(sc, req->ir_addr)) 249 return (0); | 29 30#include <sys/param.h> 31#include <sys/systm.h> 32#include <sys/bus.h> 33#include <sys/condvar.h> 34#include <sys/eventhandler.h> 35#include <sys/kernel.h> 36#include <sys/kthread.h> --- 205 unchanged lines hidden (view full) --- 242smic_polled_request(struct ipmi_softc *sc, struct ipmi_request *req) 243{ 244 u_char *cp, data; 245 int i, state; 246 247 /* First, start the message with the address. */ 248 if (!smic_start_write(sc, req->ir_addr)) 249 return (0); |
250#ifdef SMIC_DEBUG 251 device_printf(sc->ipmi_dev, "SMIC: WRITE_START address: %02x\n", 252 req->ir_addr); 253#endif |
|
250 251 if (req->ir_requestlen == 0) { 252 /* Send the command as the last byte. */ 253 if (!smic_write_last(sc, req->ir_command)) 254 return (0); | 254 255 if (req->ir_requestlen == 0) { 256 /* Send the command as the last byte. */ 257 if (!smic_write_last(sc, req->ir_command)) 258 return (0); |
259#ifdef SMIC_DEBUG 260 device_printf(sc->ipmi_dev, "SMIC: Wrote command: %02x\n", 261 req->ir_command); 262#endif |
|
255 } else { 256 /* Send the command. */ 257 if (!smic_write_next(sc, req->ir_command)) 258 return (0); | 263 } else { 264 /* Send the command. */ 265 if (!smic_write_next(sc, req->ir_command)) 266 return (0); |
267#ifdef SMIC_DEBUG 268 device_printf(sc->ipmi_dev, "SMIC: Wrote command: %02x\n", 269 req->ir_command); 270#endif |
|
259 260 /* Send the payload. */ 261 cp = req->ir_request; | 271 272 /* Send the payload. */ 273 cp = req->ir_request; |
262 for (i = 0; i < req->ir_requestlen - 1; i++) | 274 for (i = 0; i < req->ir_requestlen - 1; i++) { |
263 if (!smic_write_next(sc, *cp++)) 264 return (0); | 275 if (!smic_write_next(sc, *cp++)) 276 return (0); |
277#ifdef SMIC_DEBUG 278 device_printf(sc->ipmi_dev, "SMIC: Wrote data: %02x\n", 279 cp[-1]); 280#endif 281 } |
|
265 if (!smic_write_last(sc, *cp)) 266 return (0); | 282 if (!smic_write_last(sc, *cp)) 283 return (0); |
284#ifdef SMIC_DEBUG 285 device_printf(sc->ipmi_dev, "SMIC: Write last data: %02x\n", 286 *cp); 287#endif |
|
267 } 268 269 /* Start the read phase by reading the NetFn/LUN. */ 270 if (smic_start_read(sc, &data) != 1) 271 return (0); | 288 } 289 290 /* Start the read phase by reading the NetFn/LUN. */ 291 if (smic_start_read(sc, &data) != 1) 292 return (0); |
293#ifdef SMIC_DEBUG 294 device_printf(sc->ipmi_dev, "SMIC: Read address: %02x\n", data); 295#endif |
|
272 if (data != IPMI_REPLY_ADDR(req->ir_addr)) { 273 device_printf(sc->ipmi_dev, "SMIC: Reply address mismatch\n"); 274 return (0); 275 } 276 277 /* Read the command. */ 278 if (smic_read_byte(sc, &data) != 1) 279 return (0); | 296 if (data != IPMI_REPLY_ADDR(req->ir_addr)) { 297 device_printf(sc->ipmi_dev, "SMIC: Reply address mismatch\n"); 298 return (0); 299 } 300 301 /* Read the command. */ 302 if (smic_read_byte(sc, &data) != 1) 303 return (0); |
304#ifdef SMIC_DEBUG 305 device_printf(sc->ipmi_dev, "SMIC: Read command: %02x\n", data); 306#endif |
|
280 if (data != req->ir_command) { 281 device_printf(sc->ipmi_dev, "SMIC: Command mismatch\n"); 282 return (0); 283 } 284 285 /* Read the completion code. */ 286 state = smic_read_byte(sc, &req->ir_compcode); 287 if (state == 0) 288 return (0); | 307 if (data != req->ir_command) { 308 device_printf(sc->ipmi_dev, "SMIC: Command mismatch\n"); 309 return (0); 310 } 311 312 /* Read the completion code. */ 313 state = smic_read_byte(sc, &req->ir_compcode); 314 if (state == 0) 315 return (0); |
316#ifdef SMIC_DEBUG 317 device_printf(sc->ipmi_dev, "SMIC: Read completion code: %02x\n", 318 req->ir_compcode); 319#endif |
|
289 290 /* Finally, read the reply from the BMC. */ 291 i = 0; 292 while (state == 1) { 293 state = smic_read_byte(sc, &data); 294 if (state == 0) 295 return (0); | 320 321 /* Finally, read the reply from the BMC. */ 322 i = 0; 323 while (state == 1) { 324 state = smic_read_byte(sc, &data); 325 if (state == 0) 326 return (0); |
296 if (i < req->ir_replybuflen) | 327 if (i < req->ir_replybuflen) { |
297 req->ir_reply[i] = data; | 328 req->ir_reply[i] = data; |
329#ifdef SMIC_DEBUG 330 device_printf(sc->ipmi_dev, "SMIC: Read data: %02x\n", 331 data); 332 } else { 333 device_printf(sc->ipmi_dev, 334 "SMIC: Read short %02x byte %d\n", data, i + 1); 335#endif 336 } |
|
298 i++; 299 } 300 301 /* Terminate the transfer. */ 302 if (!smic_read_end(sc)) 303 return (0); 304 req->ir_replylen = i; | 337 i++; 338 } 339 340 /* Terminate the transfer. */ 341 if (!smic_read_end(sc)) 342 return (0); 343 req->ir_replylen = i; |
344#ifdef SMIC_DEBUG 345 device_printf(sc->ipmi_dev, "SMIC: READ finished (%d bytes)\n", i); 346 if (req->ir_replybuflen < i) 347#else |
|
305 if (req->ir_replybuflen < i && req->ir_replybuflen != 0) | 348 if (req->ir_replybuflen < i && req->ir_replybuflen != 0) |
349#endif |
|
306 device_printf(sc->ipmi_dev, 307 "SMIC: Read short: %zd buffer, %d actual\n", 308 req->ir_replybuflen, i); 309 return (1); 310} 311 312static void 313smic_loop(void *arg) --- 36 unchanged lines hidden (view full) --- 350 351 /* See if we can talk to the controller. */ 352 flags = INB(sc, SMIC_FLAGS); 353 if (flags == 0xff) { 354 device_printf(sc->ipmi_dev, "couldn't find it\n"); 355 return (ENXIO); 356 } 357 | 350 device_printf(sc->ipmi_dev, 351 "SMIC: Read short: %zd buffer, %d actual\n", 352 req->ir_replybuflen, i); 353 return (1); 354} 355 356static void 357smic_loop(void *arg) --- 36 unchanged lines hidden (view full) --- 394 395 /* See if we can talk to the controller. */ 396 flags = INB(sc, SMIC_FLAGS); 397 if (flags == 0xff) { 398 device_printf(sc->ipmi_dev, "couldn't find it\n"); 399 return (ENXIO); 400 } 401 |
402#ifdef SMIC_DEBUG 403 device_printf(sc->ipmi_dev, "SMIC: initial state: %02x\n", flags); 404#endif 405 |
|
358 return (0); 359} | 406 return (0); 407} |