Emulex Logo
OneCoreā„¢ Storage SDK Release 11.2
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ocs_lnx.c
Go to the documentation of this file.
1 /**
2  * Copyright (C) 2013-2015 Emulex
3  * All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License version 2
7  * as published by the Free Software Foundation. The full GNU General
8  * Public License can be found at <http://www.gnu.org/licenses/>.
9  *
10  * Written by: Chris Moore (chris.moore@emulex.com)
11  *
12  * Emulex
13  * 3333 Susan Street
14  * Costa Mesa, CA 92626
15  */
16 
17 
18 #include "ocs.h"
19 #include "ocs_ini_template.h"
20 
21 /* Copyright notice */
22 static const char ocs_copyright[] = "Copyright © 2013 Emulex. All rights reserved";
23 
24 int logdest = 1;
25 int loglevel = 3;
26 
27 extern ocs_scsi_ini_template_t ocs_iscsi_ini_template;
28 
29 /**
30  * @brief driver load entry point
31  *
32  * Called when driver is loaded, device class DRV_NAME is created, and
33  * PCI devices are enumerated.
34  *
35  * @return returns 0 for success, a negative error code value for failure.
36  */
37 static int __init ocs_init(void)
38 {
39  int i;
40  int ocs_count = 0;
41  ocs_t *ocs;
42 
43  /* Initialize this back-end module */
45 
46  /* Enumerate OCS devices and call new device (this will register callbacks with base driver) */
47  for (i = 0; (ocs = ocs_get_instance(i)); i++) {
48  if (ocs_scsi_ini_new_device(ocs) == 0) {
49  ++ocs_count;
50  }
51  }
52 
53  if (ocs_count == 0) {
55  printk(KERN_INFO "No valid devices found, %s not loaded\n", DRV_NAME);
56  return -ENODEV;
57  }
58 
59  printk(KERN_INFO "%s loaded\n", DRV_NAME);
60 
61  return 0;
62 }
63 
64 /**
65  * @brief driver unload entry point
66  *
67  * Called when driver is unloaded. PCI devices are removed, and device class objects
68  * removed.
69  *
70  * @return none
71  */
72 static void __exit ocs_exit(void)
73 {
74  int i;
75  ocs_t *ocs;
76 
77  /* Enumerate OCS devices and call del device (this will delete callbacks with base driver) */
78  for (i = 0; (ocs = ocs_get_instance(i)); i++) {
80  }
82 
83  printk(KERN_INFO "%s unloaded\n", DRV_NAME);
84 }
85 
86 const char *ocs_display_name(void *os)
87 {
88  ocs_t *ocs = os;
89  ocs_assert(ocs, "[?]");
90 
91  return ocs->display_name;
92 
93 }
94 
95 static inline int get_current_tid(void)
96 {
97  /* Code should be the same as in sys_gettid() */
98 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
99  return current->pid;
100 #else
101  if (in_interrupt()) {
102  /*
103  * Unfortunately, task_pid_vnr() isn't IRQ-safe, so otherwise
104  * it can oops. ToDo.
105  */
106  return current->pid;
107  }
108  return task_pid_vnr(current);
109 #endif
110 }
111 
112 static const char *log_level_to_klog_level(int level)
113 {
114  switch (level) {
115  case LOG_CRIT:
116  return KERN_CRIT;
117  case LOG_ERR:
118  return KERN_ERR;
119  case LOG_WARN:
120  return KERN_WARNING;
121  case LOG_INFO:
122  case LOG_TEST:
123  case LOG_DEBUG:
124  return KERN_INFO;
125  default:
126  return "";
127  }
128 }
129 
130 void _ocs_log(void *os, const char *func_name, int line, int level, const char *fmt, ...)
131 {
132  va_list ap;
133  char buf[256];
134  char *p = buf;
135 
136  va_start(ap, fmt);
137 
138  if (logdest & 2) {
139  struct timeval tv;
140 
141  do_gettimeofday(&tv);
142 
143  p += snprintf(p, sizeof(buf) - (p - buf), "%10ld.%06ld: ", tv.tv_sec, tv.tv_usec);
144  }
145 
146  p += snprintf(p, sizeof(buf) - (p - buf), "[%d]: ", get_current_tid());
147 
148  p += snprintf(p, sizeof(buf) - (p - buf), "%s: ", DRV_NAME);
149  p += snprintf(p, sizeof(buf) - (p - buf), "%s:", func_name);
150  p += snprintf(p, sizeof(buf) - (p - buf), "%i:", line);
151  p += snprintf(p, sizeof(buf) - (p - buf), "%s:", (os != NULL) ? ocs_display_name(os) : "");
152  p += vsnprintf(p, sizeof(buf) - (p - buf), fmt, ap);
153 
154  va_end(ap);
155 
156  if (logdest & 1) {
157  printk("%s%s", log_level_to_klog_level(level), buf);
158  }
159 
160  if (logdest & 2) {
161  ocs_ramlog_printf(os, "%s", buf);
162  }
163 }
164 
165 void
166 _ocs_assert(const char *cond, const char *filename, int linenum)
167 {
168  const char *fn = strrchr(__FILE__, '/');
169 
170  ocs_log_err(NULL, "%s(%d) assertion (%s) failed\n", (fn ? fn + 1 : filename), linenum, cond);
171  ocs_print_stack();
173 }
176 
178 MODULE_LICENSE("GPL");
#define OCS_DDUMP_FLAGS_WQES
Definition: ocs_ddump.h:38
const char * ocs_display_name(void *os)
Definition: ocs_driver.c:385
ocs_t * ocs_get_instance(uint32_t index)
Returns a pointer to the ocs structure given the instance index.
Definition: ocs_driver.c:141
ocs_scsi_ini_template_t ocs_iscsi_ini_template
int32_t ocs_scsi_ini_driver_init(int32_t initiator)
Initialize initiator client.
static const char ocs_copyright[]
Definition: ocs_lnx.c:22
#define DRV_VERSION
Definition: ocs.h:45
int32_t ocs_ramlog_printf(void *os, const char *fmt,...)
Append formatted printf data to a ramlog buffer.
Definition: ocs_ramlog.c:179
int loglevel
Definition: ocs_lnx.c:25
MODULE_VERSION(DRV_VERSION)
void _ocs_assert(const char *cond, const char *filename, int linenum)
Definition: ocs_lnx.c:166
void _ocs_log(void *os, const char *func_name, int line, int level, const char *fmt,...)
Definition: ocs_lnx.c:130
void ocs_print_stack(void)
static int get_current_tid(void)
Definition: ocs_lnx.c:95
static void __exit ocs_exit(void)
driver unload entry point
Definition: ocs_lnx.c:72
int32_t ocs_scsi_ini_del_device(ocs_t *ocs)
Tears down initiator members of ocs structure.
#define DRV_NAME
Definition: ocs.h:44
int32_t ocs_save_ddump_all(uint32_t flags, uint32_t qentries, uint32_t alloc_flag)
Capture and save ddump for all OCS instances.
Definition: ocs_ddump.c:765
MODULE_LICENSE("GPL")
const char const char va_list ap
Definition: ocs_ramlog.h:54
module_exit(ocs_exit)
static const char * log_level_to_klog_level(int level)
Definition: ocs_lnx.c:112
int32_t ocs_scsi_ini_driver_exit(int32_t initiator)
initiator client exit
static int __init ocs_init(void)
driver load entry point
Definition: ocs_lnx.c:37
int32_t ocs_scsi_ini_new_device(ocs_t *ocs)
Initializes any initiator fields on the ocs structure.
#define ocs_assert(cond,...)
Definition: ocs_debug.h:163
int logdest
Definition: ocs_lnx.c:24
module_init(ocs_init)
const char const char * fmt
Definition: ocs_ddump.h:54
#define OCS_DDUMP_FLAGS_CQES
Definition: ocs_ddump.h:39
#define OCS_DDUMP_FLAGS_MQES
Definition: ocs_ddump.h:40