zfcp_aux.c 48 KB

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