3535 * Atul Gupta (atul.gupta@chelsio.com)
3636 */
3737
38- #define pr_fmt (fmt ) "chcr: " fmt
38+ #define pr_fmt (fmt ) "ch_ipsec: " fmt
3939
4040#include <linux/kernel.h>
4141#include <linux/module.h>
7272static LIST_HEAD (uld_ctx_list );
7373static DEFINE_MUTEX (dev_mutex );
7474
75- static int chcr_xfrm_add_state (struct xfrm_state * x );
76- static void chcr_xfrm_del_state (struct xfrm_state * x );
77- static void chcr_xfrm_free_state (struct xfrm_state * x );
78- static bool chcr_ipsec_offload_ok (struct sk_buff * skb , struct xfrm_state * x );
79- static void chcr_advance_esn_state (struct xfrm_state * x );
75+ static bool ch_ipsec_offload_ok (struct sk_buff * skb , struct xfrm_state * x );
8076static int ch_ipsec_uld_state_change (void * handle , enum cxgb4_state new_state );
77+ static int ch_ipsec_xmit (struct sk_buff * skb , struct net_device * dev );
8178static void * ch_ipsec_uld_add (const struct cxgb4_lld_info * infop );
82-
83- static const struct xfrmdev_ops chcr_xfrmdev_ops = {
84- .xdo_dev_state_add = chcr_xfrm_add_state ,
85- .xdo_dev_state_delete = chcr_xfrm_del_state ,
86- .xdo_dev_state_free = chcr_xfrm_free_state ,
87- .xdo_dev_offload_ok = chcr_ipsec_offload_ok ,
88- .xdo_dev_state_advance_esn = chcr_advance_esn_state ,
79+ static void ch_ipsec_advance_esn_state (struct xfrm_state * x );
80+ static void ch_ipsec_xfrm_free_state (struct xfrm_state * x );
81+ static void ch_ipsec_xfrm_del_state (struct xfrm_state * x );
82+ static int ch_ipsec_xfrm_add_state (struct xfrm_state * x );
83+
84+ static const struct xfrmdev_ops ch_ipsec_xfrmdev_ops = {
85+ .xdo_dev_state_add = ch_ipsec_xfrm_add_state ,
86+ .xdo_dev_state_delete = ch_ipsec_xfrm_del_state ,
87+ .xdo_dev_state_free = ch_ipsec_xfrm_free_state ,
88+ .xdo_dev_offload_ok = ch_ipsec_offload_ok ,
89+ .xdo_dev_state_advance_esn = ch_ipsec_advance_esn_state ,
8990};
9091
9192static struct cxgb4_uld_info ch_ipsec_uld_info = {
@@ -95,8 +96,8 @@ static struct cxgb4_uld_info ch_ipsec_uld_info = {
9596 .rxq_size = 1024 ,
9697 .add = ch_ipsec_uld_add ,
9798 .state_change = ch_ipsec_uld_state_change ,
98- .tx_handler = chcr_ipsec_xmit ,
99- .xfrmdev_ops = & chcr_xfrmdev_ops ,
99+ .tx_handler = ch_ipsec_xmit ,
100+ .xfrmdev_ops = & ch_ipsec_xfrmdev_ops ,
100101};
101102
102103static void * ch_ipsec_uld_add (const struct cxgb4_lld_info * infop )
@@ -119,7 +120,7 @@ static int ch_ipsec_uld_state_change(void *handle, enum cxgb4_state new_state)
119120{
120121 struct ipsec_uld_ctx * u_ctx = handle ;
121122
122- pr_info ("new_state %u\n" , new_state );
123+ pr_debug ("new_state %u\n" , new_state );
123124 switch (new_state ) {
124125 case CXGB4_STATE_UP :
125126 pr_info ("%s: Up\n" , pci_name (u_ctx -> lldi .pdev ));
@@ -140,8 +141,8 @@ static int ch_ipsec_uld_state_change(void *handle, enum cxgb4_state new_state)
140141 return 0 ;
141142}
142143
143- static inline int chcr_ipsec_setauthsize (struct xfrm_state * x ,
144- struct ipsec_sa_entry * sa_entry )
144+ static int ch_ipsec_setauthsize (struct xfrm_state * x ,
145+ struct ipsec_sa_entry * sa_entry )
145146{
146147 int hmac_ctrl ;
147148 int authsize = x -> aead -> alg_icv_len / 8 ;
@@ -164,8 +165,8 @@ static inline int chcr_ipsec_setauthsize(struct xfrm_state *x,
164165 return hmac_ctrl ;
165166}
166167
167- static inline int chcr_ipsec_setkey (struct xfrm_state * x ,
168- struct ipsec_sa_entry * sa_entry )
168+ static int ch_ipsec_setkey (struct xfrm_state * x ,
169+ struct ipsec_sa_entry * sa_entry )
169170{
170171 int keylen = (x -> aead -> alg_key_len + 7 ) / 8 ;
171172 unsigned char * key = x -> aead -> alg_key ;
@@ -223,65 +224,65 @@ static inline int chcr_ipsec_setkey(struct xfrm_state *x,
223224}
224225
225226/*
226- * chcr_xfrm_add_state
227+ * ch_ipsec_xfrm_add_state
227228 * returns 0 on success, negative error if failed to send message to FPGA
228229 * positive error if FPGA returned a bad response
229230 */
230- static int chcr_xfrm_add_state (struct xfrm_state * x )
231+ static int ch_ipsec_xfrm_add_state (struct xfrm_state * x )
231232{
232233 struct ipsec_sa_entry * sa_entry ;
233234 int res = 0 ;
234235
235236 if (x -> props .aalgo != SADB_AALG_NONE ) {
236- pr_debug ("CHCR: Cannot offload authenticated xfrm states\n" );
237+ pr_debug ("Cannot offload authenticated xfrm states\n" );
237238 return - EINVAL ;
238239 }
239240 if (x -> props .calgo != SADB_X_CALG_NONE ) {
240- pr_debug ("CHCR: Cannot offload compressed xfrm states\n" );
241+ pr_debug ("Cannot offload compressed xfrm states\n" );
241242 return - EINVAL ;
242243 }
243244 if (x -> props .family != AF_INET &&
244245 x -> props .family != AF_INET6 ) {
245- pr_debug ("CHCR: Only IPv4/6 xfrm state offloaded\n" );
246+ pr_debug ("Only IPv4/6 xfrm state offloaded\n" );
246247 return - EINVAL ;
247248 }
248249 if (x -> props .mode != XFRM_MODE_TRANSPORT &&
249250 x -> props .mode != XFRM_MODE_TUNNEL ) {
250- pr_debug ("CHCR: Only transport and tunnel xfrm offload\n" );
251+ pr_debug ("Only transport and tunnel xfrm offload\n" );
251252 return - EINVAL ;
252253 }
253254 if (x -> id .proto != IPPROTO_ESP ) {
254- pr_debug ("CHCR: Only ESP xfrm state offloaded\n" );
255+ pr_debug ("Only ESP xfrm state offloaded\n" );
255256 return - EINVAL ;
256257 }
257258 if (x -> encap ) {
258- pr_debug ("CHCR: Encapsulated xfrm state not offloaded\n" );
259+ pr_debug ("Encapsulated xfrm state not offloaded\n" );
259260 return - EINVAL ;
260261 }
261262 if (!x -> aead ) {
262- pr_debug ("CHCR: Cannot offload xfrm states without aead\n" );
263+ pr_debug ("Cannot offload xfrm states without aead\n" );
263264 return - EINVAL ;
264265 }
265266 if (x -> aead -> alg_icv_len != 128 &&
266267 x -> aead -> alg_icv_len != 96 ) {
267- pr_debug ("CHCR: Cannot offload xfrm states with AEAD ICV length other than 96b & 128b\n" );
268+ pr_debug ("Cannot offload xfrm states with AEAD ICV length other than 96b & 128b\n" );
268269 return - EINVAL ;
269270 }
270271 if ((x -> aead -> alg_key_len != 128 + 32 ) &&
271272 (x -> aead -> alg_key_len != 256 + 32 )) {
272- pr_debug ("CHCR: Cannot offload xfrm states with AEAD key length other than 128/256 bit\n" );
273+ pr_debug ("cannot offload xfrm states with AEAD key length other than 128/256 bit\n" );
273274 return - EINVAL ;
274275 }
275276 if (x -> tfcpad ) {
276- pr_debug ("CHCR: Cannot offload xfrm states with tfc padding\n" );
277+ pr_debug ("Cannot offload xfrm states with tfc padding\n" );
277278 return - EINVAL ;
278279 }
279280 if (!x -> geniv ) {
280- pr_debug ("CHCR: Cannot offload xfrm states without geniv\n" );
281+ pr_debug ("Cannot offload xfrm states without geniv\n" );
281282 return - EINVAL ;
282283 }
283284 if (strcmp (x -> geniv , "seqiv" )) {
284- pr_debug ("CHCR: Cannot offload xfrm states with geniv other than seqiv\n" );
285+ pr_debug ("Cannot offload xfrm states with geniv other than seqiv\n" );
285286 return - EINVAL ;
286287 }
287288
@@ -291,24 +292,24 @@ static int chcr_xfrm_add_state(struct xfrm_state *x)
291292 goto out ;
292293 }
293294
294- sa_entry -> hmac_ctrl = chcr_ipsec_setauthsize (x , sa_entry );
295+ sa_entry -> hmac_ctrl = ch_ipsec_setauthsize (x , sa_entry );
295296 if (x -> props .flags & XFRM_STATE_ESN )
296297 sa_entry -> esn = 1 ;
297- chcr_ipsec_setkey (x , sa_entry );
298+ ch_ipsec_setkey (x , sa_entry );
298299 x -> xso .offload_handle = (unsigned long )sa_entry ;
299300 try_module_get (THIS_MODULE );
300301out :
301302 return res ;
302303}
303304
304- static void chcr_xfrm_del_state (struct xfrm_state * x )
305+ static void ch_ipsec_xfrm_del_state (struct xfrm_state * x )
305306{
306307 /* do nothing */
307308 if (!x -> xso .offload_handle )
308309 return ;
309310}
310311
311- static void chcr_xfrm_free_state (struct xfrm_state * x )
312+ static void ch_ipsec_xfrm_free_state (struct xfrm_state * x )
312313{
313314 struct ipsec_sa_entry * sa_entry ;
314315
@@ -320,7 +321,7 @@ static void chcr_xfrm_free_state(struct xfrm_state *x)
320321 module_put (THIS_MODULE );
321322}
322323
323- static bool chcr_ipsec_offload_ok (struct sk_buff * skb , struct xfrm_state * x )
324+ static bool ch_ipsec_offload_ok (struct sk_buff * skb , struct xfrm_state * x )
324325{
325326 if (x -> props .family == AF_INET ) {
326327 /* Offload with IP options is not supported yet */
@@ -334,15 +335,15 @@ static bool chcr_ipsec_offload_ok(struct sk_buff *skb, struct xfrm_state *x)
334335 return true;
335336}
336337
337- static void chcr_advance_esn_state (struct xfrm_state * x )
338+ static void ch_ipsec_advance_esn_state (struct xfrm_state * x )
338339{
339340 /* do nothing */
340341 if (!x -> xso .offload_handle )
341342 return ;
342343}
343344
344- static inline int is_eth_imm (const struct sk_buff * skb ,
345- struct ipsec_sa_entry * sa_entry )
345+ static int is_eth_imm (const struct sk_buff * skb ,
346+ struct ipsec_sa_entry * sa_entry )
346347{
347348 unsigned int kctx_len ;
348349 int hdrlen ;
@@ -360,9 +361,9 @@ static inline int is_eth_imm(const struct sk_buff *skb,
360361 return 0 ;
361362}
362363
363- static inline unsigned int calc_tx_sec_flits (const struct sk_buff * skb ,
364- struct ipsec_sa_entry * sa_entry ,
365- bool * immediate )
364+ static unsigned int calc_tx_sec_flits (const struct sk_buff * skb ,
365+ struct ipsec_sa_entry * sa_entry ,
366+ bool * immediate )
366367{
367368 unsigned int kctx_len ;
368369 unsigned int flits ;
@@ -403,7 +404,7 @@ static inline unsigned int calc_tx_sec_flits(const struct sk_buff *skb,
403404 return flits ;
404405}
405406
406- inline void * copy_esn_pktxt (struct sk_buff * skb ,
407+ static void * copy_esn_pktxt (struct sk_buff * skb ,
407408 struct net_device * dev ,
408409 void * pos ,
409410 struct ipsec_sa_entry * sa_entry )
@@ -457,7 +458,7 @@ inline void *copy_esn_pktxt(struct sk_buff *skb,
457458 return pos ;
458459}
459460
460- inline void * copy_cpltx_pktxt (struct sk_buff * skb ,
461+ static void * copy_cpltx_pktxt (struct sk_buff * skb ,
461462 struct net_device * dev ,
462463 void * pos ,
463464 struct ipsec_sa_entry * sa_entry )
@@ -501,10 +502,10 @@ inline void *copy_cpltx_pktxt(struct sk_buff *skb,
501502 return pos ;
502503}
503504
504- inline void * copy_key_cpltx_pktxt (struct sk_buff * skb ,
505- struct net_device * dev ,
506- void * pos ,
507- struct ipsec_sa_entry * sa_entry )
505+ static void * copy_key_cpltx_pktxt (struct sk_buff * skb ,
506+ struct net_device * dev ,
507+ void * pos ,
508+ struct ipsec_sa_entry * sa_entry )
508509{
509510 struct _key_ctx * key_ctx ;
510511 int left , eoq , key_len ;
@@ -549,11 +550,11 @@ inline void *copy_key_cpltx_pktxt(struct sk_buff *skb,
549550 return pos ;
550551}
551552
552- inline void * chcr_crypto_wreq (struct sk_buff * skb ,
553- struct net_device * dev ,
554- void * pos ,
555- int credits ,
556- struct ipsec_sa_entry * sa_entry )
553+ static void * ch_ipsec_crypto_wreq (struct sk_buff * skb ,
554+ struct net_device * dev ,
555+ void * pos ,
556+ int credits ,
557+ struct ipsec_sa_entry * sa_entry )
557558{
558559 struct port_info * pi = netdev_priv (dev );
559560 struct adapter * adap = pi -> adapter ;
@@ -674,13 +675,13 @@ inline void *chcr_crypto_wreq(struct sk_buff *skb,
674675 * Returns the number of Tx descriptors needed for the supplied number
675676 * of flits.
676677 */
677- static inline unsigned int flits_to_desc (unsigned int n )
678+ static unsigned int flits_to_desc (unsigned int n )
678679{
679680 WARN_ON (n > SGE_MAX_WR_LEN / 8 );
680681 return DIV_ROUND_UP (n , 8 );
681682}
682683
683- static inline unsigned int txq_avail (const struct sge_txq * q )
684+ static unsigned int txq_avail (const struct sge_txq * q )
684685{
685686 return q -> size - 1 - q -> in_use ;
686687}
@@ -691,7 +692,7 @@ static void eth_txq_stop(struct sge_eth_txq *q)
691692 q -> q .stops ++ ;
692693}
693694
694- static inline void txq_advance (struct sge_txq * q , unsigned int n )
695+ static void txq_advance (struct sge_txq * q , unsigned int n )
695696{
696697 q -> in_use += n ;
697698 q -> pidx += n ;
@@ -700,9 +701,9 @@ static inline void txq_advance(struct sge_txq *q, unsigned int n)
700701}
701702
702703/*
703- * chcr_ipsec_xmit called from ULD Tx handler
704+ * ch_ipsec_xmit called from ULD Tx handler
704705 */
705- int chcr_ipsec_xmit (struct sk_buff * skb , struct net_device * dev )
706+ int ch_ipsec_xmit (struct sk_buff * skb , struct net_device * dev )
706707{
707708 struct xfrm_state * x = xfrm_input_state (skb );
708709 unsigned int last_desc , ndesc , flits = 0 ;
@@ -763,8 +764,8 @@ out_free: dev_kfree_skb_any(skb);
763764 before = (u64 * )pos ;
764765 end = (u64 * )pos + flits ;
765766 /* Setup IPSec CPL */
766- pos = (void * )chcr_crypto_wreq (skb , dev , (void * )pos ,
767- credits , sa_entry );
767+ pos = (void * )ch_ipsec_crypto_wreq (skb , dev , (void * )pos ,
768+ credits , sa_entry );
768769 if (before > (u64 * )pos ) {
769770 left = (u8 * )end - (u8 * )q -> q .stat ;
770771 end = (void * )q -> q .desc + left ;
@@ -791,14 +792,14 @@ out_free: dev_kfree_skb_any(skb);
791792 return NETDEV_TX_OK ;
792793}
793794
794- static int __init chcr_ipsec_init (void )
795+ static int __init ch_ipsec_init (void )
795796{
796797 cxgb4_register_uld (CXGB4_ULD_IPSEC , & ch_ipsec_uld_info );
797798
798799 return 0 ;
799800}
800801
801- static void __exit chcr_ipsec_exit (void )
802+ static void __exit ch_ipsec_exit (void )
802803{
803804 struct ipsec_uld_ctx * u_ctx , * tmp ;
804805 struct adapter * adap ;
@@ -814,8 +815,8 @@ static void __exit chcr_ipsec_exit(void)
814815 cxgb4_unregister_uld (CXGB4_ULD_IPSEC );
815816}
816817
817- module_init (chcr_ipsec_init );
818- module_exit (chcr_ipsec_exit );
818+ module_init (ch_ipsec_init );
819+ module_exit (ch_ipsec_exit );
819820
820821MODULE_DESCRIPTION ("Crypto IPSEC for Chelsio Terminator cards." );
821822MODULE_LICENSE ("GPL" );
0 commit comments