Lines Matching refs:serial
141 struct mctp_binding_serial *serial = binding_to_serial(b); in mctp_binding_serial_tx() local
152 hdr = (void *)serial->txbuf; in mctp_binding_serial_tx()
164 if (len + sizeof(*hdr) + sizeof(*tlr) > sizeof(serial->txbuf)) in mctp_binding_serial_tx()
178 if (!serial->tx_fn) in mctp_binding_serial_tx()
179 return mctp_write_all(mctp_serial_write, serial->fd, in mctp_binding_serial_tx()
180 &serial->txbuf[0], len); in mctp_binding_serial_tx()
182 return mctp_write_all(serial->tx_fn, serial->tx_fn_data, in mctp_binding_serial_tx()
183 &serial->txbuf[0], len); in mctp_binding_serial_tx()
186 static void mctp_serial_finish_packet(struct mctp_binding_serial *serial, in mctp_serial_finish_packet() argument
189 struct mctp_pktbuf *pkt = serial->rx_pkt; in mctp_serial_finish_packet()
193 mctp_bus_rx(&serial->binding, pkt); in mctp_serial_finish_packet()
195 serial->rx_pkt = NULL; in mctp_serial_finish_packet()
198 static void mctp_serial_start_packet(struct mctp_binding_serial *serial, in mctp_serial_start_packet() argument
201 serial->rx_pkt = mctp_pktbuf_alloc(&serial->binding, len); in mctp_serial_start_packet()
204 static void mctp_rx_consume_one(struct mctp_binding_serial *serial, uint8_t c) in mctp_rx_consume_one() argument
206 struct mctp_pktbuf *pkt = serial->rx_pkt; in mctp_rx_consume_one()
209 mctp_prdebug("state: %d, char 0x%02x", serial->rx_state, c); in mctp_rx_consume_one()
211 assert(!pkt == (serial->rx_state == STATE_WAIT_SYNC_START || in mctp_rx_consume_one()
212 serial->rx_state == STATE_WAIT_REVISION || in mctp_rx_consume_one()
213 serial->rx_state == STATE_WAIT_LEN)); in mctp_rx_consume_one()
215 switch (serial->rx_state) { in mctp_rx_consume_one()
220 mctp_serial_finish_packet(serial, false); in mctp_rx_consume_one()
222 serial->rx_state = STATE_WAIT_REVISION; in mctp_rx_consume_one()
228 serial->rx_state = STATE_WAIT_LEN; in mctp_rx_consume_one()
229 serial->rx_fcs_calc = crc_16_ccitt_byte(FCS_INIT_16, c); in mctp_rx_consume_one()
244 serial->rx_state = STATE_WAIT_SYNC_START; in mctp_rx_consume_one()
248 if (c > serial->binding.pkt_size || in mctp_rx_consume_one()
251 serial->rx_state = STATE_WAIT_SYNC_START; in mctp_rx_consume_one()
253 mctp_serial_start_packet(serial, 0); in mctp_rx_consume_one()
254 pkt = serial->rx_pkt; in mctp_rx_consume_one()
255 serial->rx_exp_len = c; in mctp_rx_consume_one()
256 serial->rx_state = STATE_DATA; in mctp_rx_consume_one()
257 serial->rx_fcs_calc = in mctp_rx_consume_one()
258 crc_16_ccitt_byte(serial->rx_fcs_calc, c); in mctp_rx_consume_one()
264 serial->rx_state = STATE_DATA_ESCAPED; in mctp_rx_consume_one()
267 serial->rx_fcs_calc = in mctp_rx_consume_one()
268 crc_16_ccitt_byte(serial->rx_fcs_calc, c); in mctp_rx_consume_one()
269 if (pkt->end - pkt->mctp_hdr_off == serial->rx_exp_len) in mctp_rx_consume_one()
270 serial->rx_state = STATE_WAIT_FCS1; in mctp_rx_consume_one()
277 serial->rx_fcs_calc = crc_16_ccitt_byte(serial->rx_fcs_calc, c); in mctp_rx_consume_one()
278 if (pkt->end - pkt->mctp_hdr_off == serial->rx_exp_len) in mctp_rx_consume_one()
279 serial->rx_state = STATE_WAIT_FCS1; in mctp_rx_consume_one()
281 serial->rx_state = STATE_DATA; in mctp_rx_consume_one()
285 serial->rx_fcs = c << 8; in mctp_rx_consume_one()
286 serial->rx_state = STATE_WAIT_FCS2; in mctp_rx_consume_one()
289 serial->rx_fcs |= c; in mctp_rx_consume_one()
290 serial->rx_state = STATE_WAIT_SYNC_END; in mctp_rx_consume_one()
294 if (serial->rx_fcs == serial->rx_fcs_calc) { in mctp_rx_consume_one()
304 serial->rx_fcs, serial->rx_fcs_calc); in mctp_rx_consume_one()
307 mctp_serial_finish_packet(serial, valid); in mctp_rx_consume_one()
308 serial->rx_state = STATE_WAIT_SYNC_START; in mctp_rx_consume_one()
312 mctp_prdebug(" -> state: %d", serial->rx_state); in mctp_rx_consume_one()
314 static void mctp_rx_consume(struct mctp_binding_serial *serial, const void *buf, in mctp_rx_consume() argument
320 mctp_rx_consume_one(serial, *(uint8_t *)(buf + i)); in mctp_rx_consume()
324 int mctp_serial_read(struct mctp_binding_serial *serial) in mctp_serial_read() argument
328 len = read(serial->fd, serial->rxbuf, sizeof(serial->rxbuf)); in mctp_serial_read()
337 mctp_rx_consume(serial, serial->rxbuf, len); in mctp_serial_read()
342 int mctp_serial_init_pollfd(struct mctp_binding_serial *serial, in mctp_serial_init_pollfd() argument
345 pollfd->fd = serial->fd; in mctp_serial_init_pollfd()
351 int mctp_serial_open_path(struct mctp_binding_serial *serial, in mctp_serial_open_path() argument
354 serial->fd = open(device, O_RDWR); in mctp_serial_open_path()
355 if (serial->fd < 0) in mctp_serial_open_path()
361 void mctp_serial_open_fd(struct mctp_binding_serial *serial, int fd) in mctp_serial_open_fd() argument
363 serial->fd = fd; in mctp_serial_open_fd()
367 void mctp_serial_set_tx_fn(struct mctp_binding_serial *serial, in mctp_serial_set_tx_fn() argument
370 serial->tx_fn = fn; in mctp_serial_set_tx_fn()
371 serial->tx_fn_data = data; in mctp_serial_set_tx_fn()
374 int mctp_serial_rx(struct mctp_binding_serial *serial, const void *buf, in mctp_serial_rx() argument
377 mctp_rx_consume(serial, buf, len); in mctp_serial_rx()
394 struct mctp_binding_serial *serial; in mctp_serial_init() local
396 serial = __mctp_alloc(sizeof(*serial)); in mctp_serial_init()
397 memset(serial, 0, sizeof(*serial)); in mctp_serial_init()
398 serial->fd = -1; in mctp_serial_init()
399 serial->rx_state = STATE_WAIT_SYNC_START; in mctp_serial_init()
400 serial->rx_pkt = NULL; in mctp_serial_init()
401 serial->binding.name = "serial"; in mctp_serial_init()
402 serial->binding.version = 1; in mctp_serial_init()
403 serial->binding.pkt_size = MCTP_PACKET_SIZE(MCTP_BTU); in mctp_serial_init()
404 serial->binding.pkt_header = 0; in mctp_serial_init()
405 serial->binding.pkt_trailer = 0; in mctp_serial_init()
407 serial->binding.start = mctp_serial_core_start; in mctp_serial_init()
408 serial->binding.tx = mctp_binding_serial_tx; in mctp_serial_init()
410 return serial; in mctp_serial_init()
413 void mctp_serial_destroy(struct mctp_binding_serial *serial) in mctp_serial_destroy() argument
415 __mctp_free(serial); in mctp_serial_destroy()