21 #include <linux/sched.h>
22 #include <asm/div64.h>
54 if ((ret != vector) ||
time_after(jiffies, stamp))
61 dev_alert(&card->
pdev->dev,
"firmware %s failed (%i)\n", msg, ret);
65 static int softing_fct_cmd(
struct softing *card,
int16_t cmd,
const char *msg)
69 ret = _softing_fct_cmd(card, cmd, 0, msg);
71 dev_alert(&card->
pdev->dev,
"%s returned %u\n", msg, ret);
99 }
while (!signal_pending(
current));
102 dev_alert(&card->
pdev->dev,
"bootloader %s failed (%i)\n", msg, ret);
134 end = &mem[8 + *
plen];
136 for (checksum[1] = 0; mem <
end; ++
mem)
138 if (checksum[0] != checksum[1])
160 dev_dbg(&card->
pdev->dev,
"%s, firmware(%s) got %u bytes"
161 ", offset %c0x%04x\n",
162 card->
pdat->name, file, (
unsigned int)fw->
size,
163 (offset >= 0) ?
'+' :
'-', (
unsigned int)
abs(offset));
166 end = &mem[fw->
size];
168 ret = fw_parse(&mem, &type, &addr, &len, &dat);
173 if (
strncmp(
"Structured Binary Format, Softing GmbH" , dat, len)) {
179 ret = fw_parse(&mem, &type, &addr, &len, &dat);
185 }
else if (type == 1) {
189 }
else if (type != 0) {
194 if ((addr + len + offset) > size)
201 buflen = (len + (1024-1)) & ~(1024-1);
211 if (
memcmp(buf, dat, len)) {
213 dev_alert(&card->
pdev->dev,
"DPRAM readback failed\n");
226 dev_info(&card->
pdev->dev,
"firmware %s failed\n", file);
237 unsigned int sum, rx_sum;
238 int8_t type_end = 0, type_entrypoint = 0;
242 dev_alert(&card->
pdev->dev,
"request_firmware(%s) got %i\n",
246 dev_dbg(&card->
pdev->dev,
"firmware(%s) got %lu bytes\n",
247 file, (
unsigned long)fw->
size);
250 end = &mem[fw->
size];
252 ret = fw_parse(&mem, &type, &addr, &len, &dat);
256 if (type != 0xffff) {
257 dev_alert(&card->
pdev->dev,
"firmware starts with type 0x%x\n",
261 if (
strncmp(
"Structured Binary Format, Softing GmbH", dat, len)) {
262 dev_alert(&card->
pdev->dev,
"firmware string '%.*s' fault\n",
268 ret = fw_parse(&mem, &type, &addr, &len, &dat);
277 }
else if (type == 1) {
281 }
else if (type != 0) {
282 dev_alert(&card->
pdev->dev,
283 "unknown record type 0x%04x\n", type);
289 for (sum = 0, j = 0; j < len; ++
j)
306 dev_alert(&card->
pdev->dev,
"SRAM seems to be damaged"
307 ", wanted 0x%04x, got 0x%04x\n", sum, rx_sum);
312 if (!type_end || !type_entrypoint)
324 dev_info(&card->
pdev->dev,
"firmware %s failed\n", file);
328 static int softing_reset_chip(
struct softing *card)
339 ret = softing_fct_cmd(card, 0,
"reset_can");
346 card->
tx.pending = 0;
354 ret = _softing_fct_cmd(card, 99, 0x55,
"sync-a");
358 ret = _softing_fct_cmd(card, 99, 0xaa,
"sync-b");
362 ret = softing_reset_chip(card);
366 ret = softing_fct_cmd(card, 43,
"get_serial_number");
371 ret = softing_fct_cmd(card, 12,
"get_version");
384 static void softing_initialize_timestamp(
struct softing *card)
391 ovf = 0x100000000ULL * 16;
394 card->
ts_overflow = ktime_add_us(ktime_set(0, 0), ovf);
410 target = ktime_add_us(card->
ts_ref, rawl);
413 while (
unlikely(ktime_to_ns(tmp) > ktime_to_ns(now))) {
418 return ktime_add(target, real_offset);
421 static inline int softing_error_reporting(
struct net_device *netdev)
435 int bus_bitmask_start;
436 int j, error_reporting;
440 priv = netdev_priv(dev);
450 bus_bitmask_start = 0;
453 bus_bitmask_start |= (1 << priv->
index);
456 netdev = card->
net[
j];
459 priv = netdev_priv(netdev);
462 netif_stop_queue(netdev);
464 if (netif_running(netdev)) {
466 bus_bitmask_start |= (1 <<
j);
467 priv->
tx.pending = 0;
468 priv->
tx.echo_put = 0;
469 priv->
tx.echo_get = 0;
482 card->
tx.pending = 0;
485 ret = softing_reset_chip(card);
488 if (!bus_bitmask_start)
492 if ((bus_bitmask_start & 1) && (bus_bitmask_start & 2)
493 && (softing_error_reporting(card->
net[0])
494 != softing_error_reporting(card->
net[1]))) {
495 dev_alert(&card->
pdev->dev,
496 "err_reporting flag differs for busses\n");
500 if (bus_bitmask_start & 1) {
501 netdev = card->
net[0];
502 priv = netdev_priv(netdev);
503 error_reporting += softing_error_reporting(netdev);
505 bt = &priv->
can.bittiming;
513 ret = softing_fct_cmd(card, 1,
"initialize_chip[0]");
519 ret = softing_fct_cmd(card, 3,
"set_mode[0]");
531 ret = softing_fct_cmd(card, 7,
"set_filter[0]");
536 ret = softing_fct_cmd(card, 5,
"set_output[0]");
540 if (bus_bitmask_start & 2) {
541 netdev = card->
net[1];
542 priv = netdev_priv(netdev);
543 error_reporting += softing_error_reporting(netdev);
545 bt = &priv->
can.bittiming;
553 ret = softing_fct_cmd(card, 2,
"initialize_chip[1]");
559 ret = softing_fct_cmd(card, 4,
"set_mode[1]");
571 ret = softing_fct_cmd(card, 8,
"set_filter[1]");
576 ret = softing_fct_cmd(card, 6,
"set_output[1]");
603 ret = softing_fct_cmd(card, 17,
"initialize_interface");
607 ret = softing_fct_cmd(card, 36,
"enable_fifo");
611 ret = softing_fct_cmd(card, 13,
"fifo_tx_ack[0]");
615 ret = softing_fct_cmd(card, 14,
"fifo_tx_ack[1]");
619 ret = softing_fct_cmd(card, 11,
"start_chip");
624 if (card->
pdat->generation < 2) {
630 softing_initialize_timestamp(card);
637 memset(&msg, 0,
sizeof(msg));
641 if (!(bus_bitmask_start & (1 << j)))
643 netdev = card->
net[
j];
646 priv = netdev_priv(netdev);
652 ++priv->
can.can_stats.restarts;
654 netif_wake_queue(netdev);
668 softing_reset_chip(card);
672 netdev = card->
net[
j];
685 switch (priv->
chip) {
687 return (card->
pdat->generation < 2) ? 0xfb : 0xfa;