|
5 | 5 | #include "netlink.h"
|
6 | 6 | #include "common.h"
|
7 | 7 | #include "bitset.h"
|
| 8 | +#include "module_fw.h" |
8 | 9 |
|
9 | 10 | struct module_req_info {
|
10 | 11 | struct ethnl_req_info base;
|
@@ -158,3 +159,119 @@ const struct ethnl_request_ops ethnl_module_request_ops = {
|
158 | 159 | .set = ethnl_set_module,
|
159 | 160 | .set_ntf_cmd = ETHTOOL_MSG_MODULE_NTF,
|
160 | 161 | };
|
| 162 | + |
| 163 | +/* MODULE_FW_FLASH_NTF */ |
| 164 | + |
| 165 | +static int |
| 166 | +ethnl_module_fw_flash_ntf_put_err(struct sk_buff *skb, char *err_msg, |
| 167 | + char *sub_err_msg) |
| 168 | +{ |
| 169 | + int err_msg_len, sub_err_msg_len, total_len; |
| 170 | + struct nlattr *attr; |
| 171 | + |
| 172 | + if (!err_msg) |
| 173 | + return 0; |
| 174 | + |
| 175 | + err_msg_len = strlen(err_msg); |
| 176 | + total_len = err_msg_len + 2; /* For period and NUL. */ |
| 177 | + |
| 178 | + if (sub_err_msg) { |
| 179 | + sub_err_msg_len = strlen(sub_err_msg); |
| 180 | + total_len += sub_err_msg_len + 2; /* For ", ". */ |
| 181 | + } |
| 182 | + |
| 183 | + attr = nla_reserve(skb, ETHTOOL_A_MODULE_FW_FLASH_STATUS_MSG, |
| 184 | + total_len); |
| 185 | + if (!attr) |
| 186 | + return -ENOMEM; |
| 187 | + |
| 188 | + if (sub_err_msg) |
| 189 | + sprintf(nla_data(attr), "%s, %s.", err_msg, sub_err_msg); |
| 190 | + else |
| 191 | + sprintf(nla_data(attr), "%s.", err_msg); |
| 192 | + |
| 193 | + return 0; |
| 194 | +} |
| 195 | + |
| 196 | +static void |
| 197 | +ethnl_module_fw_flash_ntf(struct net_device *dev, |
| 198 | + enum ethtool_module_fw_flash_status status, |
| 199 | + struct ethnl_module_fw_flash_ntf_params *ntf_params, |
| 200 | + char *err_msg, char *sub_err_msg, |
| 201 | + u64 done, u64 total) |
| 202 | +{ |
| 203 | + struct sk_buff *skb; |
| 204 | + void *hdr; |
| 205 | + int ret; |
| 206 | + |
| 207 | + if (ntf_params->closed_sock) |
| 208 | + return; |
| 209 | + |
| 210 | + skb = genlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 211 | + if (!skb) |
| 212 | + return; |
| 213 | + |
| 214 | + hdr = ethnl_unicast_put(skb, ntf_params->portid, ntf_params->seq, |
| 215 | + ETHTOOL_MSG_MODULE_FW_FLASH_NTF); |
| 216 | + if (!hdr) |
| 217 | + goto err_skb; |
| 218 | + |
| 219 | + ret = ethnl_fill_reply_header(skb, dev, |
| 220 | + ETHTOOL_A_MODULE_FW_FLASH_HEADER); |
| 221 | + if (ret < 0) |
| 222 | + goto err_skb; |
| 223 | + |
| 224 | + if (nla_put_u32(skb, ETHTOOL_A_MODULE_FW_FLASH_STATUS, status)) |
| 225 | + goto err_skb; |
| 226 | + |
| 227 | + ret = ethnl_module_fw_flash_ntf_put_err(skb, err_msg, sub_err_msg); |
| 228 | + if (ret < 0) |
| 229 | + goto err_skb; |
| 230 | + |
| 231 | + if (nla_put_uint(skb, ETHTOOL_A_MODULE_FW_FLASH_DONE, done)) |
| 232 | + goto err_skb; |
| 233 | + |
| 234 | + if (nla_put_uint(skb, ETHTOOL_A_MODULE_FW_FLASH_TOTAL, total)) |
| 235 | + goto err_skb; |
| 236 | + |
| 237 | + genlmsg_end(skb, hdr); |
| 238 | + genlmsg_unicast(dev_net(dev), skb, ntf_params->portid); |
| 239 | + return; |
| 240 | + |
| 241 | +err_skb: |
| 242 | + nlmsg_free(skb); |
| 243 | +} |
| 244 | + |
| 245 | +void ethnl_module_fw_flash_ntf_err(struct net_device *dev, |
| 246 | + struct ethnl_module_fw_flash_ntf_params *params, |
| 247 | + char *err_msg, char *sub_err_msg) |
| 248 | +{ |
| 249 | + ethnl_module_fw_flash_ntf(dev, ETHTOOL_MODULE_FW_FLASH_STATUS_ERROR, |
| 250 | + params, err_msg, sub_err_msg, 0, 0); |
| 251 | +} |
| 252 | + |
| 253 | +void |
| 254 | +ethnl_module_fw_flash_ntf_start(struct net_device *dev, |
| 255 | + struct ethnl_module_fw_flash_ntf_params *params) |
| 256 | +{ |
| 257 | + ethnl_module_fw_flash_ntf(dev, ETHTOOL_MODULE_FW_FLASH_STATUS_STARTED, |
| 258 | + params, NULL, NULL, 0, 0); |
| 259 | +} |
| 260 | + |
| 261 | +void |
| 262 | +ethnl_module_fw_flash_ntf_complete(struct net_device *dev, |
| 263 | + struct ethnl_module_fw_flash_ntf_params *params) |
| 264 | +{ |
| 265 | + ethnl_module_fw_flash_ntf(dev, ETHTOOL_MODULE_FW_FLASH_STATUS_COMPLETED, |
| 266 | + params, NULL, NULL, 0, 0); |
| 267 | +} |
| 268 | + |
| 269 | +void |
| 270 | +ethnl_module_fw_flash_ntf_in_progress(struct net_device *dev, |
| 271 | + struct ethnl_module_fw_flash_ntf_params *params, |
| 272 | + u64 done, u64 total) |
| 273 | +{ |
| 274 | + ethnl_module_fw_flash_ntf(dev, |
| 275 | + ETHTOOL_MODULE_FW_FLASH_STATUS_IN_PROGRESS, |
| 276 | + params, NULL, NULL, done, total); |
| 277 | +} |
0 commit comments