mcdi.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /****************************************************************************
  2. * Driver for Solarflare Solarstorm network controllers and boards
  3. * Copyright 2008-2010 Solarflare Communications Inc.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License version 2 as published
  7. * by the Free Software Foundation, incorporated herein by reference.
  8. */
  9. #ifndef EFX_MCDI_H
  10. #define EFX_MCDI_H
  11. /**
  12. * enum efx_mcdi_state
  13. * @MCDI_STATE_QUIESCENT: No pending MCDI requests. If the caller holds the
  14. * mcdi_lock then they are able to move to MCDI_STATE_RUNNING
  15. * @MCDI_STATE_RUNNING: There is an MCDI request pending. Only the thread that
  16. * moved into this state is allowed to move out of it.
  17. * @MCDI_STATE_COMPLETED: An MCDI request has completed, but the owning thread
  18. * has not yet consumed the result. For all other threads, equivalent to
  19. * MCDI_STATE_RUNNING.
  20. */
  21. enum efx_mcdi_state {
  22. MCDI_STATE_QUIESCENT,
  23. MCDI_STATE_RUNNING,
  24. MCDI_STATE_COMPLETED,
  25. };
  26. enum efx_mcdi_mode {
  27. MCDI_MODE_POLL,
  28. MCDI_MODE_EVENTS,
  29. };
  30. /**
  31. * struct efx_mcdi_iface
  32. * @state: Interface state. Waited for by mcdi_wq.
  33. * @wq: Wait queue for threads waiting for state != STATE_RUNNING
  34. * @iface_lock: Protects @credits, @seqno, @resprc, @resplen
  35. * @mode: Poll for mcdi completion, or wait for an mcdi_event.
  36. * Serialised by @lock
  37. * @seqno: The next sequence number to use for mcdi requests.
  38. * Serialised by @lock
  39. * @credits: Number of spurious MCDI completion events allowed before we
  40. * trigger a fatal error. Protected by @lock
  41. * @resprc: Returned MCDI completion
  42. * @resplen: Returned payload length
  43. */
  44. struct efx_mcdi_iface {
  45. atomic_t state;
  46. wait_queue_head_t wq;
  47. spinlock_t iface_lock;
  48. enum efx_mcdi_mode mode;
  49. unsigned int credits;
  50. unsigned int seqno;
  51. unsigned int resprc;
  52. size_t resplen;
  53. };
  54. extern void efx_mcdi_init(struct efx_nic *efx);
  55. extern int efx_mcdi_rpc(struct efx_nic *efx, unsigned cmd, const u8 *inbuf,
  56. size_t inlen, u8 *outbuf, size_t outlen,
  57. size_t *outlen_actual);
  58. extern int efx_mcdi_poll_reboot(struct efx_nic *efx);
  59. extern void efx_mcdi_mode_poll(struct efx_nic *efx);
  60. extern void efx_mcdi_mode_event(struct efx_nic *efx);
  61. extern void efx_mcdi_process_event(struct efx_channel *channel,
  62. efx_qword_t *event);
  63. #define MCDI_PTR2(_buf, _ofst) \
  64. (((u8 *)_buf) + _ofst)
  65. #define MCDI_SET_DWORD2(_buf, _ofst, _value) \
  66. EFX_POPULATE_DWORD_1(*((efx_dword_t *)MCDI_PTR2(_buf, _ofst)), \
  67. EFX_DWORD_0, _value)
  68. #define MCDI_DWORD2(_buf, _ofst) \
  69. EFX_DWORD_FIELD(*((efx_dword_t *)MCDI_PTR2(_buf, _ofst)), \
  70. EFX_DWORD_0)
  71. #define MCDI_QWORD2(_buf, _ofst) \
  72. EFX_QWORD_FIELD64(*((efx_qword_t *)MCDI_PTR2(_buf, _ofst)), \
  73. EFX_QWORD_0)
  74. #define MCDI_PTR(_buf, _ofst) \
  75. MCDI_PTR2(_buf, MC_CMD_ ## _ofst ## _OFST)
  76. #define MCDI_SET_DWORD(_buf, _ofst, _value) \
  77. MCDI_SET_DWORD2(_buf, MC_CMD_ ## _ofst ## _OFST, _value)
  78. #define MCDI_DWORD(_buf, _ofst) \
  79. MCDI_DWORD2(_buf, MC_CMD_ ## _ofst ## _OFST)
  80. #define MCDI_QWORD(_buf, _ofst) \
  81. MCDI_QWORD2(_buf, MC_CMD_ ## _ofst ## _OFST)
  82. #define MCDI_EVENT_FIELD(_ev, _field) \
  83. EFX_QWORD_FIELD(_ev, MCDI_EVENT_ ## _field)
  84. extern void efx_mcdi_print_fwver(struct efx_nic *efx, char *buf, size_t len);
  85. extern int efx_mcdi_drv_attach(struct efx_nic *efx, bool driver_operating,
  86. bool *was_attached_out);
  87. extern int efx_mcdi_get_board_cfg(struct efx_nic *efx, u8 *mac_address,
  88. u16 *fw_subtype_list);
  89. extern int efx_mcdi_log_ctrl(struct efx_nic *efx, bool evq, bool uart,
  90. u32 dest_evq);
  91. extern int efx_mcdi_nvram_types(struct efx_nic *efx, u32 *nvram_types_out);
  92. extern int efx_mcdi_nvram_info(struct efx_nic *efx, unsigned int type,
  93. size_t *size_out, size_t *erase_size_out,
  94. bool *protected_out);
  95. extern int efx_mcdi_nvram_update_start(struct efx_nic *efx,
  96. unsigned int type);
  97. extern int efx_mcdi_nvram_read(struct efx_nic *efx, unsigned int type,
  98. loff_t offset, u8 *buffer, size_t length);
  99. extern int efx_mcdi_nvram_write(struct efx_nic *efx, unsigned int type,
  100. loff_t offset, const u8 *buffer,
  101. size_t length);
  102. #define EFX_MCDI_NVRAM_LEN_MAX 128
  103. extern int efx_mcdi_nvram_erase(struct efx_nic *efx, unsigned int type,
  104. loff_t offset, size_t length);
  105. extern int efx_mcdi_nvram_update_finish(struct efx_nic *efx,
  106. unsigned int type);
  107. extern int efx_mcdi_nvram_test_all(struct efx_nic *efx);
  108. extern int efx_mcdi_handle_assertion(struct efx_nic *efx);
  109. extern void efx_mcdi_set_id_led(struct efx_nic *efx, enum efx_led_mode mode);
  110. extern int efx_mcdi_reset_port(struct efx_nic *efx);
  111. extern int efx_mcdi_reset_mc(struct efx_nic *efx);
  112. extern int efx_mcdi_wol_filter_set_magic(struct efx_nic *efx,
  113. const u8 *mac, int *id_out);
  114. extern int efx_mcdi_wol_filter_get_magic(struct efx_nic *efx, int *id_out);
  115. extern int efx_mcdi_wol_filter_remove(struct efx_nic *efx, int id);
  116. extern int efx_mcdi_wol_filter_reset(struct efx_nic *efx);
  117. #endif /* EFX_MCDI_H */