~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/net/ncsi/ncsi-cmd.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /net/ncsi/ncsi-cmd.c (Version linux-6.11.5) and /net/ncsi/ncsi-cmd.c (Version linux-5.0.21)


  1 // SPDX-License-Identifier: GPL-2.0-or-later   << 
  2 /*                                                  1 /*
  3  * Copyright Gavin Shan, IBM Corporation 2016.      2  * Copyright Gavin Shan, IBM Corporation 2016.
                                                   >>   3  *
                                                   >>   4  * This program is free software; you can redistribute it and/or modify
                                                   >>   5  * it under the terms of the GNU General Public License as published by
                                                   >>   6  * the Free Software Foundation; either version 2 of the License, or
                                                   >>   7  * (at your option) any later version.
  4  */                                                 8  */
  5                                                     9 
  6 #include <linux/module.h>                          10 #include <linux/module.h>
  7 #include <linux/kernel.h>                          11 #include <linux/kernel.h>
  8 #include <linux/init.h>                            12 #include <linux/init.h>
  9 #include <linux/etherdevice.h>                     13 #include <linux/etherdevice.h>
 10 #include <linux/netdevice.h>                       14 #include <linux/netdevice.h>
 11 #include <linux/skbuff.h>                          15 #include <linux/skbuff.h>
 12                                                    16 
 13 #include <net/ncsi.h>                              17 #include <net/ncsi.h>
 14 #include <net/net_namespace.h>                     18 #include <net/net_namespace.h>
 15 #include <net/sock.h>                              19 #include <net/sock.h>
 16 #include <net/genetlink.h>                         20 #include <net/genetlink.h>
 17                                                    21 
 18 #include "internal.h"                              22 #include "internal.h"
 19 #include "ncsi-pkt.h"                              23 #include "ncsi-pkt.h"
 20                                                    24 
 21 static const int padding_bytes = 26;           << 
 22                                                << 
 23 u32 ncsi_calculate_checksum(unsigned char *dat     25 u32 ncsi_calculate_checksum(unsigned char *data, int len)
 24 {                                                  26 {
 25         u32 checksum = 0;                          27         u32 checksum = 0;
 26         int i;                                     28         int i;
 27                                                    29 
 28         for (i = 0; i < len; i += 2)               30         for (i = 0; i < len; i += 2)
 29                 checksum += (((u32)data[i] <<      31                 checksum += (((u32)data[i] << 8) | data[i + 1]);
 30                                                    32 
 31         checksum = (~checksum + 1);                33         checksum = (~checksum + 1);
 32         return checksum;                           34         return checksum;
 33 }                                                  35 }
 34                                                    36 
 35 /* This function should be called after the da     37 /* This function should be called after the data area has been
 36  * populated completely.                           38  * populated completely.
 37  */                                                39  */
 38 static void ncsi_cmd_build_header(struct ncsi_     40 static void ncsi_cmd_build_header(struct ncsi_pkt_hdr *h,
 39                                   struct ncsi_     41                                   struct ncsi_cmd_arg *nca)
 40 {                                                  42 {
 41         u32 checksum;                              43         u32 checksum;
 42         __be32 *pchecksum;                         44         __be32 *pchecksum;
 43                                                    45 
 44         h->mc_id        = 0;                       46         h->mc_id        = 0;
 45         h->revision     = NCSI_PKT_REVISION;       47         h->revision     = NCSI_PKT_REVISION;
 46         h->reserved     = 0;                       48         h->reserved     = 0;
 47         h->id           = nca->id;                 49         h->id           = nca->id;
 48         h->type         = nca->type;               50         h->type         = nca->type;
 49         h->channel      = NCSI_TO_CHANNEL(nca-     51         h->channel      = NCSI_TO_CHANNEL(nca->package,
 50                                           nca-     52                                           nca->channel);
 51         h->length       = htons(nca->payload);     53         h->length       = htons(nca->payload);
 52         h->reserved1[0] = 0;                       54         h->reserved1[0] = 0;
 53         h->reserved1[1] = 0;                       55         h->reserved1[1] = 0;
 54                                                    56 
 55         /* Fill with calculated checksum */        57         /* Fill with calculated checksum */
 56         checksum = ncsi_calculate_checksum((un     58         checksum = ncsi_calculate_checksum((unsigned char *)h,
 57                                            siz     59                                            sizeof(*h) + nca->payload);
 58         pchecksum = (__be32 *)((void *)h + siz     60         pchecksum = (__be32 *)((void *)h + sizeof(struct ncsi_pkt_hdr) +
 59                     ALIGN(nca->payload, 4));   !!  61                     nca->payload);
 60         *pchecksum = htonl(checksum);              62         *pchecksum = htonl(checksum);
 61 }                                                  63 }
 62                                                    64 
 63 static int ncsi_cmd_handler_default(struct sk_     65 static int ncsi_cmd_handler_default(struct sk_buff *skb,
 64                                     struct ncs     66                                     struct ncsi_cmd_arg *nca)
 65 {                                                  67 {
 66         struct ncsi_cmd_pkt *cmd;                  68         struct ncsi_cmd_pkt *cmd;
 67                                                    69 
 68         cmd = skb_put_zero(skb, sizeof(*cmd));     70         cmd = skb_put_zero(skb, sizeof(*cmd));
 69         ncsi_cmd_build_header(&cmd->cmd.common     71         ncsi_cmd_build_header(&cmd->cmd.common, nca);
 70                                                    72 
 71         return 0;                                  73         return 0;
 72 }                                                  74 }
 73                                                    75 
 74 static int ncsi_cmd_handler_sp(struct sk_buff      76 static int ncsi_cmd_handler_sp(struct sk_buff *skb,
 75                                struct ncsi_cmd     77                                struct ncsi_cmd_arg *nca)
 76 {                                                  78 {
 77         struct ncsi_cmd_sp_pkt *cmd;               79         struct ncsi_cmd_sp_pkt *cmd;
 78                                                    80 
 79         cmd = skb_put_zero(skb, sizeof(*cmd));     81         cmd = skb_put_zero(skb, sizeof(*cmd));
 80         cmd->hw_arbitration = nca->bytes[0];       82         cmd->hw_arbitration = nca->bytes[0];
 81         ncsi_cmd_build_header(&cmd->cmd.common     83         ncsi_cmd_build_header(&cmd->cmd.common, nca);
 82                                                    84 
 83         return 0;                                  85         return 0;
 84 }                                                  86 }
 85                                                    87 
 86 static int ncsi_cmd_handler_dc(struct sk_buff      88 static int ncsi_cmd_handler_dc(struct sk_buff *skb,
 87                                struct ncsi_cmd     89                                struct ncsi_cmd_arg *nca)
 88 {                                                  90 {
 89         struct ncsi_cmd_dc_pkt *cmd;               91         struct ncsi_cmd_dc_pkt *cmd;
 90                                                    92 
 91         cmd = skb_put_zero(skb, sizeof(*cmd));     93         cmd = skb_put_zero(skb, sizeof(*cmd));
 92         cmd->ald = nca->bytes[0];                  94         cmd->ald = nca->bytes[0];
 93         ncsi_cmd_build_header(&cmd->cmd.common     95         ncsi_cmd_build_header(&cmd->cmd.common, nca);
 94                                                    96 
 95         return 0;                                  97         return 0;
 96 }                                                  98 }
 97                                                    99 
 98 static int ncsi_cmd_handler_rc(struct sk_buff     100 static int ncsi_cmd_handler_rc(struct sk_buff *skb,
 99                                struct ncsi_cmd    101                                struct ncsi_cmd_arg *nca)
100 {                                                 102 {
101         struct ncsi_cmd_rc_pkt *cmd;              103         struct ncsi_cmd_rc_pkt *cmd;
102                                                   104 
103         cmd = skb_put_zero(skb, sizeof(*cmd));    105         cmd = skb_put_zero(skb, sizeof(*cmd));
104         ncsi_cmd_build_header(&cmd->cmd.common    106         ncsi_cmd_build_header(&cmd->cmd.common, nca);
105                                                   107 
106         return 0;                                 108         return 0;
107 }                                                 109 }
108                                                   110 
109 static int ncsi_cmd_handler_ae(struct sk_buff     111 static int ncsi_cmd_handler_ae(struct sk_buff *skb,
110                                struct ncsi_cmd    112                                struct ncsi_cmd_arg *nca)
111 {                                                 113 {
112         struct ncsi_cmd_ae_pkt *cmd;              114         struct ncsi_cmd_ae_pkt *cmd;
113                                                   115 
114         cmd = skb_put_zero(skb, sizeof(*cmd));    116         cmd = skb_put_zero(skb, sizeof(*cmd));
115         cmd->mc_id = nca->bytes[0];               117         cmd->mc_id = nca->bytes[0];
116         cmd->mode = htonl(nca->dwords[1]);        118         cmd->mode = htonl(nca->dwords[1]);
117         ncsi_cmd_build_header(&cmd->cmd.common    119         ncsi_cmd_build_header(&cmd->cmd.common, nca);
118                                                   120 
119         return 0;                                 121         return 0;
120 }                                                 122 }
121                                                   123 
122 static int ncsi_cmd_handler_sl(struct sk_buff     124 static int ncsi_cmd_handler_sl(struct sk_buff *skb,
123                                struct ncsi_cmd    125                                struct ncsi_cmd_arg *nca)
124 {                                                 126 {
125         struct ncsi_cmd_sl_pkt *cmd;              127         struct ncsi_cmd_sl_pkt *cmd;
126                                                   128 
127         cmd = skb_put_zero(skb, sizeof(*cmd));    129         cmd = skb_put_zero(skb, sizeof(*cmd));
128         cmd->mode = htonl(nca->dwords[0]);        130         cmd->mode = htonl(nca->dwords[0]);
129         cmd->oem_mode = htonl(nca->dwords[1]);    131         cmd->oem_mode = htonl(nca->dwords[1]);
130         ncsi_cmd_build_header(&cmd->cmd.common    132         ncsi_cmd_build_header(&cmd->cmd.common, nca);
131                                                   133 
132         return 0;                                 134         return 0;
133 }                                                 135 }
134                                                   136 
135 static int ncsi_cmd_handler_svf(struct sk_buff    137 static int ncsi_cmd_handler_svf(struct sk_buff *skb,
136                                 struct ncsi_cm    138                                 struct ncsi_cmd_arg *nca)
137 {                                                 139 {
138         struct ncsi_cmd_svf_pkt *cmd;             140         struct ncsi_cmd_svf_pkt *cmd;
139                                                   141 
140         cmd = skb_put_zero(skb, sizeof(*cmd));    142         cmd = skb_put_zero(skb, sizeof(*cmd));
141         cmd->vlan = htons(nca->words[1]);         143         cmd->vlan = htons(nca->words[1]);
142         cmd->index = nca->bytes[6];               144         cmd->index = nca->bytes[6];
143         cmd->enable = nca->bytes[7];              145         cmd->enable = nca->bytes[7];
144         ncsi_cmd_build_header(&cmd->cmd.common    146         ncsi_cmd_build_header(&cmd->cmd.common, nca);
145                                                   147 
146         return 0;                                 148         return 0;
147 }                                                 149 }
148                                                   150 
149 static int ncsi_cmd_handler_ev(struct sk_buff     151 static int ncsi_cmd_handler_ev(struct sk_buff *skb,
150                                struct ncsi_cmd    152                                struct ncsi_cmd_arg *nca)
151 {                                                 153 {
152         struct ncsi_cmd_ev_pkt *cmd;              154         struct ncsi_cmd_ev_pkt *cmd;
153                                                   155 
154         cmd = skb_put_zero(skb, sizeof(*cmd));    156         cmd = skb_put_zero(skb, sizeof(*cmd));
155         cmd->mode = nca->bytes[3];                157         cmd->mode = nca->bytes[3];
156         ncsi_cmd_build_header(&cmd->cmd.common    158         ncsi_cmd_build_header(&cmd->cmd.common, nca);
157                                                   159 
158         return 0;                                 160         return 0;
159 }                                                 161 }
160                                                   162 
161 static int ncsi_cmd_handler_sma(struct sk_buff    163 static int ncsi_cmd_handler_sma(struct sk_buff *skb,
162                                 struct ncsi_cm    164                                 struct ncsi_cmd_arg *nca)
163 {                                                 165 {
164         struct ncsi_cmd_sma_pkt *cmd;             166         struct ncsi_cmd_sma_pkt *cmd;
165         int i;                                    167         int i;
166                                                   168 
167         cmd = skb_put_zero(skb, sizeof(*cmd));    169         cmd = skb_put_zero(skb, sizeof(*cmd));
168         for (i = 0; i < 6; i++)                   170         for (i = 0; i < 6; i++)
169                 cmd->mac[i] = nca->bytes[i];      171                 cmd->mac[i] = nca->bytes[i];
170         cmd->index = nca->bytes[6];               172         cmd->index = nca->bytes[6];
171         cmd->at_e = nca->bytes[7];                173         cmd->at_e = nca->bytes[7];
172         ncsi_cmd_build_header(&cmd->cmd.common    174         ncsi_cmd_build_header(&cmd->cmd.common, nca);
173                                                   175 
174         return 0;                                 176         return 0;
175 }                                                 177 }
176                                                   178 
177 static int ncsi_cmd_handler_ebf(struct sk_buff    179 static int ncsi_cmd_handler_ebf(struct sk_buff *skb,
178                                 struct ncsi_cm    180                                 struct ncsi_cmd_arg *nca)
179 {                                                 181 {
180         struct ncsi_cmd_ebf_pkt *cmd;             182         struct ncsi_cmd_ebf_pkt *cmd;
181                                                   183 
182         cmd = skb_put_zero(skb, sizeof(*cmd));    184         cmd = skb_put_zero(skb, sizeof(*cmd));
183         cmd->mode = htonl(nca->dwords[0]);        185         cmd->mode = htonl(nca->dwords[0]);
184         ncsi_cmd_build_header(&cmd->cmd.common    186         ncsi_cmd_build_header(&cmd->cmd.common, nca);
185                                                   187 
186         return 0;                                 188         return 0;
187 }                                                 189 }
188                                                   190 
189 static int ncsi_cmd_handler_egmf(struct sk_buf    191 static int ncsi_cmd_handler_egmf(struct sk_buff *skb,
190                                  struct ncsi_c    192                                  struct ncsi_cmd_arg *nca)
191 {                                                 193 {
192         struct ncsi_cmd_egmf_pkt *cmd;            194         struct ncsi_cmd_egmf_pkt *cmd;
193                                                   195 
194         cmd = skb_put_zero(skb, sizeof(*cmd));    196         cmd = skb_put_zero(skb, sizeof(*cmd));
195         cmd->mode = htonl(nca->dwords[0]);        197         cmd->mode = htonl(nca->dwords[0]);
196         ncsi_cmd_build_header(&cmd->cmd.common    198         ncsi_cmd_build_header(&cmd->cmd.common, nca);
197                                                   199 
198         return 0;                                 200         return 0;
199 }                                                 201 }
200                                                   202 
201 static int ncsi_cmd_handler_snfc(struct sk_buf    203 static int ncsi_cmd_handler_snfc(struct sk_buff *skb,
202                                  struct ncsi_c    204                                  struct ncsi_cmd_arg *nca)
203 {                                                 205 {
204         struct ncsi_cmd_snfc_pkt *cmd;            206         struct ncsi_cmd_snfc_pkt *cmd;
205                                                   207 
206         cmd = skb_put_zero(skb, sizeof(*cmd));    208         cmd = skb_put_zero(skb, sizeof(*cmd));
207         cmd->mode = nca->bytes[0];                209         cmd->mode = nca->bytes[0];
208         ncsi_cmd_build_header(&cmd->cmd.common    210         ncsi_cmd_build_header(&cmd->cmd.common, nca);
209                                                   211 
210         return 0;                                 212         return 0;
211 }                                                 213 }
212                                                   214 
213 static int ncsi_cmd_handler_oem(struct sk_buff    215 static int ncsi_cmd_handler_oem(struct sk_buff *skb,
214                                 struct ncsi_cm    216                                 struct ncsi_cmd_arg *nca)
215 {                                                 217 {
216         struct ncsi_cmd_oem_pkt *cmd;             218         struct ncsi_cmd_oem_pkt *cmd;
217         unsigned int len;                         219         unsigned int len;
218         int payload;                           << 
219         /* NC-SI spec DSP_0222_1.2.0, section  << 
220          * requires payload to be padded with  << 
221          * 32-bit boundary before the checksum << 
222          * Ensure the padding bytes are accoun << 
223          * skb allocation                      << 
224          */                                    << 
225                                                   220 
226         payload = ALIGN(nca->payload, 4);      << 
227         len = sizeof(struct ncsi_cmd_pkt_hdr)     221         len = sizeof(struct ncsi_cmd_pkt_hdr) + 4;
228         len += max(payload, padding_bytes);    !! 222         if (nca->payload < 26)
                                                   >> 223                 len += 26;
                                                   >> 224         else
                                                   >> 225                 len += nca->payload;
229                                                   226 
230         cmd = skb_put_zero(skb, len);             227         cmd = skb_put_zero(skb, len);
231         unsafe_memcpy(&cmd->mfr_id, nca->data, !! 228         memcpy(&cmd->mfr_id, nca->data, nca->payload);
232                       /* skb allocated with en << 
233         ncsi_cmd_build_header(&cmd->cmd.common    229         ncsi_cmd_build_header(&cmd->cmd.common, nca);
234                                                   230 
235         return 0;                                 231         return 0;
236 }                                                 232 }
237                                                   233 
238 static struct ncsi_cmd_handler {                  234 static struct ncsi_cmd_handler {
239         unsigned char type;                       235         unsigned char type;
240         int           payload;                    236         int           payload;
241         int           (*handler)(struct sk_buf    237         int           (*handler)(struct sk_buff *skb,
242                                  struct ncsi_c    238                                  struct ncsi_cmd_arg *nca);
243 } ncsi_cmd_handlers[] = {                         239 } ncsi_cmd_handlers[] = {
244         { NCSI_PKT_CMD_CIS,    0, ncsi_cmd_han    240         { NCSI_PKT_CMD_CIS,    0, ncsi_cmd_handler_default },
245         { NCSI_PKT_CMD_SP,     4, ncsi_cmd_han    241         { NCSI_PKT_CMD_SP,     4, ncsi_cmd_handler_sp      },
246         { NCSI_PKT_CMD_DP,     0, ncsi_cmd_han    242         { NCSI_PKT_CMD_DP,     0, ncsi_cmd_handler_default },
247         { NCSI_PKT_CMD_EC,     0, ncsi_cmd_han    243         { NCSI_PKT_CMD_EC,     0, ncsi_cmd_handler_default },
248         { NCSI_PKT_CMD_DC,     4, ncsi_cmd_han    244         { NCSI_PKT_CMD_DC,     4, ncsi_cmd_handler_dc      },
249         { NCSI_PKT_CMD_RC,     4, ncsi_cmd_han    245         { NCSI_PKT_CMD_RC,     4, ncsi_cmd_handler_rc      },
250         { NCSI_PKT_CMD_ECNT,   0, ncsi_cmd_han    246         { NCSI_PKT_CMD_ECNT,   0, ncsi_cmd_handler_default },
251         { NCSI_PKT_CMD_DCNT,   0, ncsi_cmd_han    247         { NCSI_PKT_CMD_DCNT,   0, ncsi_cmd_handler_default },
252         { NCSI_PKT_CMD_AE,     8, ncsi_cmd_han    248         { NCSI_PKT_CMD_AE,     8, ncsi_cmd_handler_ae      },
253         { NCSI_PKT_CMD_SL,     8, ncsi_cmd_han    249         { NCSI_PKT_CMD_SL,     8, ncsi_cmd_handler_sl      },
254         { NCSI_PKT_CMD_GLS,    0, ncsi_cmd_han    250         { NCSI_PKT_CMD_GLS,    0, ncsi_cmd_handler_default },
255         { NCSI_PKT_CMD_SVF,    8, ncsi_cmd_han    251         { NCSI_PKT_CMD_SVF,    8, ncsi_cmd_handler_svf     },
256         { NCSI_PKT_CMD_EV,     4, ncsi_cmd_han    252         { NCSI_PKT_CMD_EV,     4, ncsi_cmd_handler_ev      },
257         { NCSI_PKT_CMD_DV,     0, ncsi_cmd_han    253         { NCSI_PKT_CMD_DV,     0, ncsi_cmd_handler_default },
258         { NCSI_PKT_CMD_SMA,    8, ncsi_cmd_han    254         { NCSI_PKT_CMD_SMA,    8, ncsi_cmd_handler_sma     },
259         { NCSI_PKT_CMD_EBF,    4, ncsi_cmd_han    255         { NCSI_PKT_CMD_EBF,    4, ncsi_cmd_handler_ebf     },
260         { NCSI_PKT_CMD_DBF,    0, ncsi_cmd_han    256         { NCSI_PKT_CMD_DBF,    0, ncsi_cmd_handler_default },
261         { NCSI_PKT_CMD_EGMF,   4, ncsi_cmd_han    257         { NCSI_PKT_CMD_EGMF,   4, ncsi_cmd_handler_egmf    },
262         { NCSI_PKT_CMD_DGMF,   0, ncsi_cmd_han    258         { NCSI_PKT_CMD_DGMF,   0, ncsi_cmd_handler_default },
263         { NCSI_PKT_CMD_SNFC,   4, ncsi_cmd_han    259         { NCSI_PKT_CMD_SNFC,   4, ncsi_cmd_handler_snfc    },
264         { NCSI_PKT_CMD_GVI,    0, ncsi_cmd_han    260         { NCSI_PKT_CMD_GVI,    0, ncsi_cmd_handler_default },
265         { NCSI_PKT_CMD_GC,     0, ncsi_cmd_han    261         { NCSI_PKT_CMD_GC,     0, ncsi_cmd_handler_default },
266         { NCSI_PKT_CMD_GP,     0, ncsi_cmd_han    262         { NCSI_PKT_CMD_GP,     0, ncsi_cmd_handler_default },
267         { NCSI_PKT_CMD_GCPS,   0, ncsi_cmd_han    263         { NCSI_PKT_CMD_GCPS,   0, ncsi_cmd_handler_default },
268         { NCSI_PKT_CMD_GNS,    0, ncsi_cmd_han    264         { NCSI_PKT_CMD_GNS,    0, ncsi_cmd_handler_default },
269         { NCSI_PKT_CMD_GNPTS,  0, ncsi_cmd_han    265         { NCSI_PKT_CMD_GNPTS,  0, ncsi_cmd_handler_default },
270         { NCSI_PKT_CMD_GPS,    0, ncsi_cmd_han    266         { NCSI_PKT_CMD_GPS,    0, ncsi_cmd_handler_default },
271         { NCSI_PKT_CMD_OEM,   -1, ncsi_cmd_han    267         { NCSI_PKT_CMD_OEM,   -1, ncsi_cmd_handler_oem     },
272         { NCSI_PKT_CMD_PLDM,   0, NULL            268         { NCSI_PKT_CMD_PLDM,   0, NULL                     },
273         { NCSI_PKT_CMD_GPUUID, 0, ncsi_cmd_han !! 269         { NCSI_PKT_CMD_GPUUID, 0, ncsi_cmd_handler_default }
274         { NCSI_PKT_CMD_GMCMA,  0, ncsi_cmd_han << 
275 };                                                270 };
276                                                   271 
277 static struct ncsi_request *ncsi_alloc_command    272 static struct ncsi_request *ncsi_alloc_command(struct ncsi_cmd_arg *nca)
278 {                                                 273 {
279         struct ncsi_dev_priv *ndp = nca->ndp;     274         struct ncsi_dev_priv *ndp = nca->ndp;
280         struct ncsi_dev *nd = &ndp->ndev;         275         struct ncsi_dev *nd = &ndp->ndev;
281         struct net_device *dev = nd->dev;         276         struct net_device *dev = nd->dev;
282         int hlen = LL_RESERVED_SPACE(dev);        277         int hlen = LL_RESERVED_SPACE(dev);
283         int tlen = dev->needed_tailroom;          278         int tlen = dev->needed_tailroom;
284         int payload;                           << 
285         int len = hlen + tlen;                    279         int len = hlen + tlen;
286         struct sk_buff *skb;                      280         struct sk_buff *skb;
287         struct ncsi_request *nr;                  281         struct ncsi_request *nr;
288                                                   282 
289         nr = ncsi_alloc_request(ndp, nca->req_    283         nr = ncsi_alloc_request(ndp, nca->req_flags);
290         if (!nr)                                  284         if (!nr)
291                 return NULL;                      285                 return NULL;
292                                                   286 
293         /* NCSI command packet has 16-bytes he    287         /* NCSI command packet has 16-bytes header, payload, 4 bytes checksum.
294          * Payload needs padding so that the c << 
295          * aligned to 32-bit boundary.         << 
296          * The packet needs padding if its pay    288          * The packet needs padding if its payload is less than 26 bytes to
297          * meet 64 bytes minimal ethernet fram    289          * meet 64 bytes minimal ethernet frame length.
298          */                                       290          */
299         len += sizeof(struct ncsi_cmd_pkt_hdr)    291         len += sizeof(struct ncsi_cmd_pkt_hdr) + 4;
300         payload = ALIGN(nca->payload, 4);      !! 292         if (nca->payload < 26)
301         len += max(payload, padding_bytes);    !! 293                 len += 26;
                                                   >> 294         else
                                                   >> 295                 len += nca->payload;
302                                                   296 
303         /* Allocate skb */                        297         /* Allocate skb */
304         skb = alloc_skb(len, GFP_ATOMIC);         298         skb = alloc_skb(len, GFP_ATOMIC);
305         if (!skb) {                               299         if (!skb) {
306                 ncsi_free_request(nr);            300                 ncsi_free_request(nr);
307                 return NULL;                      301                 return NULL;
308         }                                         302         }
309                                                   303 
310         nr->cmd = skb;                            304         nr->cmd = skb;
311         skb_reserve(skb, hlen);                   305         skb_reserve(skb, hlen);
312         skb_reset_network_header(skb);            306         skb_reset_network_header(skb);
313                                                   307 
314         skb->dev = dev;                           308         skb->dev = dev;
315         skb->protocol = htons(ETH_P_NCSI);        309         skb->protocol = htons(ETH_P_NCSI);
316                                                   310 
317         return nr;                                311         return nr;
318 }                                                 312 }
319                                                   313 
320 int ncsi_xmit_cmd(struct ncsi_cmd_arg *nca)       314 int ncsi_xmit_cmd(struct ncsi_cmd_arg *nca)
321 {                                                 315 {
322         struct ncsi_cmd_handler *nch = NULL;   << 
323         struct ncsi_request *nr;                  316         struct ncsi_request *nr;
324         unsigned char type;                    << 
325         struct ethhdr *eh;                        317         struct ethhdr *eh;
                                                   >> 318         struct ncsi_cmd_handler *nch = NULL;
326         int i, ret;                               319         int i, ret;
327                                                   320 
328         /* Use OEM generic handler for Netlink << 
329         if (nca->req_flags == NCSI_REQ_FLAG_NE << 
330                 type = NCSI_PKT_CMD_OEM;       << 
331         else                                   << 
332                 type = nca->type;              << 
333                                                << 
334         /* Search for the handler */              321         /* Search for the handler */
335         for (i = 0; i < ARRAY_SIZE(ncsi_cmd_ha    322         for (i = 0; i < ARRAY_SIZE(ncsi_cmd_handlers); i++) {
336                 if (ncsi_cmd_handlers[i].type  !! 323                 if (ncsi_cmd_handlers[i].type == nca->type) {
337                         if (ncsi_cmd_handlers[    324                         if (ncsi_cmd_handlers[i].handler)
338                                 nch = &ncsi_cm    325                                 nch = &ncsi_cmd_handlers[i];
339                         else                      326                         else
340                                 nch = NULL;       327                                 nch = NULL;
341                                                   328 
342                         break;                    329                         break;
343                 }                                 330                 }
344         }                                         331         }
345                                                   332 
346         if (!nch) {                               333         if (!nch) {
347                 netdev_err(nca->ndp->ndev.dev,    334                 netdev_err(nca->ndp->ndev.dev,
348                            "Cannot send packet    335                            "Cannot send packet with type 0x%02x\n", nca->type);
349                 return -ENOENT;                   336                 return -ENOENT;
350         }                                         337         }
351                                                   338 
352         /* Get packet payload length and alloc    339         /* Get packet payload length and allocate the request
353          * It is expected that if length set a    340          * It is expected that if length set as negative in
354          * handler structure means caller is i    341          * handler structure means caller is initializing it
355          * and setting length in nca before ca    342          * and setting length in nca before calling xmit function
356          */                                       343          */
357         if (nch->payload >= 0)                    344         if (nch->payload >= 0)
358                 nca->payload = nch->payload;      345                 nca->payload = nch->payload;
359         nr = ncsi_alloc_command(nca);             346         nr = ncsi_alloc_command(nca);
360         if (!nr)                                  347         if (!nr)
361                 return -ENOMEM;                   348                 return -ENOMEM;
362                                                   349 
363         /* track netlink information */           350         /* track netlink information */
364         if (nca->req_flags == NCSI_REQ_FLAG_NE    351         if (nca->req_flags == NCSI_REQ_FLAG_NETLINK_DRIVEN) {
365                 nr->snd_seq = nca->info->snd_s    352                 nr->snd_seq = nca->info->snd_seq;
366                 nr->snd_portid = nca->info->sn    353                 nr->snd_portid = nca->info->snd_portid;
367                 nr->nlhdr = *nca->info->nlhdr;    354                 nr->nlhdr = *nca->info->nlhdr;
368         }                                         355         }
369                                                   356 
370         /* Prepare the packet */                  357         /* Prepare the packet */
371         nca->id = nr->id;                         358         nca->id = nr->id;
372         ret = nch->handler(nr->cmd, nca);         359         ret = nch->handler(nr->cmd, nca);
373         if (ret) {                                360         if (ret) {
374                 ncsi_free_request(nr);            361                 ncsi_free_request(nr);
375                 return ret;                       362                 return ret;
376         }                                         363         }
377                                                   364 
378         /* Fill the ethernet header */            365         /* Fill the ethernet header */
379         eh = skb_push(nr->cmd, sizeof(*eh));      366         eh = skb_push(nr->cmd, sizeof(*eh));
380         eh->h_proto = htons(ETH_P_NCSI);          367         eh->h_proto = htons(ETH_P_NCSI);
381         eth_broadcast_addr(eh->h_dest);           368         eth_broadcast_addr(eh->h_dest);
382                                                !! 369         eth_broadcast_addr(eh->h_source);
383         /* If mac address received from device << 
384          * source address as unicast address e << 
385          * address as source address           << 
386          */                                    << 
387         if (nca->ndp->gma_flag == 1)           << 
388                 memcpy(eh->h_source, nca->ndp- << 
389         else                                   << 
390                 eth_broadcast_addr(eh->h_sourc << 
391                                                   370 
392         /* Start the timer for the request tha    371         /* Start the timer for the request that might not have
393          * corresponding response. Given NCSI     372          * corresponding response. Given NCSI is an internal
394          * connection a 1 second delay should     373          * connection a 1 second delay should be sufficient.
395          */                                       374          */
396         nr->enabled = true;                       375         nr->enabled = true;
397         mod_timer(&nr->timer, jiffies + 1 * HZ    376         mod_timer(&nr->timer, jiffies + 1 * HZ);
398                                                   377 
399         /* Send NCSI packet */                    378         /* Send NCSI packet */
400         skb_get(nr->cmd);                         379         skb_get(nr->cmd);
401         ret = dev_queue_xmit(nr->cmd);            380         ret = dev_queue_xmit(nr->cmd);
402         if (ret < 0) {                            381         if (ret < 0) {
403                 ncsi_free_request(nr);            382                 ncsi_free_request(nr);
404                 return ret;                       383                 return ret;
405         }                                         384         }
406                                                   385 
407         return 0;                                 386         return 0;
408 }                                                 387 }
409                                                   388 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php