zfcp_aux.c 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773
  1. /*
  2. *
  3. * linux/drivers/s390/scsi/zfcp_aux.c
  4. *
  5. * FCP adapter driver for IBM eServer zSeries
  6. *
  7. * (C) Copyright IBM Corp. 2002, 2004
  8. *
  9. * Author(s): Martin Peschke <mpeschke@de.ibm.com>
  10. * Raimund Schroeder <raimund.schroeder@de.ibm.com>
  11. * Aron Zeh
  12. * Wolfgang Taphorn
  13. * Stefan Bader <stefan.bader@de.ibm.com>
  14. * Heiko Carstens <heiko.carstens@de.ibm.com>
  15. * Andreas Herrmann <aherrman@de.ibm.com>
  16. *
  17. * This program is free software; you can redistribute it and/or modify
  18. * it under the terms of the GNU General Public License as published by
  19. * the Free Software Foundation; either version 2, or (at your option)
  20. * any later version.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU General Public License
  28. * along with this program; if not, write to the Free Software
  29. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  30. */
  31. #define ZFCP_AUX_REVISION "$Revision: 1.145 $"
  32. #include "zfcp_ext.h"
  33. /* accumulated log level (module parameter) */
  34. static u32 loglevel = ZFCP_LOG_LEVEL_DEFAULTS;
  35. static char *device;
  36. /*********************** FUNCTION PROTOTYPES *********************************/
  37. /* written against the module interface */
  38. static int __init zfcp_module_init(void);
  39. /* FCP related */
  40. static void zfcp_ns_gid_pn_handler(unsigned long);
  41. /* miscellaneous */
  42. static inline int zfcp_sg_list_alloc(struct zfcp_sg_list *, size_t);
  43. static inline void zfcp_sg_list_free(struct zfcp_sg_list *);
  44. static inline int zfcp_sg_list_copy_from_user(struct zfcp_sg_list *,
  45. void __user *, size_t);
  46. static inline int zfcp_sg_list_copy_to_user(void __user *,
  47. struct zfcp_sg_list *, size_t);
  48. static long zfcp_cfdc_dev_ioctl(struct file *, unsigned int, unsigned long);
  49. #define ZFCP_CFDC_IOC_MAGIC 0xDD
  50. #define ZFCP_CFDC_IOC \
  51. _IOWR(ZFCP_CFDC_IOC_MAGIC, 0, struct zfcp_cfdc_sense_data)
  52. static struct file_operations zfcp_cfdc_fops = {
  53. .unlocked_ioctl = zfcp_cfdc_dev_ioctl,
  54. #ifdef CONFIG_COMPAT
  55. .compat_ioctl = zfcp_cfdc_dev_ioctl
  56. #endif
  57. };
  58. static struct miscdevice zfcp_cfdc_misc = {
  59. .minor = ZFCP_CFDC_DEV_MINOR,
  60. .name = ZFCP_CFDC_DEV_NAME,
  61. .fops = &zfcp_cfdc_fops
  62. };
  63. /*********************** KERNEL/MODULE PARAMETERS ***************************/
  64. /* declare driver module init/cleanup functions */
  65. module_init(zfcp_module_init);
  66. MODULE_AUTHOR("Heiko Carstens <heiko.carstens@de.ibm.com>, "
  67. "Andreas Herrman <aherrman@de.ibm.com>, "
  68. "Martin Peschke <mpeschke@de.ibm.com>, "
  69. "Raimund Schroeder <raimund.schroeder@de.ibm.com>, "
  70. "Wolfgang Taphorn <taphorn@de.ibm.com>, "
  71. "Aron Zeh <arzeh@de.ibm.com>, "
  72. "IBM Deutschland Entwicklung GmbH");
  73. MODULE_DESCRIPTION
  74. ("FCP (SCSI over Fibre Channel) HBA driver for IBM eServer zSeries");
  75. MODULE_LICENSE("GPL");
  76. module_param(device, charp, 0400);
  77. MODULE_PARM_DESC(device, "specify initial device");
  78. module_param(loglevel, uint, 0400);
  79. MODULE_PARM_DESC(loglevel,
  80. "log levels, 8 nibbles: "
  81. "FC ERP QDIO CIO Config FSF SCSI Other, "
  82. "levels: 0=none 1=normal 2=devel 3=trace");
  83. /****************************************************************/
  84. /************** Functions without logging ***********************/
  85. /****************************************************************/
  86. void
  87. _zfcp_hex_dump(char *addr, int count)
  88. {
  89. int i;
  90. for (i = 0; i < count; i++) {
  91. printk("%02x", addr[i]);
  92. if ((i % 4) == 3)
  93. printk(" ");
  94. if ((i % 32) == 31)
  95. printk("\n");
  96. }
  97. if (((i-1) % 32) != 31)
  98. printk("\n");
  99. }
  100. /****************************************************************/
  101. /************** Uncategorised Functions *************************/
  102. /****************************************************************/
  103. #define ZFCP_LOG_AREA ZFCP_LOG_AREA_OTHER
  104. /**
  105. * zfcp_device_setup - setup function
  106. * @str: pointer to parameter string
  107. *
  108. * Parse "device=..." parameter string.
  109. */
  110. static int __init
  111. zfcp_device_setup(char *devstr)
  112. {
  113. char *tmp, *str;
  114. size_t len;
  115. if (!devstr)
  116. return 0;
  117. len = strlen(devstr) + 1;
  118. str = (char *) kmalloc(len, GFP_KERNEL);
  119. if (!str)
  120. goto err_out;
  121. memcpy(str, devstr, len);
  122. tmp = strchr(str, ',');
  123. if (!tmp)
  124. goto err_out;
  125. *tmp++ = '\0';
  126. strncpy(zfcp_data.init_busid, str, BUS_ID_SIZE);
  127. zfcp_data.init_busid[BUS_ID_SIZE-1] = '\0';
  128. zfcp_data.init_wwpn = simple_strtoull(tmp, &tmp, 0);
  129. if (*tmp++ != ',')
  130. goto err_out;
  131. if (*tmp == '\0')
  132. goto err_out;
  133. zfcp_data.init_fcp_lun = simple_strtoull(tmp, &tmp, 0);
  134. if (*tmp != '\0')
  135. goto err_out;
  136. kfree(str);
  137. return 1;
  138. err_out:
  139. ZFCP_LOG_NORMAL("Parse error for device parameter string %s\n", str);
  140. kfree(str);
  141. return 0;
  142. }
  143. static void __init
  144. zfcp_init_device_configure(void)
  145. {
  146. struct zfcp_adapter *adapter;
  147. struct zfcp_port *port;
  148. struct zfcp_unit *unit;
  149. down(&zfcp_data.config_sema);
  150. read_lock_irq(&zfcp_data.config_lock);
  151. adapter = zfcp_get_adapter_by_busid(zfcp_data.init_busid);
  152. if (adapter)
  153. zfcp_adapter_get(adapter);
  154. read_unlock_irq(&zfcp_data.config_lock);
  155. if (adapter == NULL)
  156. goto out_adapter;
  157. port = zfcp_port_enqueue(adapter, zfcp_data.init_wwpn, 0, 0);
  158. if (!port)
  159. goto out_port;
  160. unit = zfcp_unit_enqueue(port, zfcp_data.init_fcp_lun);
  161. if (!unit)
  162. goto out_unit;
  163. up(&zfcp_data.config_sema);
  164. ccw_device_set_online(adapter->ccw_device);
  165. zfcp_erp_wait(adapter);
  166. down(&zfcp_data.config_sema);
  167. zfcp_unit_put(unit);
  168. out_unit:
  169. zfcp_port_put(port);
  170. out_port:
  171. zfcp_adapter_put(adapter);
  172. out_adapter:
  173. up(&zfcp_data.config_sema);
  174. return;
  175. }
  176. static int __init
  177. zfcp_module_init(void)
  178. {
  179. int retval = 0;
  180. atomic_set(&zfcp_data.loglevel, loglevel);
  181. /* initialize adapter list */
  182. INIT_LIST_HEAD(&zfcp_data.adapter_list_head);
  183. /* initialize adapters to be removed list head */
  184. INIT_LIST_HEAD(&zfcp_data.adapter_remove_lh);
  185. zfcp_transport_template = fc_attach_transport(&zfcp_transport_functions);
  186. if (!zfcp_transport_template)
  187. return -ENODEV;
  188. retval = misc_register(&zfcp_cfdc_misc);
  189. if (retval != 0) {
  190. ZFCP_LOG_INFO("registration of misc device "
  191. "zfcp_cfdc failed\n");
  192. goto out;
  193. }
  194. ZFCP_LOG_TRACE("major/minor for zfcp_cfdc: %d/%d\n",
  195. ZFCP_CFDC_DEV_MAJOR, zfcp_cfdc_misc.minor);
  196. /* Initialise proc semaphores */
  197. sema_init(&zfcp_data.config_sema, 1);
  198. /* initialise configuration rw lock */
  199. rwlock_init(&zfcp_data.config_lock);
  200. /* save address of data structure managing the driver module */
  201. zfcp_data.scsi_host_template.module = THIS_MODULE;
  202. /* setup dynamic I/O */
  203. retval = zfcp_ccw_register();
  204. if (retval) {
  205. ZFCP_LOG_NORMAL("registration with common I/O layer failed\n");
  206. goto out_ccw_register;
  207. }
  208. if (zfcp_device_setup(device))
  209. zfcp_init_device_configure();
  210. goto out;
  211. out_ccw_register:
  212. misc_deregister(&zfcp_cfdc_misc);
  213. out:
  214. return retval;
  215. }
  216. /*
  217. * function: zfcp_cfdc_dev_ioctl
  218. *
  219. * purpose: Handle control file upload/download transaction via IOCTL
  220. * interface
  221. *
  222. * returns: 0 - Operation completed successfuly
  223. * -ENOTTY - Unknown IOCTL command
  224. * -EINVAL - Invalid sense data record
  225. * -ENXIO - The FCP adapter is not available
  226. * -EOPNOTSUPP - The FCP adapter does not have CFDC support
  227. * -ENOMEM - Insufficient memory
  228. * -EFAULT - User space memory I/O operation fault
  229. * -EPERM - Cannot create or queue FSF request or create SBALs
  230. * -ERESTARTSYS- Received signal (is mapped to EAGAIN by VFS)
  231. */
  232. static long
  233. zfcp_cfdc_dev_ioctl(struct file *file, unsigned int command,
  234. unsigned long buffer)
  235. {
  236. struct zfcp_cfdc_sense_data *sense_data, __user *sense_data_user;
  237. struct zfcp_adapter *adapter = NULL;
  238. struct zfcp_fsf_req *fsf_req = NULL;
  239. struct zfcp_sg_list *sg_list = NULL;
  240. u32 fsf_command, option;
  241. char *bus_id = NULL;
  242. int retval = 0;
  243. sense_data = kmalloc(sizeof(struct zfcp_cfdc_sense_data), GFP_KERNEL);
  244. if (sense_data == NULL) {
  245. retval = -ENOMEM;
  246. goto out;
  247. }
  248. sg_list = kmalloc(sizeof(struct zfcp_sg_list), GFP_KERNEL);
  249. if (sg_list == NULL) {
  250. retval = -ENOMEM;
  251. goto out;
  252. }
  253. memset(sg_list, 0, sizeof(*sg_list));
  254. if (command != ZFCP_CFDC_IOC) {
  255. ZFCP_LOG_INFO("IOC request code 0x%x invalid\n", command);
  256. retval = -ENOTTY;
  257. goto out;
  258. }
  259. if ((sense_data_user = (void __user *) buffer) == NULL) {
  260. ZFCP_LOG_INFO("sense data record is required\n");
  261. retval = -EINVAL;
  262. goto out;
  263. }
  264. retval = copy_from_user(sense_data, sense_data_user,
  265. sizeof(struct zfcp_cfdc_sense_data));
  266. if (retval) {
  267. retval = -EFAULT;
  268. goto out;
  269. }
  270. if (sense_data->signature != ZFCP_CFDC_SIGNATURE) {
  271. ZFCP_LOG_INFO("invalid sense data request signature 0x%08x\n",
  272. ZFCP_CFDC_SIGNATURE);
  273. retval = -EINVAL;
  274. goto out;
  275. }
  276. switch (sense_data->command) {
  277. case ZFCP_CFDC_CMND_DOWNLOAD_NORMAL:
  278. fsf_command = FSF_QTCB_DOWNLOAD_CONTROL_FILE;
  279. option = FSF_CFDC_OPTION_NORMAL_MODE;
  280. break;
  281. case ZFCP_CFDC_CMND_DOWNLOAD_FORCE:
  282. fsf_command = FSF_QTCB_DOWNLOAD_CONTROL_FILE;
  283. option = FSF_CFDC_OPTION_FORCE;
  284. break;
  285. case ZFCP_CFDC_CMND_FULL_ACCESS:
  286. fsf_command = FSF_QTCB_DOWNLOAD_CONTROL_FILE;
  287. option = FSF_CFDC_OPTION_FULL_ACCESS;
  288. break;
  289. case ZFCP_CFDC_CMND_RESTRICTED_ACCESS:
  290. fsf_command = FSF_QTCB_DOWNLOAD_CONTROL_FILE;
  291. option = FSF_CFDC_OPTION_RESTRICTED_ACCESS;
  292. break;
  293. case ZFCP_CFDC_CMND_UPLOAD:
  294. fsf_command = FSF_QTCB_UPLOAD_CONTROL_FILE;
  295. option = 0;
  296. break;
  297. default:
  298. ZFCP_LOG_INFO("invalid command code 0x%08x\n",
  299. sense_data->command);
  300. retval = -EINVAL;
  301. goto out;
  302. }
  303. bus_id = kmalloc(BUS_ID_SIZE, GFP_KERNEL);
  304. if (bus_id == NULL) {
  305. retval = -ENOMEM;
  306. goto out;
  307. }
  308. snprintf(bus_id, BUS_ID_SIZE, "%d.%d.%04x",
  309. (sense_data->devno >> 24),
  310. (sense_data->devno >> 16) & 0xFF,
  311. (sense_data->devno & 0xFFFF));
  312. read_lock_irq(&zfcp_data.config_lock);
  313. adapter = zfcp_get_adapter_by_busid(bus_id);
  314. if (adapter)
  315. zfcp_adapter_get(adapter);
  316. read_unlock_irq(&zfcp_data.config_lock);
  317. kfree(bus_id);
  318. if (adapter == NULL) {
  319. ZFCP_LOG_INFO("invalid adapter\n");
  320. retval = -ENXIO;
  321. goto out;
  322. }
  323. if (sense_data->command & ZFCP_CFDC_WITH_CONTROL_FILE) {
  324. retval = zfcp_sg_list_alloc(sg_list,
  325. ZFCP_CFDC_MAX_CONTROL_FILE_SIZE);
  326. if (retval) {
  327. retval = -ENOMEM;
  328. goto out;
  329. }
  330. }
  331. if ((sense_data->command & ZFCP_CFDC_DOWNLOAD) &&
  332. (sense_data->command & ZFCP_CFDC_WITH_CONTROL_FILE)) {
  333. retval = zfcp_sg_list_copy_from_user(
  334. sg_list, &sense_data_user->control_file,
  335. ZFCP_CFDC_MAX_CONTROL_FILE_SIZE);
  336. if (retval) {
  337. retval = -EFAULT;
  338. goto out;
  339. }
  340. }
  341. retval = zfcp_fsf_control_file(adapter, &fsf_req, fsf_command,
  342. option, sg_list);
  343. if (retval)
  344. goto out;
  345. if ((fsf_req->qtcb->prefix.prot_status != FSF_PROT_GOOD) &&
  346. (fsf_req->qtcb->prefix.prot_status != FSF_PROT_FSF_STATUS_PRESENTED)) {
  347. retval = -ENXIO;
  348. goto out;
  349. }
  350. sense_data->fsf_status = fsf_req->qtcb->header.fsf_status;
  351. memcpy(&sense_data->fsf_status_qual,
  352. &fsf_req->qtcb->header.fsf_status_qual,
  353. sizeof(union fsf_status_qual));
  354. memcpy(&sense_data->payloads, &fsf_req->qtcb->bottom.support.els, 256);
  355. retval = copy_to_user(sense_data_user, sense_data,
  356. sizeof(struct zfcp_cfdc_sense_data));
  357. if (retval) {
  358. retval = -EFAULT;
  359. goto out;
  360. }
  361. if (sense_data->command & ZFCP_CFDC_UPLOAD) {
  362. retval = zfcp_sg_list_copy_to_user(
  363. &sense_data_user->control_file, sg_list,
  364. ZFCP_CFDC_MAX_CONTROL_FILE_SIZE);
  365. if (retval) {
  366. retval = -EFAULT;
  367. goto out;
  368. }
  369. }
  370. out:
  371. if (fsf_req != NULL)
  372. zfcp_fsf_req_free(fsf_req);
  373. if ((adapter != NULL) && (retval != -ENXIO))
  374. zfcp_adapter_put(adapter);
  375. if (sg_list != NULL) {
  376. zfcp_sg_list_free(sg_list);
  377. kfree(sg_list);
  378. }
  379. kfree(sense_data);
  380. return retval;
  381. }
  382. /**
  383. * zfcp_sg_list_alloc - create a scatter-gather list of the specified size
  384. * @sg_list: structure describing a scatter gather list
  385. * @size: size of scatter-gather list
  386. * Return: 0 on success, else -ENOMEM
  387. *
  388. * In sg_list->sg a pointer to the created scatter-gather list is returned,
  389. * or NULL if we run out of memory. sg_list->count specifies the number of
  390. * elements of the scatter-gather list. The maximum size of a single element
  391. * in the scatter-gather list is PAGE_SIZE.
  392. */
  393. static inline int
  394. zfcp_sg_list_alloc(struct zfcp_sg_list *sg_list, size_t size)
  395. {
  396. struct scatterlist *sg;
  397. unsigned int i;
  398. int retval = 0;
  399. void *address;
  400. BUG_ON(sg_list == NULL);
  401. sg_list->count = size >> PAGE_SHIFT;
  402. if (size & ~PAGE_MASK)
  403. sg_list->count++;
  404. sg_list->sg = kmalloc(sg_list->count * sizeof(struct scatterlist),
  405. GFP_KERNEL);
  406. if (sg_list->sg == NULL) {
  407. sg_list->count = 0;
  408. retval = -ENOMEM;
  409. goto out;
  410. }
  411. memset(sg_list->sg, 0, sg_list->count * sizeof(struct scatterlist));
  412. for (i = 0, sg = sg_list->sg; i < sg_list->count; i++, sg++) {
  413. sg->length = min(size, PAGE_SIZE);
  414. sg->offset = 0;
  415. address = (void *) get_zeroed_page(GFP_KERNEL);
  416. if (address == NULL) {
  417. sg_list->count = i;
  418. zfcp_sg_list_free(sg_list);
  419. retval = -ENOMEM;
  420. goto out;
  421. }
  422. zfcp_address_to_sg(address, sg);
  423. size -= sg->length;
  424. }
  425. out:
  426. return retval;
  427. }
  428. /**
  429. * zfcp_sg_list_free - free memory of a scatter-gather list
  430. * @sg_list: structure describing a scatter-gather list
  431. *
  432. * Memory for each element in the scatter-gather list is freed.
  433. * Finally sg_list->sg is freed itself and sg_list->count is reset.
  434. */
  435. static inline void
  436. zfcp_sg_list_free(struct zfcp_sg_list *sg_list)
  437. {
  438. struct scatterlist *sg;
  439. unsigned int i;
  440. BUG_ON(sg_list == NULL);
  441. for (i = 0, sg = sg_list->sg; i < sg_list->count; i++, sg++)
  442. free_page((unsigned long) zfcp_sg_to_address(sg));
  443. sg_list->count = 0;
  444. kfree(sg_list->sg);
  445. }
  446. /**
  447. * zfcp_sg_size - determine size of a scatter-gather list
  448. * @sg: array of (struct scatterlist)
  449. * @sg_count: elements in array
  450. * Return: size of entire scatter-gather list
  451. */
  452. size_t
  453. zfcp_sg_size(struct scatterlist *sg, unsigned int sg_count)
  454. {
  455. unsigned int i;
  456. struct scatterlist *p;
  457. size_t size;
  458. size = 0;
  459. for (i = 0, p = sg; i < sg_count; i++, p++) {
  460. BUG_ON(p == NULL);
  461. size += p->length;
  462. }
  463. return size;
  464. }
  465. /**
  466. * zfcp_sg_list_copy_from_user -copy data from user space to scatter-gather list
  467. * @sg_list: structure describing a scatter-gather list
  468. * @user_buffer: pointer to buffer in user space
  469. * @size: number of bytes to be copied
  470. * Return: 0 on success, -EFAULT if copy_from_user fails.
  471. */
  472. static inline int
  473. zfcp_sg_list_copy_from_user(struct zfcp_sg_list *sg_list,
  474. void __user *user_buffer,
  475. size_t size)
  476. {
  477. struct scatterlist *sg;
  478. unsigned int length;
  479. void *zfcp_buffer;
  480. int retval = 0;
  481. BUG_ON(sg_list == NULL);
  482. if (zfcp_sg_size(sg_list->sg, sg_list->count) < size)
  483. return -EFAULT;
  484. for (sg = sg_list->sg; size > 0; sg++) {
  485. length = min((unsigned int)size, sg->length);
  486. zfcp_buffer = zfcp_sg_to_address(sg);
  487. if (copy_from_user(zfcp_buffer, user_buffer, length)) {
  488. retval = -EFAULT;
  489. goto out;
  490. }
  491. user_buffer += length;
  492. size -= length;
  493. }
  494. out:
  495. return retval;
  496. }
  497. /**
  498. * zfcp_sg_list_copy_to_user - copy data from scatter-gather list to user space
  499. * @user_buffer: pointer to buffer in user space
  500. * @sg_list: structure describing a scatter-gather list
  501. * @size: number of bytes to be copied
  502. * Return: 0 on success, -EFAULT if copy_to_user fails
  503. */
  504. static inline int
  505. zfcp_sg_list_copy_to_user(void __user *user_buffer,
  506. struct zfcp_sg_list *sg_list,
  507. size_t size)
  508. {
  509. struct scatterlist *sg;
  510. unsigned int length;
  511. void *zfcp_buffer;
  512. int retval = 0;
  513. BUG_ON(sg_list == NULL);
  514. if (zfcp_sg_size(sg_list->sg, sg_list->count) < size)
  515. return -EFAULT;
  516. for (sg = sg_list->sg; size > 0; sg++) {
  517. length = min((unsigned int) size, sg->length);
  518. zfcp_buffer = zfcp_sg_to_address(sg);
  519. if (copy_to_user(user_buffer, zfcp_buffer, length)) {
  520. retval = -EFAULT;
  521. goto out;
  522. }
  523. user_buffer += length;
  524. size -= length;
  525. }
  526. out:
  527. return retval;
  528. }
  529. #undef ZFCP_LOG_AREA
  530. /****************************************************************/
  531. /****** Functions for configuration/set-up of structures ********/
  532. /****************************************************************/
  533. #define ZFCP_LOG_AREA ZFCP_LOG_AREA_CONFIG
  534. /**
  535. * zfcp_get_unit_by_lun - find unit in unit list of port by FCP LUN
  536. * @port: pointer to port to search for unit
  537. * @fcp_lun: FCP LUN to search for
  538. * Traverse list of all units of a port and return pointer to a unit
  539. * with the given FCP LUN.
  540. */
  541. struct zfcp_unit *
  542. zfcp_get_unit_by_lun(struct zfcp_port *port, fcp_lun_t fcp_lun)
  543. {
  544. struct zfcp_unit *unit;
  545. int found = 0;
  546. list_for_each_entry(unit, &port->unit_list_head, list) {
  547. if ((unit->fcp_lun == fcp_lun) &&
  548. !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status))
  549. {
  550. found = 1;
  551. break;
  552. }
  553. }
  554. return found ? unit : NULL;
  555. }
  556. /**
  557. * zfcp_get_port_by_wwpn - find port in port list of adapter by wwpn
  558. * @adapter: pointer to adapter to search for port
  559. * @wwpn: wwpn to search for
  560. * Traverse list of all ports of an adapter and return pointer to a port
  561. * with the given wwpn.
  562. */
  563. struct zfcp_port *
  564. zfcp_get_port_by_wwpn(struct zfcp_adapter *adapter, wwn_t wwpn)
  565. {
  566. struct zfcp_port *port;
  567. int found = 0;
  568. list_for_each_entry(port, &adapter->port_list_head, list) {
  569. if ((port->wwpn == wwpn) &&
  570. !(atomic_read(&port->status) &
  571. (ZFCP_STATUS_PORT_NO_WWPN | ZFCP_STATUS_COMMON_REMOVE))) {
  572. found = 1;
  573. break;
  574. }
  575. }
  576. return found ? port : NULL;
  577. }
  578. /**
  579. * zfcp_get_port_by_did - find port in port list of adapter by d_id
  580. * @adapter: pointer to adapter to search for port
  581. * @d_id: d_id to search for
  582. * Traverse list of all ports of an adapter and return pointer to a port
  583. * with the given d_id.
  584. */
  585. struct zfcp_port *
  586. zfcp_get_port_by_did(struct zfcp_adapter *adapter, u32 d_id)
  587. {
  588. struct zfcp_port *port;
  589. int found = 0;
  590. list_for_each_entry(port, &adapter->port_list_head, list) {
  591. if ((port->d_id == d_id) &&
  592. !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status))
  593. {
  594. found = 1;
  595. break;
  596. }
  597. }
  598. return found ? port : NULL;
  599. }
  600. /**
  601. * zfcp_get_adapter_by_busid - find adpater in adapter list by bus_id
  602. * @bus_id: bus_id to search for
  603. * Traverse list of all adapters and return pointer to an adapter
  604. * with the given bus_id.
  605. */
  606. struct zfcp_adapter *
  607. zfcp_get_adapter_by_busid(char *bus_id)
  608. {
  609. struct zfcp_adapter *adapter;
  610. int found = 0;
  611. list_for_each_entry(adapter, &zfcp_data.adapter_list_head, list) {
  612. if ((strncmp(bus_id, zfcp_get_busid_by_adapter(adapter),
  613. BUS_ID_SIZE) == 0) &&
  614. !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE,
  615. &adapter->status)){
  616. found = 1;
  617. break;
  618. }
  619. }
  620. return found ? adapter : NULL;
  621. }
  622. /**
  623. * zfcp_unit_enqueue - enqueue unit to unit list of a port.
  624. * @port: pointer to port where unit is added
  625. * @fcp_lun: FCP LUN of unit to be enqueued
  626. * Return: pointer to enqueued unit on success, NULL on error
  627. * Locks: config_sema must be held to serialize changes to the unit list
  628. *
  629. * Sets up some unit internal structures and creates sysfs entry.
  630. */
  631. struct zfcp_unit *
  632. zfcp_unit_enqueue(struct zfcp_port *port, fcp_lun_t fcp_lun)
  633. {
  634. struct zfcp_unit *unit, *tmp_unit;
  635. scsi_lun_t scsi_lun;
  636. int found;
  637. /*
  638. * check that there is no unit with this FCP_LUN already in list
  639. * and enqueue it.
  640. * Note: Unlike for the adapter and the port, this is an error
  641. */
  642. read_lock_irq(&zfcp_data.config_lock);
  643. unit = zfcp_get_unit_by_lun(port, fcp_lun);
  644. read_unlock_irq(&zfcp_data.config_lock);
  645. if (unit)
  646. return NULL;
  647. unit = kmalloc(sizeof (struct zfcp_unit), GFP_KERNEL);
  648. if (!unit)
  649. return NULL;
  650. memset(unit, 0, sizeof (struct zfcp_unit));
  651. /* initialise reference count stuff */
  652. atomic_set(&unit->refcount, 0);
  653. init_waitqueue_head(&unit->remove_wq);
  654. unit->port = port;
  655. unit->fcp_lun = fcp_lun;
  656. /* setup for sysfs registration */
  657. snprintf(unit->sysfs_device.bus_id, BUS_ID_SIZE, "0x%016llx", fcp_lun);
  658. unit->sysfs_device.parent = &port->sysfs_device;
  659. unit->sysfs_device.release = zfcp_sysfs_unit_release;
  660. dev_set_drvdata(&unit->sysfs_device, unit);
  661. /* mark unit unusable as long as sysfs registration is not complete */
  662. atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status);
  663. if (device_register(&unit->sysfs_device)) {
  664. kfree(unit);
  665. return NULL;
  666. }
  667. if (zfcp_sysfs_unit_create_files(&unit->sysfs_device)) {
  668. device_unregister(&unit->sysfs_device);
  669. return NULL;
  670. }
  671. zfcp_unit_get(unit);
  672. scsi_lun = 0;
  673. found = 0;
  674. write_lock_irq(&zfcp_data.config_lock);
  675. list_for_each_entry(tmp_unit, &port->unit_list_head, list) {
  676. if (tmp_unit->scsi_lun != scsi_lun) {
  677. found = 1;
  678. break;
  679. }
  680. scsi_lun++;
  681. }
  682. unit->scsi_lun = scsi_lun;
  683. if (found)
  684. list_add_tail(&unit->list, &tmp_unit->list);
  685. else
  686. list_add_tail(&unit->list, &port->unit_list_head);
  687. atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status);
  688. atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING, &unit->status);
  689. write_unlock_irq(&zfcp_data.config_lock);
  690. port->units++;
  691. zfcp_port_get(port);
  692. return unit;
  693. }
  694. void
  695. zfcp_unit_dequeue(struct zfcp_unit *unit)
  696. {
  697. zfcp_unit_wait(unit);
  698. write_lock_irq(&zfcp_data.config_lock);
  699. list_del(&unit->list);
  700. write_unlock_irq(&zfcp_data.config_lock);
  701. unit->port->units--;
  702. zfcp_port_put(unit->port);
  703. zfcp_sysfs_unit_remove_files(&unit->sysfs_device);
  704. device_unregister(&unit->sysfs_device);
  705. }
  706. static void *
  707. zfcp_mempool_alloc(gfp_t gfp_mask, void *size)
  708. {
  709. return kmalloc((size_t) size, gfp_mask);
  710. }
  711. static void
  712. zfcp_mempool_free(void *element, void *size)
  713. {
  714. kfree(element);
  715. }
  716. /*
  717. * Allocates a combined QTCB/fsf_req buffer for erp actions and fcp/SCSI
  718. * commands.
  719. * It also genrates fcp-nameserver request/response buffer and unsolicited
  720. * status read fsf_req buffers.
  721. *
  722. * locks: must only be called with zfcp_data.config_sema taken
  723. */
  724. static int
  725. zfcp_allocate_low_mem_buffers(struct zfcp_adapter *adapter)
  726. {
  727. adapter->pool.fsf_req_erp =
  728. mempool_create(ZFCP_POOL_FSF_REQ_ERP_NR,
  729. zfcp_mempool_alloc, zfcp_mempool_free, (void *)
  730. sizeof(struct zfcp_fsf_req_pool_element));
  731. if (NULL == adapter->pool.fsf_req_erp)
  732. return -ENOMEM;
  733. adapter->pool.fsf_req_scsi =
  734. mempool_create(ZFCP_POOL_FSF_REQ_SCSI_NR,
  735. zfcp_mempool_alloc, zfcp_mempool_free, (void *)
  736. sizeof(struct zfcp_fsf_req_pool_element));
  737. if (NULL == adapter->pool.fsf_req_scsi)
  738. return -ENOMEM;
  739. adapter->pool.fsf_req_abort =
  740. mempool_create(ZFCP_POOL_FSF_REQ_ABORT_NR,
  741. zfcp_mempool_alloc, zfcp_mempool_free, (void *)
  742. sizeof(struct zfcp_fsf_req_pool_element));
  743. if (NULL == adapter->pool.fsf_req_abort)
  744. return -ENOMEM;
  745. adapter->pool.fsf_req_status_read =
  746. mempool_create(ZFCP_POOL_STATUS_READ_NR,
  747. zfcp_mempool_alloc, zfcp_mempool_free,
  748. (void *) sizeof(struct zfcp_fsf_req));
  749. if (NULL == adapter->pool.fsf_req_status_read)
  750. return -ENOMEM;
  751. adapter->pool.data_status_read =
  752. mempool_create(ZFCP_POOL_STATUS_READ_NR,
  753. zfcp_mempool_alloc, zfcp_mempool_free,
  754. (void *) sizeof(struct fsf_status_read_buffer));
  755. if (NULL == adapter->pool.data_status_read)
  756. return -ENOMEM;
  757. adapter->pool.data_gid_pn =
  758. mempool_create(ZFCP_POOL_DATA_GID_PN_NR,
  759. zfcp_mempool_alloc, zfcp_mempool_free, (void *)
  760. sizeof(struct zfcp_gid_pn_data));
  761. if (NULL == adapter->pool.data_gid_pn)
  762. return -ENOMEM;
  763. return 0;
  764. }
  765. /**
  766. * zfcp_free_low_mem_buffers - free memory pools of an adapter
  767. * @adapter: pointer to zfcp_adapter for which memory pools should be freed
  768. * locking: zfcp_data.config_sema must be held
  769. */
  770. static void
  771. zfcp_free_low_mem_buffers(struct zfcp_adapter *adapter)
  772. {
  773. if (adapter->pool.fsf_req_erp)
  774. mempool_destroy(adapter->pool.fsf_req_erp);
  775. if (adapter->pool.fsf_req_scsi)
  776. mempool_destroy(adapter->pool.fsf_req_scsi);
  777. if (adapter->pool.fsf_req_abort)
  778. mempool_destroy(adapter->pool.fsf_req_abort);
  779. if (adapter->pool.fsf_req_status_read)
  780. mempool_destroy(adapter->pool.fsf_req_status_read);
  781. if (adapter->pool.data_status_read)
  782. mempool_destroy(adapter->pool.data_status_read);
  783. if (adapter->pool.data_gid_pn)
  784. mempool_destroy(adapter->pool.data_gid_pn);
  785. }
  786. void
  787. zfcp_dummy_release(struct device *dev)
  788. {
  789. return;
  790. }
  791. /*
  792. * Enqueues an adapter at the end of the adapter list in the driver data.
  793. * All adapter internal structures are set up.
  794. * Proc-fs entries are also created.
  795. *
  796. * returns: 0 if a new adapter was successfully enqueued
  797. * ZFCP_KNOWN if an adapter with this devno was already present
  798. * -ENOMEM if alloc failed
  799. * locks: config_sema must be held to serialise changes to the adapter list
  800. */
  801. struct zfcp_adapter *
  802. zfcp_adapter_enqueue(struct ccw_device *ccw_device)
  803. {
  804. int retval = 0;
  805. struct zfcp_adapter *adapter;
  806. /*
  807. * Note: It is safe to release the list_lock, as any list changes
  808. * are protected by the config_sema, which must be held to get here
  809. */
  810. /* try to allocate new adapter data structure (zeroed) */
  811. adapter = kmalloc(sizeof (struct zfcp_adapter), GFP_KERNEL);
  812. if (!adapter) {
  813. ZFCP_LOG_INFO("error: allocation of base adapter "
  814. "structure failed\n");
  815. goto out;
  816. }
  817. memset(adapter, 0, sizeof (struct zfcp_adapter));
  818. ccw_device->handler = NULL;
  819. /* save ccw_device pointer */
  820. adapter->ccw_device = ccw_device;
  821. retval = zfcp_qdio_allocate_queues(adapter);
  822. if (retval)
  823. goto queues_alloc_failed;
  824. retval = zfcp_qdio_allocate(adapter);
  825. if (retval)
  826. goto qdio_allocate_failed;
  827. retval = zfcp_allocate_low_mem_buffers(adapter);
  828. if (retval) {
  829. ZFCP_LOG_INFO("error: pool allocation failed\n");
  830. goto failed_low_mem_buffers;
  831. }
  832. /* initialise reference count stuff */
  833. atomic_set(&adapter->refcount, 0);
  834. init_waitqueue_head(&adapter->remove_wq);
  835. /* initialise list of ports */
  836. INIT_LIST_HEAD(&adapter->port_list_head);
  837. /* initialise list of ports to be removed */
  838. INIT_LIST_HEAD(&adapter->port_remove_lh);
  839. /* initialize list of fsf requests */
  840. spin_lock_init(&adapter->fsf_req_list_lock);
  841. INIT_LIST_HEAD(&adapter->fsf_req_list_head);
  842. /* initialize abort lock */
  843. rwlock_init(&adapter->abort_lock);
  844. /* initialise some erp stuff */
  845. init_waitqueue_head(&adapter->erp_thread_wqh);
  846. init_waitqueue_head(&adapter->erp_done_wqh);
  847. /* initialize lock of associated request queue */
  848. rwlock_init(&adapter->request_queue.queue_lock);
  849. /* intitialise SCSI ER timer */
  850. init_timer(&adapter->scsi_er_timer);
  851. /* set FC service class used per default */
  852. adapter->fc_service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
  853. sprintf(adapter->name, "%s", zfcp_get_busid_by_adapter(adapter));
  854. ASCEBC(adapter->name, strlen(adapter->name));
  855. /* mark adapter unusable as long as sysfs registration is not complete */
  856. atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status);
  857. adapter->ccw_device = ccw_device;
  858. dev_set_drvdata(&ccw_device->dev, adapter);
  859. if (zfcp_sysfs_adapter_create_files(&ccw_device->dev))
  860. goto sysfs_failed;
  861. adapter->generic_services.parent = &adapter->ccw_device->dev;
  862. adapter->generic_services.release = zfcp_dummy_release;
  863. snprintf(adapter->generic_services.bus_id, BUS_ID_SIZE,
  864. "generic_services");
  865. if (device_register(&adapter->generic_services))
  866. goto generic_services_failed;
  867. /* put allocated adapter at list tail */
  868. write_lock_irq(&zfcp_data.config_lock);
  869. atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status);
  870. list_add_tail(&adapter->list, &zfcp_data.adapter_list_head);
  871. write_unlock_irq(&zfcp_data.config_lock);
  872. zfcp_data.adapters++;
  873. goto out;
  874. generic_services_failed:
  875. zfcp_sysfs_adapter_remove_files(&adapter->ccw_device->dev);
  876. sysfs_failed:
  877. dev_set_drvdata(&ccw_device->dev, NULL);
  878. failed_low_mem_buffers:
  879. zfcp_free_low_mem_buffers(adapter);
  880. if (qdio_free(ccw_device) != 0)
  881. ZFCP_LOG_NORMAL("bug: qdio_free for adapter %s failed\n",
  882. zfcp_get_busid_by_adapter(adapter));
  883. qdio_allocate_failed:
  884. zfcp_qdio_free_queues(adapter);
  885. queues_alloc_failed:
  886. kfree(adapter);
  887. adapter = NULL;
  888. out:
  889. return adapter;
  890. }
  891. /*
  892. * returns: 0 - struct zfcp_adapter data structure successfully removed
  893. * !0 - struct zfcp_adapter data structure could not be removed
  894. * (e.g. still used)
  895. * locks: adapter list write lock is assumed to be held by caller
  896. * adapter->fsf_req_list_lock is taken and released within this
  897. * function and must not be held on entry
  898. */
  899. void
  900. zfcp_adapter_dequeue(struct zfcp_adapter *adapter)
  901. {
  902. int retval = 0;
  903. unsigned long flags;
  904. device_unregister(&adapter->generic_services);
  905. zfcp_sysfs_adapter_remove_files(&adapter->ccw_device->dev);
  906. dev_set_drvdata(&adapter->ccw_device->dev, NULL);
  907. /* sanity check: no pending FSF requests */
  908. spin_lock_irqsave(&adapter->fsf_req_list_lock, flags);
  909. retval = !list_empty(&adapter->fsf_req_list_head);
  910. spin_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
  911. if (retval) {
  912. ZFCP_LOG_NORMAL("bug: adapter %s (%p) still in use, "
  913. "%i requests outstanding\n",
  914. zfcp_get_busid_by_adapter(adapter), adapter,
  915. atomic_read(&adapter->fsf_reqs_active));
  916. retval = -EBUSY;
  917. goto out;
  918. }
  919. /* remove specified adapter data structure from list */
  920. write_lock_irq(&zfcp_data.config_lock);
  921. list_del(&adapter->list);
  922. write_unlock_irq(&zfcp_data.config_lock);
  923. /* decrease number of adapters in list */
  924. zfcp_data.adapters--;
  925. ZFCP_LOG_TRACE("adapter %s (%p) removed from list, "
  926. "%i adapters still in list\n",
  927. zfcp_get_busid_by_adapter(adapter),
  928. adapter, zfcp_data.adapters);
  929. retval = qdio_free(adapter->ccw_device);
  930. if (retval)
  931. ZFCP_LOG_NORMAL("bug: qdio_free for adapter %s failed\n",
  932. zfcp_get_busid_by_adapter(adapter));
  933. zfcp_free_low_mem_buffers(adapter);
  934. /* free memory of adapter data structure and queues */
  935. zfcp_qdio_free_queues(adapter);
  936. ZFCP_LOG_TRACE("freeing adapter structure\n");
  937. kfree(adapter);
  938. out:
  939. return;
  940. }
  941. /**
  942. * zfcp_port_enqueue - enqueue port to port list of adapter
  943. * @adapter: adapter where remote port is added
  944. * @wwpn: WWPN of the remote port to be enqueued
  945. * @status: initial status for the port
  946. * @d_id: destination id of the remote port to be enqueued
  947. * Return: pointer to enqueued port on success, NULL on error
  948. * Locks: config_sema must be held to serialize changes to the port list
  949. *
  950. * All port internal structures are set up and the sysfs entry is generated.
  951. * d_id is used to enqueue ports with a well known address like the Directory
  952. * Service for nameserver lookup.
  953. */
  954. struct zfcp_port *
  955. zfcp_port_enqueue(struct zfcp_adapter *adapter, wwn_t wwpn, u32 status,
  956. u32 d_id)
  957. {
  958. struct zfcp_port *port;
  959. int check_wwpn;
  960. check_wwpn = !(status & ZFCP_STATUS_PORT_NO_WWPN);
  961. /*
  962. * check that there is no port with this WWPN already in list
  963. */
  964. if (check_wwpn) {
  965. read_lock_irq(&zfcp_data.config_lock);
  966. port = zfcp_get_port_by_wwpn(adapter, wwpn);
  967. read_unlock_irq(&zfcp_data.config_lock);
  968. if (port)
  969. return NULL;
  970. }
  971. port = kmalloc(sizeof (struct zfcp_port), GFP_KERNEL);
  972. if (!port)
  973. return NULL;
  974. memset(port, 0, sizeof (struct zfcp_port));
  975. /* initialise reference count stuff */
  976. atomic_set(&port->refcount, 0);
  977. init_waitqueue_head(&port->remove_wq);
  978. INIT_LIST_HEAD(&port->unit_list_head);
  979. INIT_LIST_HEAD(&port->unit_remove_lh);
  980. port->adapter = adapter;
  981. if (check_wwpn)
  982. port->wwpn = wwpn;
  983. atomic_set_mask(status, &port->status);
  984. /* setup for sysfs registration */
  985. if (status & ZFCP_STATUS_PORT_WKA) {
  986. switch (d_id) {
  987. case ZFCP_DID_DIRECTORY_SERVICE:
  988. snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE,
  989. "directory");
  990. break;
  991. case ZFCP_DID_MANAGEMENT_SERVICE:
  992. snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE,
  993. "management");
  994. break;
  995. case ZFCP_DID_KEY_DISTRIBUTION_SERVICE:
  996. snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE,
  997. "key_distribution");
  998. break;
  999. case ZFCP_DID_ALIAS_SERVICE:
  1000. snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE,
  1001. "alias");
  1002. break;
  1003. case ZFCP_DID_TIME_SERVICE:
  1004. snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE,
  1005. "time");
  1006. break;
  1007. default:
  1008. kfree(port);
  1009. return NULL;
  1010. }
  1011. port->d_id = d_id;
  1012. port->sysfs_device.parent = &adapter->generic_services;
  1013. } else {
  1014. snprintf(port->sysfs_device.bus_id,
  1015. BUS_ID_SIZE, "0x%016llx", wwpn);
  1016. port->sysfs_device.parent = &adapter->ccw_device->dev;
  1017. }
  1018. port->sysfs_device.release = zfcp_sysfs_port_release;
  1019. dev_set_drvdata(&port->sysfs_device, port);
  1020. /* mark port unusable as long as sysfs registration is not complete */
  1021. atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
  1022. if (device_register(&port->sysfs_device)) {
  1023. kfree(port);
  1024. return NULL;
  1025. }
  1026. if (zfcp_sysfs_port_create_files(&port->sysfs_device, status)) {
  1027. device_unregister(&port->sysfs_device);
  1028. return NULL;
  1029. }
  1030. zfcp_port_get(port);
  1031. write_lock_irq(&zfcp_data.config_lock);
  1032. list_add_tail(&port->list, &adapter->port_list_head);
  1033. atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
  1034. atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING, &port->status);
  1035. if (d_id == ZFCP_DID_DIRECTORY_SERVICE)
  1036. if (!adapter->nameserver_port)
  1037. adapter->nameserver_port = port;
  1038. adapter->ports++;
  1039. write_unlock_irq(&zfcp_data.config_lock);
  1040. zfcp_adapter_get(adapter);
  1041. return port;
  1042. }
  1043. void
  1044. zfcp_port_dequeue(struct zfcp_port *port)
  1045. {
  1046. zfcp_port_wait(port);
  1047. write_lock_irq(&zfcp_data.config_lock);
  1048. list_del(&port->list);
  1049. port->adapter->ports--;
  1050. write_unlock_irq(&zfcp_data.config_lock);
  1051. if (port->rport)
  1052. fc_remote_port_delete(port->rport);
  1053. port->rport = NULL;
  1054. zfcp_adapter_put(port->adapter);
  1055. zfcp_sysfs_port_remove_files(&port->sysfs_device,
  1056. atomic_read(&port->status));
  1057. device_unregister(&port->sysfs_device);
  1058. }
  1059. /* Enqueues a nameserver port */
  1060. int
  1061. zfcp_nameserver_enqueue(struct zfcp_adapter *adapter)
  1062. {
  1063. struct zfcp_port *port;
  1064. port = zfcp_port_enqueue(adapter, 0, ZFCP_STATUS_PORT_WKA,
  1065. ZFCP_DID_DIRECTORY_SERVICE);
  1066. if (!port) {
  1067. ZFCP_LOG_INFO("error: enqueue of nameserver port for "
  1068. "adapter %s failed\n",
  1069. zfcp_get_busid_by_adapter(adapter));
  1070. return -ENXIO;
  1071. }
  1072. zfcp_port_put(port);
  1073. return 0;
  1074. }
  1075. #undef ZFCP_LOG_AREA
  1076. /****************************************************************/
  1077. /******* Fibre Channel Standard related Functions **************/
  1078. /****************************************************************/
  1079. #define ZFCP_LOG_AREA ZFCP_LOG_AREA_FC
  1080. void
  1081. zfcp_fsf_incoming_els_rscn(struct zfcp_adapter *adapter,
  1082. struct fsf_status_read_buffer *status_buffer)
  1083. {
  1084. struct fcp_rscn_head *fcp_rscn_head;
  1085. struct fcp_rscn_element *fcp_rscn_element;
  1086. struct zfcp_port *port;
  1087. u16 i;
  1088. u16 no_entries;
  1089. u32 range_mask;
  1090. unsigned long flags;
  1091. fcp_rscn_head = (struct fcp_rscn_head *) status_buffer->payload;
  1092. fcp_rscn_element = (struct fcp_rscn_element *) status_buffer->payload;
  1093. /* see FC-FS */
  1094. no_entries = (fcp_rscn_head->payload_len / 4);
  1095. for (i = 1; i < no_entries; i++) {
  1096. /* skip head and start with 1st element */
  1097. fcp_rscn_element++;
  1098. switch (fcp_rscn_element->addr_format) {
  1099. case ZFCP_PORT_ADDRESS:
  1100. range_mask = ZFCP_PORTS_RANGE_PORT;
  1101. break;
  1102. case ZFCP_AREA_ADDRESS:
  1103. range_mask = ZFCP_PORTS_RANGE_AREA;
  1104. break;
  1105. case ZFCP_DOMAIN_ADDRESS:
  1106. range_mask = ZFCP_PORTS_RANGE_DOMAIN;
  1107. break;
  1108. case ZFCP_FABRIC_ADDRESS:
  1109. range_mask = ZFCP_PORTS_RANGE_FABRIC;
  1110. break;
  1111. default:
  1112. ZFCP_LOG_INFO("incoming RSCN with unknown "
  1113. "address format\n");
  1114. continue;
  1115. }
  1116. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1117. list_for_each_entry(port, &adapter->port_list_head, list) {
  1118. if (atomic_test_mask
  1119. (ZFCP_STATUS_PORT_WKA, &port->status))
  1120. continue;
  1121. /* Do we know this port? If not skip it. */
  1122. if (!atomic_test_mask
  1123. (ZFCP_STATUS_PORT_DID_DID, &port->status)) {
  1124. ZFCP_LOG_INFO("incoming RSCN, trying to open "
  1125. "port 0x%016Lx\n", port->wwpn);
  1126. zfcp_erp_port_reopen(port,
  1127. ZFCP_STATUS_COMMON_ERP_FAILED);
  1128. continue;
  1129. }
  1130. /*
  1131. * FIXME: race: d_id might being invalidated
  1132. * (...DID_DID reset)
  1133. */
  1134. if ((port->d_id & range_mask)
  1135. == (fcp_rscn_element->nport_did & range_mask)) {
  1136. ZFCP_LOG_TRACE("reopen did 0x%08x\n",
  1137. fcp_rscn_element->nport_did);
  1138. /*
  1139. * Unfortunately, an RSCN does not specify the
  1140. * type of change a target underwent. We assume
  1141. * that it makes sense to reopen the link.
  1142. * FIXME: Shall we try to find out more about
  1143. * the target and link state before closing it?
  1144. * How to accomplish this? (nameserver?)
  1145. * Where would such code be put in?
  1146. * (inside or outside erp)
  1147. */
  1148. ZFCP_LOG_INFO("incoming RSCN, trying to open "
  1149. "port 0x%016Lx\n", port->wwpn);
  1150. zfcp_test_link(port);
  1151. }
  1152. }
  1153. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1154. }
  1155. }
  1156. static void
  1157. zfcp_fsf_incoming_els_plogi(struct zfcp_adapter *adapter,
  1158. struct fsf_status_read_buffer *status_buffer)
  1159. {
  1160. logi *els_logi = (logi *) status_buffer->payload;
  1161. struct zfcp_port *port;
  1162. unsigned long flags;
  1163. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1164. list_for_each_entry(port, &adapter->port_list_head, list) {
  1165. if (port->wwpn == (*(wwn_t *) & els_logi->nport_wwn))
  1166. break;
  1167. }
  1168. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1169. if (!port || (port->wwpn != (*(wwn_t *) & els_logi->nport_wwn))) {
  1170. ZFCP_LOG_DEBUG("ignored incoming PLOGI for nonexisting port "
  1171. "with d_id 0x%08x on adapter %s\n",
  1172. status_buffer->d_id,
  1173. zfcp_get_busid_by_adapter(adapter));
  1174. } else {
  1175. zfcp_erp_port_forced_reopen(port, 0);
  1176. }
  1177. }
  1178. static void
  1179. zfcp_fsf_incoming_els_logo(struct zfcp_adapter *adapter,
  1180. struct fsf_status_read_buffer *status_buffer)
  1181. {
  1182. struct fcp_logo *els_logo = (struct fcp_logo *) status_buffer->payload;
  1183. struct zfcp_port *port;
  1184. unsigned long flags;
  1185. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1186. list_for_each_entry(port, &adapter->port_list_head, list) {
  1187. if (port->wwpn == els_logo->nport_wwpn)
  1188. break;
  1189. }
  1190. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1191. if (!port || (port->wwpn != els_logo->nport_wwpn)) {
  1192. ZFCP_LOG_DEBUG("ignored incoming LOGO for nonexisting port "
  1193. "with d_id 0x%08x on adapter %s\n",
  1194. status_buffer->d_id,
  1195. zfcp_get_busid_by_adapter(adapter));
  1196. } else {
  1197. zfcp_erp_port_forced_reopen(port, 0);
  1198. }
  1199. }
  1200. static void
  1201. zfcp_fsf_incoming_els_unknown(struct zfcp_adapter *adapter,
  1202. struct fsf_status_read_buffer *status_buffer)
  1203. {
  1204. ZFCP_LOG_NORMAL("warning: unknown incoming ELS 0x%08x "
  1205. "for adapter %s\n", *(u32 *) (status_buffer->payload),
  1206. zfcp_get_busid_by_adapter(adapter));
  1207. }
  1208. void
  1209. zfcp_fsf_incoming_els(struct zfcp_fsf_req *fsf_req)
  1210. {
  1211. struct fsf_status_read_buffer *status_buffer;
  1212. u32 els_type;
  1213. struct zfcp_adapter *adapter;
  1214. status_buffer = (struct fsf_status_read_buffer *) fsf_req->data;
  1215. els_type = *(u32 *) (status_buffer->payload);
  1216. adapter = fsf_req->adapter;
  1217. zfcp_san_dbf_event_incoming_els(fsf_req);
  1218. if (els_type == LS_PLOGI)
  1219. zfcp_fsf_incoming_els_plogi(adapter, status_buffer);
  1220. else if (els_type == LS_LOGO)
  1221. zfcp_fsf_incoming_els_logo(adapter, status_buffer);
  1222. else if ((els_type & 0xffff0000) == LS_RSCN)
  1223. /* we are only concerned with the command, not the length */
  1224. zfcp_fsf_incoming_els_rscn(adapter, status_buffer);
  1225. else
  1226. zfcp_fsf_incoming_els_unknown(adapter, status_buffer);
  1227. }
  1228. /**
  1229. * zfcp_gid_pn_buffers_alloc - allocate buffers for GID_PN nameserver request
  1230. * @gid_pn: pointer to return pointer to struct zfcp_gid_pn_data
  1231. * @pool: pointer to mempool_t if non-null memory pool is used for allocation
  1232. */
  1233. static int
  1234. zfcp_gid_pn_buffers_alloc(struct zfcp_gid_pn_data **gid_pn, mempool_t *pool)
  1235. {
  1236. struct zfcp_gid_pn_data *data;
  1237. if (pool != NULL) {
  1238. data = mempool_alloc(pool, GFP_ATOMIC);
  1239. if (likely(data != NULL)) {
  1240. data->ct.pool = pool;
  1241. }
  1242. } else {
  1243. data = kmalloc(sizeof(struct zfcp_gid_pn_data), GFP_ATOMIC);
  1244. }
  1245. if (NULL == data)
  1246. return -ENOMEM;
  1247. memset(data, 0, sizeof(*data));
  1248. data->ct.req = &data->req;
  1249. data->ct.resp = &data->resp;
  1250. data->ct.req_count = data->ct.resp_count = 1;
  1251. zfcp_address_to_sg(&data->ct_iu_req, &data->req);
  1252. zfcp_address_to_sg(&data->ct_iu_resp, &data->resp);
  1253. data->req.length = sizeof(struct ct_iu_gid_pn_req);
  1254. data->resp.length = sizeof(struct ct_iu_gid_pn_resp);
  1255. *gid_pn = data;
  1256. return 0;
  1257. }
  1258. /**
  1259. * zfcp_gid_pn_buffers_free - free buffers for GID_PN nameserver request
  1260. * @gid_pn: pointer to struct zfcp_gid_pn_data which has to be freed
  1261. */
  1262. static void
  1263. zfcp_gid_pn_buffers_free(struct zfcp_gid_pn_data *gid_pn)
  1264. {
  1265. if ((gid_pn->ct.pool != 0))
  1266. mempool_free(gid_pn, gid_pn->ct.pool);
  1267. else
  1268. kfree(gid_pn);
  1269. return;
  1270. }
  1271. /**
  1272. * zfcp_ns_gid_pn_request - initiate GID_PN nameserver request
  1273. * @erp_action: pointer to zfcp_erp_action where GID_PN request is needed
  1274. */
  1275. int
  1276. zfcp_ns_gid_pn_request(struct zfcp_erp_action *erp_action)
  1277. {
  1278. int ret;
  1279. struct ct_iu_gid_pn_req *ct_iu_req;
  1280. struct zfcp_gid_pn_data *gid_pn;
  1281. struct zfcp_adapter *adapter = erp_action->adapter;
  1282. ret = zfcp_gid_pn_buffers_alloc(&gid_pn, adapter->pool.data_gid_pn);
  1283. if (ret < 0) {
  1284. ZFCP_LOG_INFO("error: buffer allocation for gid_pn nameserver "
  1285. "request failed for adapter %s\n",
  1286. zfcp_get_busid_by_adapter(adapter));
  1287. goto out;
  1288. }
  1289. /* setup nameserver request */
  1290. ct_iu_req = zfcp_sg_to_address(gid_pn->ct.req);
  1291. ct_iu_req->header.revision = ZFCP_CT_REVISION;
  1292. ct_iu_req->header.gs_type = ZFCP_CT_DIRECTORY_SERVICE;
  1293. ct_iu_req->header.gs_subtype = ZFCP_CT_NAME_SERVER;
  1294. ct_iu_req->header.options = ZFCP_CT_SYNCHRONOUS;
  1295. ct_iu_req->header.cmd_rsp_code = ZFCP_CT_GID_PN;
  1296. ct_iu_req->header.max_res_size = ZFCP_CT_MAX_SIZE;
  1297. ct_iu_req->wwpn = erp_action->port->wwpn;
  1298. /* setup parameters for send generic command */
  1299. gid_pn->ct.port = adapter->nameserver_port;
  1300. gid_pn->ct.handler = zfcp_ns_gid_pn_handler;
  1301. gid_pn->ct.handler_data = (unsigned long) gid_pn;
  1302. gid_pn->ct.timeout = ZFCP_NS_GID_PN_TIMEOUT;
  1303. gid_pn->ct.timer = &erp_action->timer;
  1304. gid_pn->port = erp_action->port;
  1305. ret = zfcp_fsf_send_ct(&gid_pn->ct, adapter->pool.fsf_req_erp,
  1306. erp_action);
  1307. if (ret) {
  1308. ZFCP_LOG_INFO("error: initiation of gid_pn nameserver request "
  1309. "failed for adapter %s\n",
  1310. zfcp_get_busid_by_adapter(adapter));
  1311. zfcp_gid_pn_buffers_free(gid_pn);
  1312. }
  1313. out:
  1314. return ret;
  1315. }
  1316. /**
  1317. * zfcp_ns_gid_pn_handler - handler for GID_PN nameserver request
  1318. * @data: unsigned long, contains pointer to struct zfcp_gid_pn_data
  1319. */
  1320. static void zfcp_ns_gid_pn_handler(unsigned long data)
  1321. {
  1322. struct zfcp_port *port;
  1323. struct zfcp_send_ct *ct;
  1324. struct ct_iu_gid_pn_req *ct_iu_req;
  1325. struct ct_iu_gid_pn_resp *ct_iu_resp;
  1326. struct zfcp_gid_pn_data *gid_pn;
  1327. gid_pn = (struct zfcp_gid_pn_data *) data;
  1328. port = gid_pn->port;
  1329. ct = &gid_pn->ct;
  1330. ct_iu_req = zfcp_sg_to_address(ct->req);
  1331. ct_iu_resp = zfcp_sg_to_address(ct->resp);
  1332. if (ct->status != 0)
  1333. goto failed;
  1334. if (zfcp_check_ct_response(&ct_iu_resp->header)) {
  1335. /* FIXME: do we need some specific erp entry points */
  1336. atomic_set_mask(ZFCP_STATUS_PORT_INVALID_WWPN, &port->status);
  1337. goto failed;
  1338. }
  1339. /* paranoia */
  1340. if (ct_iu_req->wwpn != port->wwpn) {
  1341. ZFCP_LOG_NORMAL("bug: wwpn 0x%016Lx returned by nameserver "
  1342. "lookup does not match expected wwpn 0x%016Lx "
  1343. "for adapter %s\n", ct_iu_req->wwpn, port->wwpn,
  1344. zfcp_get_busid_by_port(port));
  1345. goto mismatch;
  1346. }
  1347. /* looks like a valid d_id */
  1348. port->d_id = ct_iu_resp->d_id & ZFCP_DID_MASK;
  1349. atomic_set_mask(ZFCP_STATUS_PORT_DID_DID, &port->status);
  1350. ZFCP_LOG_DEBUG("adapter %s: wwpn=0x%016Lx ---> d_id=0x%08x\n",
  1351. zfcp_get_busid_by_port(port), port->wwpn, port->d_id);
  1352. goto out;
  1353. mismatch:
  1354. ZFCP_LOG_DEBUG("CT IUs do not match:\n");
  1355. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, (char *) ct_iu_req,
  1356. sizeof(struct ct_iu_gid_pn_req));
  1357. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, (char *) ct_iu_resp,
  1358. sizeof(struct ct_iu_gid_pn_resp));
  1359. failed:
  1360. ZFCP_LOG_NORMAL("warning: failed gid_pn nameserver request for wwpn "
  1361. "0x%016Lx for adapter %s\n",
  1362. port->wwpn, zfcp_get_busid_by_port(port));
  1363. out:
  1364. zfcp_gid_pn_buffers_free(gid_pn);
  1365. return;
  1366. }
  1367. /* reject CT_IU reason codes acc. to FC-GS-4 */
  1368. static const struct zfcp_rc_entry zfcp_ct_rc[] = {
  1369. {0x01, "invalid command code"},
  1370. {0x02, "invalid version level"},
  1371. {0x03, "logical error"},
  1372. {0x04, "invalid CT_IU size"},
  1373. {0x05, "logical busy"},
  1374. {0x07, "protocol error"},
  1375. {0x09, "unable to perform command request"},
  1376. {0x0b, "command not supported"},
  1377. {0x0d, "server not available"},
  1378. {0x0e, "session could not be established"},
  1379. {0xff, "vendor specific error"},
  1380. {0, NULL},
  1381. };
  1382. /* LS_RJT reason codes acc. to FC-FS */
  1383. static const struct zfcp_rc_entry zfcp_ls_rjt_rc[] = {
  1384. {0x01, "invalid LS_Command code"},
  1385. {0x03, "logical error"},
  1386. {0x05, "logical busy"},
  1387. {0x07, "protocol error"},
  1388. {0x09, "unable to perform command request"},
  1389. {0x0b, "command not supported"},
  1390. {0x0e, "command already in progress"},
  1391. {0xff, "vendor specific error"},
  1392. {0, NULL},
  1393. };
  1394. /* reject reason codes according to FC-PH/FC-FS */
  1395. static const struct zfcp_rc_entry zfcp_p_rjt_rc[] = {
  1396. {0x01, "invalid D_ID"},
  1397. {0x02, "invalid S_ID"},
  1398. {0x03, "Nx_Port not available, temporary"},
  1399. {0x04, "Nx_Port not available, permament"},
  1400. {0x05, "class not supported"},
  1401. {0x06, "delimiter usage error"},
  1402. {0x07, "TYPE not supported"},
  1403. {0x08, "invalid Link_Control"},
  1404. {0x09, "invalid R_CTL field"},
  1405. {0x0a, "invalid F_CTL field"},
  1406. {0x0b, "invalid OX_ID"},
  1407. {0x0c, "invalid RX_ID"},
  1408. {0x0d, "invalid SEQ_ID"},
  1409. {0x0e, "invalid DF_CTL"},
  1410. {0x0f, "invalid SEQ_CNT"},
  1411. {0x10, "invalid parameter field"},
  1412. {0x11, "exchange error"},
  1413. {0x12, "protocol error"},
  1414. {0x13, "incorrect length"},
  1415. {0x14, "unsupported ACK"},
  1416. {0x15, "class of service not supported by entity at FFFFFE"},
  1417. {0x16, "login required"},
  1418. {0x17, "excessive sequences attempted"},
  1419. {0x18, "unable to establish exchange"},
  1420. {0x1a, "fabric path not available"},
  1421. {0x1b, "invalid VC_ID (class 4)"},
  1422. {0x1c, "invalid CS_CTL field"},
  1423. {0x1d, "insufficient resources for VC (class 4)"},
  1424. {0x1f, "invalid class of service"},
  1425. {0x20, "preemption request rejected"},
  1426. {0x21, "preemption not enabled"},
  1427. {0x22, "multicast error"},
  1428. {0x23, "multicast error terminate"},
  1429. {0x24, "process login required"},
  1430. {0xff, "vendor specific reject"},
  1431. {0, NULL},
  1432. };
  1433. /**
  1434. * zfcp_rc_description - return description for given reaon code
  1435. * @code: reason code
  1436. * @rc_table: table of reason codes and descriptions
  1437. */
  1438. static inline const char *
  1439. zfcp_rc_description(u8 code, const struct zfcp_rc_entry *rc_table)
  1440. {
  1441. const char *descr = "unknown reason code";
  1442. do {
  1443. if (code == rc_table->code) {
  1444. descr = rc_table->description;
  1445. break;
  1446. }
  1447. rc_table++;
  1448. } while (rc_table->code && rc_table->description);
  1449. return descr;
  1450. }
  1451. /**
  1452. * zfcp_check_ct_response - evaluate reason code for CT_IU
  1453. * @rjt: response payload to an CT_IU request
  1454. * Return: 0 for accept CT_IU, 1 for reject CT_IU or invlid response code
  1455. */
  1456. int
  1457. zfcp_check_ct_response(struct ct_hdr *rjt)
  1458. {
  1459. if (rjt->cmd_rsp_code == ZFCP_CT_ACCEPT)
  1460. return 0;
  1461. if (rjt->cmd_rsp_code != ZFCP_CT_REJECT) {
  1462. ZFCP_LOG_NORMAL("error: invalid Generic Service command/"
  1463. "response code (0x%04hx)\n",
  1464. rjt->cmd_rsp_code);
  1465. return 1;
  1466. }
  1467. ZFCP_LOG_INFO("Generic Service command rejected\n");
  1468. ZFCP_LOG_INFO("%s (0x%02x, 0x%02x, 0x%02x)\n",
  1469. zfcp_rc_description(rjt->reason_code, zfcp_ct_rc),
  1470. (u32) rjt->reason_code, (u32) rjt->reason_code_expl,
  1471. (u32) rjt->vendor_unique);
  1472. return 1;
  1473. }
  1474. /**
  1475. * zfcp_print_els_rjt - print reject parameter and description for ELS reject
  1476. * @rjt_par: reject parameter acc. to FC-PH/FC-FS
  1477. * @rc_table: table of reason codes and descriptions
  1478. */
  1479. static inline void
  1480. zfcp_print_els_rjt(struct zfcp_ls_rjt_par *rjt_par,
  1481. const struct zfcp_rc_entry *rc_table)
  1482. {
  1483. ZFCP_LOG_INFO("%s (%02x %02x %02x %02x)\n",
  1484. zfcp_rc_description(rjt_par->reason_code, rc_table),
  1485. (u32) rjt_par->action, (u32) rjt_par->reason_code,
  1486. (u32) rjt_par->reason_expl, (u32) rjt_par->vendor_unique);
  1487. }
  1488. /**
  1489. * zfcp_fsf_handle_els_rjt - evaluate status qualifier/reason code on ELS reject
  1490. * @sq: status qualifier word
  1491. * @rjt_par: reject parameter as described in FC-PH and FC-FS
  1492. * Return: -EROMTEIO for LS_RJT, -EREMCHG for invalid D_ID, -EIO else
  1493. */
  1494. int
  1495. zfcp_handle_els_rjt(u32 sq, struct zfcp_ls_rjt_par *rjt_par)
  1496. {
  1497. int ret = -EIO;
  1498. if (sq == FSF_IOSTAT_NPORT_RJT) {
  1499. ZFCP_LOG_INFO("ELS rejected (P_RJT)\n");
  1500. zfcp_print_els_rjt(rjt_par, zfcp_p_rjt_rc);
  1501. /* invalid d_id */
  1502. if (rjt_par->reason_code == 0x01)
  1503. ret = -EREMCHG;
  1504. } else if (sq == FSF_IOSTAT_FABRIC_RJT) {
  1505. ZFCP_LOG_INFO("ELS rejected (F_RJT)\n");
  1506. zfcp_print_els_rjt(rjt_par, zfcp_p_rjt_rc);
  1507. /* invalid d_id */
  1508. if (rjt_par->reason_code == 0x01)
  1509. ret = -EREMCHG;
  1510. } else if (sq == FSF_IOSTAT_LS_RJT) {
  1511. ZFCP_LOG_INFO("ELS rejected (LS_RJT)\n");
  1512. zfcp_print_els_rjt(rjt_par, zfcp_ls_rjt_rc);
  1513. ret = -EREMOTEIO;
  1514. } else
  1515. ZFCP_LOG_INFO("unexpected SQ: 0x%02x\n", sq);
  1516. return ret;
  1517. }
  1518. #undef ZFCP_LOG_AREA